From 0acead4ea3631240659836ce6ecd6d7f67fd352b Mon Sep 17 00:00:00 2001 From: Jakob Buchgraber Date: Thu, 4 May 2017 09:46:02 +0200 Subject: Update protobuf to latest master at a64497c and apply @laszlocsomor's latest changes from https://github.com/google/protobuf/pull/2969 on top of it. Change-Id: Ie49c5dcac06e370c5ab3863dc061513531ec8c0d --- third_party/protobuf/3.2.0/.travis.yml | 88 + third_party/protobuf/3.2.0/BUILD | 102 +- third_party/protobuf/3.2.0/CHANGES.txt | 108 ++ third_party/protobuf/3.2.0/Makefile.am | 125 +- third_party/protobuf/3.2.0/Protobuf.podspec | 2 +- third_party/protobuf/3.2.0/README.bazel.md | 34 - third_party/protobuf/3.2.0/README.md | 25 +- .../protobuf/3.2.0/cmake/extract_includes.bat.in | 3 + .../protobuf/3.2.0/cmake/libprotobuf-lite.cmake | 1 + third_party/protobuf/3.2.0/cmake/libprotoc.cmake | 2 + third_party/protobuf/3.2.0/cmake/tests.cmake | 8 +- .../protobuf/3.2.0/com_google_protobuf_java.BUILD | 2 +- third_party/protobuf/3.2.0/configure.ac | 2 +- .../protobuf/3.2.0/conformance/conformance_test.cc | 17 + .../protobuf/3.2.0/conformance/conformance_test.h | 1 + .../3.2.0/conformance/failure_list_cpp.txt | 2 - .../3.2.0/conformance/failure_list_csharp.txt | 4 + .../3.2.0/conformance/failure_list_objc.txt | 6 +- .../3.2.0/conformance/failure_list_php_c.txt | 28 +- .../3.2.0/conformance/failure_list_python.txt | 4 + .../3.2.0/csharp/Google.Protobuf.Tools.nuspec | 2 +- .../src/Google.Protobuf/Reflection/Descriptor.cs | 93 +- .../src/Google.Protobuf/WellKnownTypes/Duration.cs | 15 +- .../Google.Protobuf/WellKnownTypes/Timestamp.cs | 25 + .../3.2.0/csharp/src/Google.Protobuf/project.json | 2 +- third_party/protobuf/3.2.0/docs/third_party.md | 3 +- .../protobuf/3.2.0/generate_descriptor_proto.sh | 21 +- third_party/protobuf/3.2.0/java/core/pom.xml | 7 +- .../java/com/google/protobuf/AbstractMessage.java | 4 +- .../com/google/protobuf/AbstractMessageLite.java | 21 +- .../java/com/google/protobuf/AbstractParser.java | 26 +- .../java/com/google/protobuf/BooleanArrayList.java | 12 +- .../java/com/google/protobuf/CodedInputStream.java | 4 +- .../com/google/protobuf/CodedOutputStream.java | 4 +- .../main/java/com/google/protobuf/Descriptors.java | 7 +- .../java/com/google/protobuf/DoubleArrayList.java | 12 +- .../java/com/google/protobuf/DynamicMessage.java | 7 +- .../main/java/com/google/protobuf/FieldSet.java | 7 +- .../java/com/google/protobuf/FloatArrayList.java | 12 +- .../com/google/protobuf/GeneratedMessageLite.java | 22 +- .../com/google/protobuf/GeneratedMessageV3.java | 2 +- .../java/com/google/protobuf/IntArrayList.java | 12 +- .../main/java/com/google/protobuf/Internal.java | 15 + .../java/com/google/protobuf/LazyFieldLite.java | 1 + .../java/com/google/protobuf/LongArrayList.java | 12 +- .../main/java/com/google/protobuf/MapEntry.java | 24 +- .../java/com/google/protobuf/MapEntryLite.java | 5 + .../main/java/com/google/protobuf/MapField.java | 8 + .../java/com/google/protobuf/MapFieldLite.java | 14 +- .../src/main/java/com/google/protobuf/Parser.java | 13 + .../protobuf/PrimitiveNonBoxingCollection.java | 34 + .../google/protobuf/RepeatedFieldBuilderV3.java | 18 +- .../com/google/protobuf/SingleFieldBuilderV3.java | 12 +- .../main/java/com/google/protobuf/TextFormat.java | 4 +- .../java/com/google/protobuf/UnknownFieldSet.java | 4 +- .../main/java/com/google/protobuf/UnsafeUtil.java | 401 +++-- .../src/main/java/com/google/protobuf/Utf8.java | 2 +- .../java/com/google/protobuf/LazyFieldTest.java | 2 +- .../test/java/com/google/protobuf/LiteTest.java | 108 ++ .../java/com/google/protobuf/MapForProto2Test.java | 1 + .../src/test/java/com/google/protobuf/MapTest.java | 63 +- .../test/java/com/google/protobuf/ParserTest.java | 27 +- .../test/java/com/google/protobuf/TestUtil.java | 2 + .../java/com/google/protobuf/TextFormatTest.java | 92 ++ .../com/google/protobuf/lite_equals_and_hash.proto | 8 + third_party/protobuf/3.2.0/java/lite/pom.xml | 1 + third_party/protobuf/3.2.0/java/pom.xml | 10 +- third_party/protobuf/3.2.0/java/util/pom.xml | 2 +- .../java/com/google/protobuf/util/JsonFormat.java | 178 +- .../java/com/google/protobuf/util/Timestamps.java | 2 +- .../com/google/protobuf/util/JsonFormatTest.java | 161 +- .../3.2.0/jenkins/buildcmds/pull_request_32.sh | 2 +- .../protobuf/3.2.0/jenkins/docker/Dockerfile | 33 +- .../protobuf/3.2.0/jenkins/docker32/Dockerfile | 21 +- third_party/protobuf/3.2.0/js/binary/decoder.js | 17 +- .../protobuf/3.2.0/js/binary/decoder_test.js | 19 + third_party/protobuf/3.2.0/js/binary/encoder.js | 4 +- third_party/protobuf/3.2.0/js/binary/reader.js | 2 +- third_party/protobuf/3.2.0/js/binary/utils.js | 2 +- third_party/protobuf/3.2.0/js/binary/writer.js | 4 +- .../protobuf/3.2.0/js/binary/writer_test.js | 2 +- .../v3.0.0/binary/arith_test.js | 355 ++++ .../v3.0.0/binary/decoder_test.js | 334 ++++ .../v3.0.0/binary/proto_test.js | 628 +++++++ .../v3.0.0/binary/reader_test.js | 922 +++++++++++ .../v3.0.0/binary/utils_test.js | 668 ++++++++ .../v3.0.0/binary/writer_test.js | 122 ++ .../v3.0.0/commonjs/export_asserts.js | 37 + .../v3.0.0/commonjs/export_testdeps.js | 18 + .../v3.0.0/commonjs/import_test.js | 52 + .../v3.0.0/commonjs/jasmine.json | 9 + .../v3.0.0/commonjs/rewrite_tests_for_commonjs.js | 97 ++ .../v3.0.0/commonjs/test6/test6.proto | 40 + .../v3.0.0/commonjs/test7/test7.proto | 42 + .../3.2.0/js/compatibility_tests/v3.0.0/data.proto | 51 + .../js/compatibility_tests/v3.0.0/debug_test.js | 105 ++ .../js/compatibility_tests/v3.0.0/jasmine1.json | 17 + .../js/compatibility_tests/v3.0.0/jasmine2.json | 17 + .../js/compatibility_tests/v3.0.0/jasmine3.json | 17 + .../js/compatibility_tests/v3.0.0/message_test.js | 1080 ++++++++++++ .../js/compatibility_tests/v3.0.0/proto3_test.js | 329 ++++ .../compatibility_tests/v3.0.0/proto3_test.proto | 89 + .../3.2.0/js/compatibility_tests/v3.0.0/test.proto | 236 +++ .../3.2.0/js/compatibility_tests/v3.0.0/test.sh | 92 ++ .../js/compatibility_tests/v3.0.0/test2.proto | 54 + .../js/compatibility_tests/v3.0.0/test3.proto | 53 + .../js/compatibility_tests/v3.0.0/test4.proto | 42 + .../js/compatibility_tests/v3.0.0/test5.proto | 44 + .../js/compatibility_tests/v3.0.0/testbinary.proto | 212 +++ .../js/compatibility_tests/v3.0.0/testempty.proto | 34 + third_party/protobuf/3.2.0/js/gulpfile.js | 70 +- third_party/protobuf/3.2.0/js/jasmine.json | 4 +- third_party/protobuf/3.2.0/js/map.js | 10 +- third_party/protobuf/3.2.0/js/message.js | 31 +- third_party/protobuf/3.2.0/js/message_test.js | 1 + third_party/protobuf/3.2.0/js/package.json | 2 +- third_party/protobuf/3.2.0/libprotobuf_java.jar | Bin 0 -> 1203755 bytes .../protobuf/3.2.0/libprotobuf_java_util.jar | Bin 0 -> 58322 bytes .../3.2.0/objectivec/DevTools/full_mac_build.sh | 8 + third_party/protobuf/3.2.0/objectivec/GPBMessage.m | 23 +- .../3.2.0/objectivec/GPBMessage_PackagePrivate.h | 18 +- .../objectivec/google/protobuf/Duration.pbobjc.h | 15 +- .../objectivec/google/protobuf/Timestamp.pbobjc.h | 25 + .../protobuf/3.2.0/php/ext/google/protobuf/array.c | 313 ++-- .../protobuf/3.2.0/php/ext/google/protobuf/def.c | 450 ++--- .../3.2.0/php/ext/google/protobuf/encode_decode.c | 523 ++++-- .../protobuf/3.2.0/php/ext/google/protobuf/map.c | 195 +-- .../3.2.0/php/ext/google/protobuf/message.c | 224 ++- .../3.2.0/php/ext/google/protobuf/package.xml | 26 +- .../3.2.0/php/ext/google/protobuf/protobuf.c | 57 +- .../3.2.0/php/ext/google/protobuf/protobuf.h | 478 +++++- .../3.2.0/php/ext/google/protobuf/storage.c | 578 ++++--- .../3.2.0/php/ext/google/protobuf/type_check.c | 85 +- .../Google/Protobuf/Internal/DescriptorPool.php | 3 + .../Protobuf/Internal/GPBDecodeException.php | 47 + .../src/Google/Protobuf/Internal/InputStream.php | 17 +- .../php/src/Google/Protobuf/Internal/MapField.php | 4 +- .../php/src/Google/Protobuf/Internal/Message.php | 73 +- .../src/Google/Protobuf/Internal/RepeatedField.php | 4 + .../3.2.0/php/src/Google/Protobuf/descriptor.php | 42 +- .../protobuf/3.2.0/php/tests/array_test.php | 39 +- .../3.2.0/php/tests/encode_decode_test.php | 198 +++ third_party/protobuf/3.2.0/php/tests/gdb_test.sh | 8 +- .../3.2.0/php/tests/generated_class_test.php | 33 +- .../protobuf/3.2.0/php/tests/map_field_test.php | 17 +- .../protobuf/3.2.0/php/tests/memory_leak_test.php | 17 +- .../protobuf/3.2.0/php/tests/proto/test.proto | 23 + .../tests/proto/test_import_descriptor_proto.proto | 14 + .../3.2.0/php/tests/proto/test_no_namespace.proto | 10 +- .../3.2.0/php/tests/proto/test_prefix.proto | 5 + third_party/protobuf/3.2.0/php/tests/test_util.php | 3 +- .../protobuf/3.2.0/php/tests/well_known_test.php | 10 +- third_party/protobuf/3.2.0/protobuf-java-3.2.0.jar | Bin 1347123 -> 0 bytes .../protobuf/3.2.0/protobuf-java-util-3.2.0.jar | Bin 67556 -> 0 bytes third_party/protobuf/3.2.0/protobuf.bzl | 1 + .../protobuf/3.2.0/protoc-artifacts/pom.xml | 2 +- .../3.2.0/python/google/protobuf/__init__.py | 2 +- .../python/google/protobuf/descriptor_database.py | 11 +- .../python/google/protobuf/descriptor_pool.py | 129 +- .../python/google/protobuf/internal/containers.py | 2 +- .../protobuf/internal/descriptor_pool_test.py | 45 + .../python/google/protobuf/internal/encoder.py | 7 +- .../google/protobuf/internal/message_test.py | 27 +- .../google/protobuf/internal/python_message.py | 5 +- .../google/protobuf/internal/python_protobuf.cc | 63 + .../google/protobuf/internal/reflection_test.py | 9 +- .../protobuf/internal/symbol_database_test.py | 9 +- .../google/protobuf/internal/text_format_test.py | 51 + .../python/google/protobuf/pyext/descriptor.cc | 19 + .../python/google/protobuf/pyext/descriptor.h | 2 + .../google/protobuf/pyext/descriptor_pool.cc | 20 +- .../python/google/protobuf/pyext/descriptor_pool.h | 1 + .../3.2.0/python/google/protobuf/pyext/message.cc | 2 +- .../python/google/protobuf/pyext/python_protobuf.h | 57 - .../protobuf/pyext/repeated_composite_container.cc | 29 + .../google/protobuf/pyext/scoped_pyobject_ptr.h | 59 +- .../3.2.0/python/google/protobuf/python_protobuf.h | 57 + .../3.2.0/python/google/protobuf/reflection.py | 6 +- .../python/google/protobuf/symbol_database.py | 11 + .../3.2.0/python/google/protobuf/text_format.py | 35 +- .../protobuf/3.2.0/ruby/google-protobuf.gemspec | 2 +- third_party/protobuf/3.2.0/src/Makefile.am | 54 +- .../protobuf/3.2.0/src/google/protobuf/any.h | 6 +- .../protobuf/3.2.0/src/google/protobuf/any.pb.cc | 31 +- .../protobuf/3.2.0/src/google/protobuf/any.pb.h | 19 +- .../protobuf/3.2.0/src/google/protobuf/api.pb.cc | 106 +- .../protobuf/3.2.0/src/google/protobuf/api.pb.h | 42 +- .../protobuf/3.2.0/src/google/protobuf/arena.h | 55 +- .../3.2.0/src/google/protobuf/arena_unittest.cc | 52 + .../3.2.0/src/google/protobuf/arenastring.cc | 10 - .../3.2.0/src/google/protobuf/arenastring.h | 16 + .../src/google/protobuf/compiler/code_generator.h | 2 +- .../protobuf/compiler/command_line_interface.cc | 86 +- .../protobuf/compiler/command_line_interface.h | 7 +- .../compiler/command_line_interface_unittest.cc | 68 +- .../compiler/cpp/cpp_bootstrap_unittest.cc | 14 +- .../google/protobuf/compiler/cpp/cpp_enum_field.cc | 16 +- .../src/google/protobuf/compiler/cpp/cpp_file.cc | 163 +- .../src/google/protobuf/compiler/cpp/cpp_file.h | 3 + .../google/protobuf/compiler/cpp/cpp_generator.cc | 2 + .../google/protobuf/compiler/cpp/cpp_helpers.cc | 103 ++ .../src/google/protobuf/compiler/cpp/cpp_helpers.h | 67 + .../google/protobuf/compiler/cpp/cpp_map_field.cc | 79 +- .../google/protobuf/compiler/cpp/cpp_map_field.h | 2 +- .../google/protobuf/compiler/cpp/cpp_message.cc | 911 +++++++--- .../src/google/protobuf/compiler/cpp/cpp_message.h | 33 +- .../protobuf/compiler/cpp/cpp_message_field.cc | 20 +- .../protobuf/compiler/cpp/cpp_message_field.h | 2 +- .../src/google/protobuf/compiler/cpp/cpp_options.h | 8 +- .../protobuf/compiler/cpp/cpp_primitive_field.cc | 19 +- .../protobuf/compiler/cpp/cpp_string_field.cc | 14 +- .../google/protobuf/compiler/cpp/cpp_unittest.cc | 56 +- .../protobuf/compiler/csharp/csharp_field_base.cc | 8 +- .../3.2.0/src/google/protobuf/compiler/importer.cc | 17 +- .../3.2.0/src/google/protobuf/compiler/importer.h | 1 + .../google/protobuf/compiler/importer_unittest.cc | 2 +- .../protobuf/compiler/java/java_enum_field_lite.cc | 3 + .../protobuf/compiler/java/java_enum_lite.cc | 51 +- .../src/google/protobuf/compiler/java/java_field.h | 1 + .../src/google/protobuf/compiler/java/java_file.cc | 6 - .../protobuf/compiler/java/java_generator.cc | 1 + .../google/protobuf/compiler/java/java_helpers.cc | 2 + .../compiler/java/java_lazy_message_field_lite.cc | 3 + .../compiler/java/java_lazy_message_field_lite.h | 3 + .../protobuf/compiler/java/java_map_field.cc | 3 - .../protobuf/compiler/java/java_map_field_lite.cc | 4 +- .../protobuf/compiler/java/java_map_field_lite.h | 1 + .../google/protobuf/compiler/java/java_message.cc | 11 + .../compiler/java/java_message_builder_lite.cc | 7 - .../compiler/java/java_message_field_lite.cc | 2 + .../compiler/java/java_message_field_lite.h | 2 + .../protobuf/compiler/java/java_message_lite.cc | 29 +- .../compiler/java/java_primitive_field_lite.cc | 2 + .../compiler/java/java_primitive_field_lite.h | 3 + .../compiler/java/java_string_field_lite.cc | 3 + .../compiler/java/java_string_field_lite.h | 3 + .../protobuf/compiler/javanano/javanano_file.cc | 6 +- .../protobuf/compiler/javanano/javanano_helpers.cc | 8 +- .../protobuf/compiler/javanano/javanano_message.cc | 2 +- .../3.2.0/src/google/protobuf/compiler/js/embed.cc | 2 +- .../google/protobuf/compiler/js/js_generator.cc | 177 +- .../compiler/js/well_known_types/timestamp.js | 1 - .../protobuf/compiler/mock_code_generator.cc | 12 +- .../compiler/objectivec/objectivec_extension.cc | 6 +- .../compiler/objectivec/objectivec_field.cc | 4 +- .../compiler/objectivec/objectivec_helpers.cc | 74 +- .../compiler/objectivec/objectivec_message.cc | 6 +- .../google/protobuf/compiler/parser_unittest.cc | 7 +- .../google/protobuf/compiler/php/php_generator.cc | 131 +- .../3.2.0/src/google/protobuf/compiler/plugin.cc | 17 +- .../src/google/protobuf/compiler/plugin.pb.cc | 197 ++- .../3.2.0/src/google/protobuf/compiler/plugin.pb.h | 46 +- .../src/google/protobuf/compiler/plugin.proto | 3 + .../src/google/protobuf/compiler/profile.pb.cc | 1442 ++++++++++++++++ .../src/google/protobuf/compiler/profile.pb.h | 728 ++++++++ .../src/google/protobuf/compiler/profile.proto | 68 + .../protobuf/compiler/python/python_generator.cc | 6 +- .../src/google/protobuf/compiler/test_plugin.cc | 1 - .../src/google/protobuf/compiler/zip_writer.cc | 30 + .../src/google/protobuf/compiler/zip_writer.h | 30 + .../3.2.0/src/google/protobuf/descriptor.cc | 679 +++++--- .../3.2.0/src/google/protobuf/descriptor.h | 153 +- .../3.2.0/src/google/protobuf/descriptor.pb.cc | 1743 ++++++++++++-------- .../3.2.0/src/google/protobuf/descriptor.pb.h | 393 ++--- .../3.2.0/src/google/protobuf/descriptor.proto | 3 +- .../src/google/protobuf/descriptor_database.cc | 4 +- .../src/google/protobuf/descriptor_database.h | 12 + .../protobuf/descriptor_database_unittest.cc | 1 - .../src/google/protobuf/descriptor_unittest.cc | 359 +++- .../3.2.0/src/google/protobuf/duration.pb.cc | 29 +- .../3.2.0/src/google/protobuf/duration.pb.h | 17 +- .../3.2.0/src/google/protobuf/duration.proto | 15 +- .../3.2.0/src/google/protobuf/dynamic_message.cc | 24 +- .../protobuf/3.2.0/src/google/protobuf/empty.pb.cc | 29 +- .../protobuf/3.2.0/src/google/protobuf/empty.pb.h | 17 +- .../3.2.0/src/google/protobuf/extension_set.h | 13 +- .../src/google/protobuf/extension_set_heavy.cc | 43 +- .../src/google/protobuf/extension_set_unittest.cc | 2 +- .../3.2.0/src/google/protobuf/field_mask.pb.cc | 35 +- .../3.2.0/src/google/protobuf/field_mask.pb.h | 21 +- .../protobuf/generated_message_reflection.cc | 67 +- .../google/protobuf/generated_message_reflection.h | 81 +- .../protobuf/generated_message_table_driven.cc | 676 ++++++++ .../protobuf/generated_message_table_driven.h | 173 ++ .../src/google/protobuf/generated_message_util.cc | 2 +- .../src/google/protobuf/generated_message_util.h | 57 +- .../3.2.0/src/google/protobuf/io/coded_stream.cc | 46 +- .../3.2.0/src/google/protobuf/io/coded_stream.h | 39 +- .../google/protobuf/io/coded_stream_unittest.cc | 33 +- .../3.2.0/src/google/protobuf/io/gzip_stream.h | 2 +- .../google/protobuf/io/zero_copy_stream_impl.cc | 12 +- .../protobuf/io/zero_copy_stream_impl_lite.h | 2 +- .../protobuf/io/zero_copy_stream_unittest.cc | 10 +- .../3.2.0/src/google/protobuf/lite_unittest.cc | 239 ++- .../protobuf/3.2.0/src/google/protobuf/map.h | 710 +------- .../protobuf/3.2.0/src/google/protobuf/map_entry.h | 231 +-- .../3.2.0/src/google/protobuf/map_entry_lite.h | 191 ++- .../3.2.0/src/google/protobuf/map_field.cc | 59 +- .../protobuf/3.2.0/src/google/protobuf/map_field.h | 531 +++++- .../3.2.0/src/google/protobuf/map_field_inl.h | 290 +--- .../3.2.0/src/google/protobuf/map_field_lite.h | 226 +-- .../3.2.0/src/google/protobuf/map_field_test.cc | 51 +- .../src/google/protobuf/map_proto2_unittest.proto | 5 + .../protobuf/3.2.0/src/google/protobuf/map_test.cc | 331 +++- .../3.2.0/src/google/protobuf/map_test_util.cc | 16 + .../3.2.0/src/google/protobuf/map_test_util.h | 5 + .../3.2.0/src/google/protobuf/map_test_util_impl.h | 41 +- .../3.2.0/src/google/protobuf/map_type_handler.h | 70 +- .../protobuf/3.2.0/src/google/protobuf/message.cc | 4 +- .../protobuf/3.2.0/src/google/protobuf/message.h | 21 +- .../3.2.0/src/google/protobuf/message_lite.cc | 5 + .../3.2.0/src/google/protobuf/message_lite.h | 33 +- .../3.2.0/src/google/protobuf/message_unittest.cc | 22 +- .../protobuf/3.2.0/src/google/protobuf/metadata.h | 153 +- .../3.2.0/src/google/protobuf/metadata_lite.h | 193 +++ .../3.2.0/src/google/protobuf/reflection.h | 4 +- .../3.2.0/src/google/protobuf/reflection_ops.cc | 22 + .../src/google/protobuf/reflection_ops_unittest.cc | 1 + .../3.2.0/src/google/protobuf/repeated_field.h | 170 +- .../protobuf/repeated_field_reflection_unittest.cc | 39 +- .../src/google/protobuf/repeated_field_unittest.cc | 2 +- .../3.2.0/src/google/protobuf/source_context.pb.cc | 30 +- .../3.2.0/src/google/protobuf/source_context.pb.h | 18 +- .../3.2.0/src/google/protobuf/struct.pb.cc | 136 +- .../protobuf/3.2.0/src/google/protobuf/struct.pb.h | 62 +- .../3.2.0/src/google/protobuf/stubs/common.h | 24 +- .../src/google/protobuf/stubs/int128_unittest.cc | 14 +- .../3.2.0/src/google/protobuf/stubs/io_win32.cc | 181 +- .../3.2.0/src/google/protobuf/stubs/io_win32.h | 46 +- .../src/google/protobuf/stubs/io_win32_unittest.cc | 202 ++- .../3.2.0/src/google/protobuf/stubs/strutil.cc | 12 +- .../3.2.0/src/google/protobuf/test_util_lite.cc | 7 +- .../3.2.0/src/google/protobuf/testing/file.cc | 19 +- .../src/google/protobuf/testing/googletest.cc | 36 +- .../3.2.0/src/google/protobuf/text_format.cc | 15 +- .../3.2.0/src/google/protobuf/text_format.h | 4 +- .../src/google/protobuf/text_format_unittest.cc | 2 +- .../3.2.0/src/google/protobuf/timestamp.pb.cc | 29 +- .../3.2.0/src/google/protobuf/timestamp.pb.h | 17 +- .../3.2.0/src/google/protobuf/timestamp.proto | 25 + .../protobuf/3.2.0/src/google/protobuf/type.pb.cc | 169 +- .../protobuf/3.2.0/src/google/protobuf/type.pb.h | 65 +- .../3.2.0/src/google/protobuf/unittest.proto | 16 + .../protobuf/unittest_lazy_dependencies.proto | 75 + .../unittest_lazy_dependencies_custom_option.proto | 67 + .../protobuf/unittest_lazy_dependencies_enum.proto | 61 + .../google/protobuf/unittest_proto3_arena.proto | 2 + .../3.2.0/src/google/protobuf/unknown_field_set.cc | 48 +- .../3.2.0/src/google/protobuf/unknown_field_set.h | 43 +- .../protobuf/util/delimited_message_util_test.cc | 2 +- .../util/internal/default_value_objectwriter.cc | 82 +- .../util/internal/default_value_objectwriter.h | 44 +- .../protobuf/util/internal/field_mask_utility.cc | 7 +- .../google/protobuf/util/internal/json_escaping.cc | 48 - .../protobuf/util/internal/json_stream_parser.cc | 58 +- .../google/protobuf/util/internal/proto_writer.h | 28 +- .../util/internal/protostream_objectsource.cc | 44 +- .../util/internal/protostream_objectsource.h | 4 +- .../util/internal/protostream_objectsource_test.cc | 6 +- .../util/internal/protostream_objectwriter.cc | 35 +- .../util/internal/protostream_objectwriter.h | 11 +- .../util/internal/protostream_objectwriter_test.cc | 10 +- .../src/google/protobuf/util/internal/type_info.cc | 18 +- .../src/google/protobuf/util/internal/utility.cc | 10 - .../3.2.0/src/google/protobuf/util/json_util.cc | 6 +- .../3.2.0/src/google/protobuf/util/json_util.h | 10 +- .../src/google/protobuf/util/json_util_test.cc | 20 +- .../google/protobuf/util/message_differencer.cc | 11 +- .../protobuf/util/message_differencer_unittest.cc | 41 +- .../3.2.0/src/google/protobuf/util/time_util.cc | 28 - .../3.2.0/src/google/protobuf/wire_format.cc | 309 +++- .../3.2.0/src/google/protobuf/wire_format_lite.cc | 12 +- .../3.2.0/src/google/protobuf/wire_format_lite.h | 445 +++-- .../src/google/protobuf/wire_format_lite_inl.h | 184 ++- .../src/google/protobuf/wire_format_unittest.cc | 23 + .../3.2.0/src/google/protobuf/wrappers.pb.cc | 175 +- .../3.2.0/src/google/protobuf/wrappers.pb.h | 91 +- third_party/protobuf/3.2.0/tests.sh | 126 +- third_party/protobuf/3.2.0/update_file_lists.sh | 2 +- third_party/protobuf/3.2.0/util/python/BUILD | 1 - third_party/protobuf/README.md | 57 +- 381 files changed, 22289 insertions(+), 7155 deletions(-) create mode 100644 third_party/protobuf/3.2.0/.travis.yml delete mode 100644 third_party/protobuf/3.2.0/README.bazel.md create mode 100644 third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/PrimitiveNonBoxingCollection.java create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/arith_test.js create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/decoder_test.js create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/proto_test.js create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/reader_test.js create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/utils_test.js create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/writer_test.js create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/export_asserts.js create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/export_testdeps.js create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/import_test.js create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/jasmine.json create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/rewrite_tests_for_commonjs.js create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/test6/test6.proto create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/test7/test7.proto create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/data.proto create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/debug_test.js create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/jasmine1.json create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/jasmine2.json create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/jasmine3.json create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/message_test.js create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/proto3_test.js create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/proto3_test.proto create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test.proto create mode 100755 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test.sh create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test2.proto create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test3.proto create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test4.proto create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test5.proto create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/testbinary.proto create mode 100644 third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/testempty.proto create mode 100755 third_party/protobuf/3.2.0/libprotobuf_java.jar create mode 100755 third_party/protobuf/3.2.0/libprotobuf_java_util.jar create mode 100644 third_party/protobuf/3.2.0/php/src/Google/Protobuf/Internal/GPBDecodeException.php create mode 100644 third_party/protobuf/3.2.0/php/tests/proto/test_import_descriptor_proto.proto delete mode 100644 third_party/protobuf/3.2.0/protobuf-java-3.2.0.jar delete mode 100644 third_party/protobuf/3.2.0/protobuf-java-util-3.2.0.jar create mode 100644 third_party/protobuf/3.2.0/python/google/protobuf/internal/python_protobuf.cc delete mode 100644 third_party/protobuf/3.2.0/python/google/protobuf/pyext/python_protobuf.h create mode 100644 third_party/protobuf/3.2.0/python/google/protobuf/python_protobuf.h create mode 100644 third_party/protobuf/3.2.0/src/google/protobuf/compiler/profile.pb.cc create mode 100644 third_party/protobuf/3.2.0/src/google/protobuf/compiler/profile.pb.h create mode 100644 third_party/protobuf/3.2.0/src/google/protobuf/compiler/profile.proto create mode 100644 third_party/protobuf/3.2.0/src/google/protobuf/generated_message_table_driven.cc create mode 100644 third_party/protobuf/3.2.0/src/google/protobuf/generated_message_table_driven.h create mode 100644 third_party/protobuf/3.2.0/src/google/protobuf/metadata_lite.h create mode 100644 third_party/protobuf/3.2.0/src/google/protobuf/unittest_lazy_dependencies.proto create mode 100644 third_party/protobuf/3.2.0/src/google/protobuf/unittest_lazy_dependencies_custom_option.proto create mode 100644 third_party/protobuf/3.2.0/src/google/protobuf/unittest_lazy_dependencies_enum.proto (limited to 'third_party/protobuf') diff --git a/third_party/protobuf/3.2.0/.travis.yml b/third_party/protobuf/3.2.0/.travis.yml new file mode 100644 index 0000000000..8f6f90de62 --- /dev/null +++ b/third_party/protobuf/3.2.0/.travis.yml @@ -0,0 +1,88 @@ +sudo: required +dist: trusty +# Note: travis currently does not support listing more than one language so +# this cheats and claims to only be cpp. If they add multiple language +# support, this should probably get updated to install steps and/or +# rvm/gemfile/jdk/etc. entries rather than manually doing the work. +language: cpp +os: + - osx +# The Objective C build needs Xcode 7.0 or later. +osx_image: xcode8.1 +script: + - ./tests.sh $CONFIG +env: + - CONFIG=cpp + - CONFIG=cpp_distcheck + - CONFIG=golang + - CONFIG=java_jdk7 + - CONFIG=java_oracle7 + - CONFIG=javanano_jdk7 + - CONFIG=javanano_oracle7 + - CONFIG=javascript + # iOS build log was starting to choke travis UI, so split to cover the + # Xcode Debug and Release Configurations independently. + - CONFIG=objectivec_ios_debug + - CONFIG=objectivec_ios_release + - CONFIG=objectivec_osx + - CONFIG=objectivec_cocoapods_integration + - CONFIG=python + - CONFIG=python_cpp + - CONFIG=ruby21 + - CONFIG=ruby22 + - CONFIG=jruby + - CONFIG=php5.6_mac + - CONFIG=php7.0_mac +matrix: + exclude: + # It's nontrivial to programmatically install a new JDK from the command + # line on OS X, so we rely on testing on Linux for Java code. + - os: osx + env: CONFIG=java_jdk7 + - os: osx + env: CONFIG=java_oracle7 + - os: osx + env: CONFIG=javanano_jdk7 + - os: osx + env: CONFIG=javanano_oracle7 + # Requires installing golang, currently travis.sh is doing that with apt-get + # which doesn't work on OS X. + - os: osx + env: CONFIG=golang + include: + # The dotnet environment requires Ubuntu 14.04 or 16.04. This + # configuration is effectively an "extra" one, outside the + # autogenerated matrix. + - os: linux + env: CONFIG=csharp + dist: trusty + # This test is kept on travis because it doesn't play nicely with other + # tests on jenkins running in parallel. + - os: linux + env: CONFIG=cpp_distcheck + # The Java compatibility test currently only runs on Linux because it will + # fetch pre-built Linux protoc binaries in the test. + - os: linux + env: CONFIG=java_compatibility + # The Python compatibility test currently only runs on Linux because it will + # fetch pre-built Linux protoc binaries in the test. + - os: linux + env: CONFIG=python_compatibility + allow_failures: + # These currently do not work on OS X but are being worked on by @haberman. + - os: osx + env: CONFIG=ruby22 + - os: osx + env: CONFIG=jruby + # https://github.com/google/protobuf/issues/1253 - Started failing when + # we moved to an OS X image that is 10.11. + - os: osx + env: CONFIG=python_cpp + # Mark the iOS test as flakey as xcodebuild some times fails to start the + # iOS Simulator. + - os: osx + env: CONFIG=objectivec_ios_debug + - os: osx + env: CONFIG=objectivec_ios_release +notifications: + email: false diff --git a/third_party/protobuf/3.2.0/BUILD b/third_party/protobuf/3.2.0/BUILD index 2ad3faf178..a6a52810f1 100644 --- a/third_party/protobuf/3.2.0/BUILD +++ b/third_party/protobuf/3.2.0/BUILD @@ -26,7 +26,7 @@ filegroup( java_import( name = "protobuf_java_util", - jars = ["protobuf-java-util-3.2.0.jar"], + jars = ["libprotobuf_java_util.jar"], exports = [ "//third_party:gson", ], @@ -35,21 +35,21 @@ java_import( java_import( name = "protobuf_java", - jars = ["protobuf-java-3.2.0.jar"], + jars = ["libprotobuf_java.jar"], visibility = ["//visibility:public"], ) # For bootstrapping JavaBuilder filegroup( name = "protobuf-jars", - srcs = ["protobuf-java-3.2.0.jar"], + srcs = ["libprotobuf_java.jar"], visibility = ["//visibility:public"], ) ################################################################################ # The below build rules are a copy of the upstream protobuf BUILD file with -# Java support removed. -################################################################################ +# # Java support removed. +# ################################################################################ ################################################################################ # Protobuf Runtime Library @@ -255,6 +255,7 @@ RELATIVE_WELL_KNOWN_PROTOS = [ "google/protobuf/any.proto", "google/protobuf/api.proto", "google/protobuf/compiler/plugin.proto", + "google/protobuf/compiler/profile.proto", "google/protobuf/descriptor.proto", "google/protobuf/duration.proto", "google/protobuf/empty.proto", @@ -399,6 +400,7 @@ cc_library( "src/google/protobuf/compiler/php/php_generator.cc", "src/google/protobuf/compiler/plugin.cc", "src/google/protobuf/compiler/plugin.pb.cc", + "src/google/protobuf/compiler/profile.pb.cc", "src/google/protobuf/compiler/python/python_generator.cc", "src/google/protobuf/compiler/ruby/ruby_generator.cc", "src/google/protobuf/compiler/subprocess.cc", @@ -450,6 +452,9 @@ RELATIVE_TEST_PROTOS = [ "google/protobuf/unittest_enormous_descriptor.proto", "google/protobuf/unittest_import.proto", "google/protobuf/unittest_import_public.proto", + "google/protobuf/unittest_lazy_dependencies.proto", + "google/protobuf/unittest_lazy_dependencies_custom_option.proto", + "google/protobuf/unittest_lazy_dependencies_enum.proto", "google/protobuf/unittest_lite_imports_nonlite.proto", "google/protobuf/unittest_mset.proto", "google/protobuf/unittest_mset_wire_format.proto", @@ -494,6 +499,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", @@ -536,6 +542,7 @@ cc_test( "src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc", "src/google/protobuf/compiler/cpp/cpp_unittest.cc", "src/google/protobuf/compiler/cpp/metadata_test.cc", + "src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc", "src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc", "src/google/protobuf/compiler/importer_unittest.cc", "src/google/protobuf/compiler/java/java_doc_comment_unittest.cc", @@ -603,6 +610,10 @@ cc_test( ":test_plugin", ] + glob([ "src/google/protobuf/**/*", + # Files for csharp_bootstrap_unittest.cc. + "conformance/**/*", + "csharp/src/**/*", + "examples/**/*", ]), includes = [ "src/", @@ -833,3 +844,84 @@ proto_lang_toolchain( runtime = ":protobuf_java", visibility = ["//visibility:public"], ) + +OBJC_HDRS = [ + "objectivec/GPBArray.h", + "objectivec/GPBBootstrap.h", + "objectivec/GPBCodedInputStream.h", + "objectivec/GPBCodedOutputStream.h", + "objectivec/GPBDescriptor.h", + "objectivec/GPBDictionary.h", + "objectivec/GPBExtensionInternals.h", + "objectivec/GPBExtensionRegistry.h", + "objectivec/GPBMessage.h", + "objectivec/GPBProtocolBuffers.h", + "objectivec/GPBProtocolBuffers_RuntimeSupport.h", + "objectivec/GPBRootObject.h", + "objectivec/GPBRuntimeTypes.h", + "objectivec/GPBUnknownField.h", + "objectivec/GPBUnknownFieldSet.h", + "objectivec/GPBUtilities.h", + "objectivec/GPBWellKnownTypes.h", + "objectivec/GPBWireFormat.h", + "objectivec/google/protobuf/Any.pbobjc.h", + "objectivec/google/protobuf/Api.pbobjc.h", + "objectivec/google/protobuf/Duration.pbobjc.h", + "objectivec/google/protobuf/Empty.pbobjc.h", + "objectivec/google/protobuf/FieldMask.pbobjc.h", + "objectivec/google/protobuf/SourceContext.pbobjc.h", + "objectivec/google/protobuf/Struct.pbobjc.h", + "objectivec/google/protobuf/Timestamp.pbobjc.h", + "objectivec/google/protobuf/Type.pbobjc.h", + "objectivec/google/protobuf/Wrappers.pbobjc.h", +] + +OBJC_PRIVATE_HDRS = [ + "objectivec/GPBArray_PackagePrivate.h", + "objectivec/GPBCodedInputStream_PackagePrivate.h", + "objectivec/GPBCodedOutputStream_PackagePrivate.h", + "objectivec/GPBDescriptor_PackagePrivate.h", + "objectivec/GPBDictionary_PackagePrivate.h", + "objectivec/GPBMessage_PackagePrivate.h", + "objectivec/GPBRootObject_PackagePrivate.h", + "objectivec/GPBUnknownFieldSet_PackagePrivate.h", + "objectivec/GPBUnknownField_PackagePrivate.h", + "objectivec/GPBUtilities_PackagePrivate.h", +] + +OBJC_SRCS = [ + "objectivec/GPBArray.m", + "objectivec/GPBCodedInputStream.m", + "objectivec/GPBCodedOutputStream.m", + "objectivec/GPBDescriptor.m", + "objectivec/GPBDictionary.m", + "objectivec/GPBExtensionInternals.m", + "objectivec/GPBExtensionRegistry.m", + "objectivec/GPBMessage.m", + "objectivec/GPBRootObject.m", + "objectivec/GPBUnknownField.m", + "objectivec/GPBUnknownFieldSet.m", + "objectivec/GPBUtilities.m", + "objectivec/GPBWellKnownTypes.m", + "objectivec/GPBWireFormat.m", + "objectivec/google/protobuf/Any.pbobjc.m", + "objectivec/google/protobuf/Api.pbobjc.m", + "objectivec/google/protobuf/Duration.pbobjc.m", + "objectivec/google/protobuf/Empty.pbobjc.m", + "objectivec/google/protobuf/FieldMask.pbobjc.m", + "objectivec/google/protobuf/SourceContext.pbobjc.m", + "objectivec/google/protobuf/Struct.pbobjc.m", + "objectivec/google/protobuf/Timestamp.pbobjc.m", + "objectivec/google/protobuf/Type.pbobjc.m", + "objectivec/google/protobuf/Wrappers.pbobjc.m", +] + +objc_library( + name = "objectivec", + hdrs = OBJC_HDRS + OBJC_PRIVATE_HDRS, + includes = [ + "objectivec", + ], + non_arc_srcs = OBJC_SRCS, + visibility = ["//visibility:public"], +) diff --git a/third_party/protobuf/3.2.0/CHANGES.txt b/third_party/protobuf/3.2.0/CHANGES.txt index 1164583645..ccc8ff9439 100644 --- a/third_party/protobuf/3.2.0/CHANGES.txt +++ b/third_party/protobuf/3.2.0/CHANGES.txt @@ -1,3 +1,111 @@ +2017-04-05 version 3.3.0 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) + Planned Future Changes + * There are some changes that are not included in this release but are + planned for the near future: + - Preserve unknown fields in proto3: please read this doc: + + https://docs.google.com/document/d/1KMRX-G91Aa-Y2FkEaHeeviLRRNblgIahbsk4wA14gRk/view + + for the timeline and follow up this github issue: + + https://github.com/google/protobuf/issues/272 + + for discussion. + - Make C++ implementation C++11 only: we plan to require C++11 to build + protobuf code starting from 3.4.0 or 3.5.0 release. Please join this + github issue: + + https://github.com/google/protobuf/issues/2780 + + to provide your feedback. + + C++ + * Fixed map fields serialization of DynamicMessage to correctly serialize + both key and value regardless of their presence. + * Parser now rejects field number 0 correctly. + * New API Message::SpaceUsedLong() that’s equivalent to + Message::SpaceUsed() but returns the value in size_t. + * JSON support + - New flag always_print_enums_as_ints in JsonPrintOptions. + - New flag preserve_proto_field_names in JsonPrintOptions. It will instruct + the JSON printer to use the original field name declared in the .proto + file instead of converting them to lowerCamelCase when printing JSON. + - JsonPrintOptions.always_print_primtive_fields now works for oneof message + fields. + - Fixed a bug that doesn’t allow different fields to set the same json_name + value. + - Fixed a performance bug that causes excessive memory copy when printing + large messages. + * Various performance optimizations. + + Java + * Map field setters eagerly validate inputs and throw NullPointerExceptions + as appropriate. + * Added ByteBuffer overloads to the generated parsing methods and the Parser + interface. + * proto3 enum's getNumber() method now throws on UNRECOGNIZED values. + * Output of JsonFormat is now locale independent. + + Python + * Added FindServiceByName() in the pure-Python DescriptorPool. This works only + for descriptors added with DescriptorPool.Add(). Generated descriptor_pool + does not support this yet. + * Added a descriptor_pool parameter for parsing Any in text_format.Parse(). + * descriptor_pool.FindFileContainingSymbol() now is able to find nested + extensions. + * Extending empty [] to repeated field now sets parent message presence. + + PHP + * Added file option php_class_prefix. The prefix will be prepended to all + generated classes defined in the file. + * When encoding, negative int32 values are sign-extended to int64. + * Repeated/Map field setter accepts a regular PHP array. Type checking is + done on the array elements. + * encode/decode are renamed to serializeToString/mergeFromString. + * Added mergeFrom, clear method on Message. + * Fixed a bug that oneof accessor didn’t return the field name that is + actually set. + * C extension now works with php7. + * This is the first GA release of PHP. We guarantee that old generated code + can always work with new runtime and new generated code. + + Objective-C + * Fixed help for GPBTimestamp for dates before the epoch that contain + fractional seconds. + * Added GPBMessageDropUnknownFieldsRecursively() to remove unknowns from a + message and any sub messages. + * Addressed a threading race in extension registration/lookup. + * Increased the max message parsing depth to 100 to match the other languages. + * Removed some use of dispatch_once in favor of atomic compare/set since it + needs to be heap based. + * Fixes for new Xcode 8.3 warnings. + + C# + * Fixed MapField.Values.CopyTo, which would throw an exception unnecessarily + if provided exactly the right size of array to copy to. + * Fixed enum JSON formatting when multiple names mapped to the same numeric + value. + * Added JSON formatting option to format enums as integers. + * Modified RepeatedField to implement IReadOnlyList. + * Introduced the start of custom option handling; it's not as pleasant as it + might be, but the information is at least present. We expect to extend code + generation to improve this in the future. + * Introduced ByteString.FromStream and ByteString.FromStreamAsync to + efficiently create a ByteString from a stream. + * Added whole-message deprecation, which decorates the class with [Obsolete]. + + Ruby + * Fixed Message#to_h for messages with map fields. + * Fixed memcpy() in binary gems to work for old glibc, without breaking the + build for non-glibc libc’s like musl. + + Javascript + * Added compatibility tests for version 3.0.0. + * Added conformance tests. + * Fixed serialization of extensions: we need to emit a value even if it is + falsy (like the number 0). + * Use closurebuilder.py in favor of calcdeps.py for compiling JavaScript. + 2017-01-23 version 3.2.0 (C++/Java/Python/PHP/Ruby/Objective-C/C#/JavaScript/Lite) General * Added protoc version number to protoc plugin protocol. It can be used by diff --git a/third_party/protobuf/3.2.0/Makefile.am b/third_party/protobuf/3.2.0/Makefile.am index 0b2511f9ac..f1111898ca 100644 --- a/third_party/protobuf/3.2.0/Makefile.am +++ b/third_party/protobuf/3.2.0/Makefile.am @@ -247,6 +247,7 @@ java_EXTRA_DIST= java/core/src/main/java/com/google/protobuf/MutabilityOracle.java \ java/core/src/main/java/com/google/protobuf/NioByteString.java \ java/core/src/main/java/com/google/protobuf/Parser.java \ + java/core/src/main/java/com/google/protobuf/PrimitiveNonBoxingCollection.java \ java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java \ java/core/src/main/java/com/google/protobuf/ProtocolMessageEnum.java \ java/core/src/main/java/com/google/protobuf/ProtocolStringList.java \ @@ -645,6 +646,7 @@ php_EXTRA_DIST= \ php/src/Google/Protobuf/Internal/EnumBuilderContext.php \ php/src/Google/Protobuf/Internal/GPBUtil.php \ php/src/Google/Protobuf/Internal/FieldOptions_CType.php \ + php/src/Google/Protobuf/Internal/GPBDecodeException.php \ php/src/Google/Protobuf/descriptor.php \ php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php \ php/tests/array_test.php \ @@ -655,6 +657,7 @@ php_EXTRA_DIST= \ php/tests/map_field_test.php \ php/tests/memory_leak_test.php \ php/tests/php_implementation_test.php \ + php/tests/proto/test_import_descriptor_proto.proto \ php/tests/proto/test_include.proto \ php/tests/proto/test.proto \ php/tests/proto/test_prefix.proto \ @@ -710,6 +713,7 @@ python_EXTRA_DIST= \ python/google/protobuf/internal/packed_field_test.proto \ python/google/protobuf/internal/proto_builder_test.py \ python/google/protobuf/internal/python_message.py \ + python/google/protobuf/internal/python_protobuf.cc \ python/google/protobuf/internal/reflection_test.py \ python/google/protobuf/internal/service_reflection_test.py \ python/google/protobuf/internal/symbol_database_test.py \ @@ -752,13 +756,13 @@ python_EXTRA_DIST= \ python/google/protobuf/pyext/message_module.cc \ python/google/protobuf/pyext/proto2_api_test.proto \ python/google/protobuf/pyext/python.proto \ - python/google/protobuf/pyext/python_protobuf.h \ python/google/protobuf/pyext/repeated_composite_container.cc \ python/google/protobuf/pyext/repeated_composite_container.h \ python/google/protobuf/pyext/repeated_scalar_container.cc \ python/google/protobuf/pyext/repeated_scalar_container.h \ python/google/protobuf/pyext/safe_numerics.h \ python/google/protobuf/pyext/scoped_pyobject_ptr.h \ + python/google/protobuf/python_protobuf.h \ python/google/protobuf/reflection.py \ python/google/protobuf/service.py \ python/google/protobuf/service_reflection.py \ @@ -831,51 +835,80 @@ ruby_EXTRA_DIST= \ ruby/tests/well_known_types_test.rb \ ruby/travis-test.sh -js_EXTRA_DIST= \ - js/README.md \ - js/binary/arith.js \ - js/binary/arith_test.js \ - js/binary/constants.js \ - js/binary/decoder.js \ - js/binary/decoder_test.js \ - js/binary/encoder.js \ - js/binary/message_test.js \ - js/binary/proto_test.js \ - js/binary/reader.js \ - js/binary/reader_test.js \ - js/binary/utils.js \ - js/binary/utils_test.js \ - js/binary/writer.js \ - js/binary/writer_test.js \ - js/commonjs/export.js \ - js/commonjs/export_asserts.js \ - js/commonjs/export_testdeps.js \ - js/commonjs/import_test.js \ - js/commonjs/jasmine.json \ - js/commonjs/rewrite_tests_for_commonjs.js \ - js/commonjs/test6/test6.proto \ - js/commonjs/test7/test7.proto \ - js/data.proto \ - js/debug.js \ - js/debug_test.js \ - js/gulpfile.js \ - js/jasmine.json \ - js/map.js \ - js/maps_test.js \ - js/message.js \ - js/message_test.js \ - js/node_loader.js \ - js/package.json \ - js/proto3_test.js \ - js/proto3_test.proto \ - js/test.proto \ - js/test2.proto \ - js/test3.proto \ - js/test4.proto \ - js/test5.proto \ - js/test8.proto \ - js/test_bootstrap.js \ - js/testbinary.proto \ +js_EXTRA_DIST= \ + js/README.md \ + js/binary/arith.js \ + js/binary/arith_test.js \ + js/binary/constants.js \ + js/binary/decoder.js \ + js/binary/decoder_test.js \ + js/binary/encoder.js \ + js/binary/message_test.js \ + js/binary/proto_test.js \ + js/binary/reader.js \ + js/binary/reader_test.js \ + js/binary/utils.js \ + js/binary/utils_test.js \ + js/binary/writer.js \ + js/binary/writer_test.js \ + js/commonjs/export.js \ + js/commonjs/export_asserts.js \ + js/commonjs/export_testdeps.js \ + js/commonjs/import_test.js \ + js/commonjs/jasmine.json \ + js/commonjs/rewrite_tests_for_commonjs.js \ + js/commonjs/test6/test6.proto \ + js/commonjs/test7/test7.proto \ + js/compatibility_tests/v3.0.0/binary/arith_test.js \ + js/compatibility_tests/v3.0.0/binary/decoder_test.js \ + js/compatibility_tests/v3.0.0/binary/proto_test.js \ + js/compatibility_tests/v3.0.0/binary/reader_test.js \ + js/compatibility_tests/v3.0.0/binary/utils_test.js \ + js/compatibility_tests/v3.0.0/binary/writer_test.js \ + js/compatibility_tests/v3.0.0/commonjs/export_asserts.js \ + js/compatibility_tests/v3.0.0/commonjs/export_testdeps.js \ + js/compatibility_tests/v3.0.0/commonjs/import_test.js \ + js/compatibility_tests/v3.0.0/commonjs/jasmine.json \ + js/compatibility_tests/v3.0.0/commonjs/rewrite_tests_for_commonjs.js \ + js/compatibility_tests/v3.0.0/commonjs/test6/test6.proto \ + js/compatibility_tests/v3.0.0/commonjs/test7/test7.proto \ + js/compatibility_tests/v3.0.0/data.proto \ + js/compatibility_tests/v3.0.0/debug_test.js \ + js/compatibility_tests/v3.0.0/jasmine1.json \ + js/compatibility_tests/v3.0.0/jasmine2.json \ + js/compatibility_tests/v3.0.0/jasmine3.json \ + js/compatibility_tests/v3.0.0/message_test.js \ + js/compatibility_tests/v3.0.0/proto3_test.js \ + js/compatibility_tests/v3.0.0/proto3_test.proto \ + js/compatibility_tests/v3.0.0/test2.proto \ + js/compatibility_tests/v3.0.0/test3.proto \ + js/compatibility_tests/v3.0.0/test4.proto \ + js/compatibility_tests/v3.0.0/test5.proto \ + js/compatibility_tests/v3.0.0/testbinary.proto \ + js/compatibility_tests/v3.0.0/testempty.proto \ + js/compatibility_tests/v3.0.0/test.proto \ + js/compatibility_tests/v3.0.0/test.sh \ + js/data.proto \ + js/debug.js \ + js/debug_test.js \ + js/gulpfile.js \ + js/jasmine.json \ + js/map.js \ + js/maps_test.js \ + js/message.js \ + js/message_test.js \ + js/node_loader.js \ + js/package.json \ + js/proto3_test.js \ + js/proto3_test.proto \ + js/test.proto \ + js/test2.proto \ + js/test3.proto \ + js/test4.proto \ + js/test5.proto \ + js/test8.proto \ + js/test_bootstrap.js \ + js/testbinary.proto \ js/testempty.proto all_EXTRA_DIST=$(csharp_EXTRA_DIST) $(java_EXTRA_DIST) $(javanano_EXTRA_DIST) $(objectivec_EXTRA_DIST) $(php_EXTRA_DIST) $(python_EXTRA_DIST) $(ruby_EXTRA_DIST) $(js_EXTRA_DIST) diff --git a/third_party/protobuf/3.2.0/Protobuf.podspec b/third_party/protobuf/3.2.0/Protobuf.podspec index 0db70650ef..649f3ae3e1 100644 --- a/third_party/protobuf/3.2.0/Protobuf.podspec +++ b/third_party/protobuf/3.2.0/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.2.0' + s.version = '3.3.0' 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/third_party/protobuf/3.2.0/README.bazel.md b/third_party/protobuf/3.2.0/README.bazel.md deleted file mode 100644 index 75e448d927..0000000000 --- a/third_party/protobuf/3.2.0/README.bazel.md +++ /dev/null @@ -1,34 +0,0 @@ -# Updating protobuf - -1) Fetch the desired version from https://github.com/google/protobuf, - extract everything into a new directory and change into it. -2) Bazel uses upstream protobuf from source, except for java, as we - currently don't build protobuf java when bootstrapping bazel. So - instead we use already build jars. Go to `search.maven.org` and - search for `com.google.protobuf` and download the jars for protobuf-java - and protobuf-java-util and place them in the new directory. -3) Modify protobuf's `BUILD` file to not build java from source, but to use - the jars instead. To do that, in the BUILD file delete the rules listed - under `Java support`. Then, from the `third_party/protobuf/BUILD file` - copy the rules under "Modifications made by bazel" to the new BUILD file. - Those rules should have the same names as the ones you just deleted. You - will need to update the names of the jars in the rules sources to the - ones you just downloaded. -4) Copy `third_party/protobuf/com_google_protobuf_java.BUILD` to the new - directory. -5) Copy this file to the new directory and update it if you found the - instructions to be wrong or incomplete. -6) Replace the contents in `third_party/protobuf` with the contents in this - directory. -7) Protobuf compiles only with warnings, which we turn into errors. To fix - that, open time_util.cc and remove the constants kMicrosPerMillisecond - and kTimestampFormat. -8) Delete this directory. - -# Current protobuf version - -The current version of protobuf was obtained from @laszlocsomor's protobuf fork -`https://github.com/laszlocsomor/protobuf` at commit `421d90960d`. Once -`https://github.com/google/protobuf/pull/2969` is merged into upstream -protobuf, we no longer need to use @laszlocsomor's fork but can directly clone -upstream. diff --git a/third_party/protobuf/3.2.0/README.md b/third_party/protobuf/3.2.0/README.md index b26e5424af..e456863e8f 100644 --- a/third_party/protobuf/3.2.0/README.md +++ b/third_party/protobuf/3.2.0/README.md @@ -54,18 +54,19 @@ Protobuf supports several different programming languages. For each programming language, you can find instructions in the corresponding source directory about how to install protobuf runtime for that specific language: -| Language | Source | -|--------------------------------------|-------------------------------------------------------| -| C++ (include C++ runtime and protoc) | [src](src) | -| Java | [java](java) | -| Python | [python](python) | -| Objective-C | [objectivec](objectivec) | -| C# | [csharp](csharp) | -| JavaNano | [javanano](javanano) | -| JavaScript | [js](js) | -| Ruby | [ruby](ruby) | -| Go | [golang/protobuf](https://github.com/golang/protobuf) | -| PHP | [php](php) | +| Language | Source | +|--------------------------------------|-------------------------------------------------------------| +| C++ (include C++ runtime and protoc) | [src](src) | +| Java | [java](java) | +| Python | [python](python) | +| Objective-C | [objectivec](objectivec) | +| C# | [csharp](csharp) | +| JavaNano | [javanano](javanano) | +| JavaScript | [js](js) | +| Ruby | [ruby](ruby) | +| Go | [golang/protobuf](https://github.com/golang/protobuf) | +| PHP | [php](php) | +| Dart | [dart-lang/protobuf](https://github.com/dart-lang/protobuf) | Usage diff --git a/third_party/protobuf/3.2.0/cmake/extract_includes.bat.in b/third_party/protobuf/3.2.0/cmake/extract_includes.bat.in index a4fd762258..27ef126b83 100644 --- a/third_party/protobuf/3.2.0/cmake/extract_includes.bat.in +++ b/third_party/protobuf/3.2.0/cmake/extract_includes.bat.in @@ -36,6 +36,7 @@ copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\parser.h" in copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\php\php_generator.h" include\google\protobuf\compiler\php\php_generator.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\plugin.h" include\google\protobuf\compiler\plugin.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\plugin.pb.h" include\google\protobuf\compiler\plugin.pb.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\profile.pb.h" include\google\protobuf\compiler\profile.pb.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\python\python_generator.h" include\google\protobuf\compiler\python\python_generator.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\ruby\ruby_generator.h" include\google\protobuf\compiler\ruby\ruby_generator.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\descriptor.h" include\google\protobuf\descriptor.h @@ -96,6 +97,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 @@ -114,6 +116,7 @@ copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\text_format.h" includ copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\timestamp.pb.h" include\google\protobuf\timestamp.pb.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\type.pb.h" include\google\protobuf\type.pb.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\unknown_field_set.h" include\google\protobuf\unknown_field_set.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\delimited_message_util.h" include\google\protobuf\util\delimited_message_util.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\field_comparator.h" include\google\protobuf\util\field_comparator.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\field_mask_util.h" include\google\protobuf\util\field_mask_util.h copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\json_util.h" include\google\protobuf\util\json_util.h diff --git a/third_party/protobuf/3.2.0/cmake/libprotobuf-lite.cmake b/third_party/protobuf/3.2.0/cmake/libprotobuf-lite.cmake index 036b051707..f419784c70 100644 --- a/third_party/protobuf/3.2.0/cmake/libprotobuf-lite.cmake +++ b/third_party/protobuf/3.2.0/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/third_party/protobuf/3.2.0/cmake/libprotoc.cmake b/third_party/protobuf/3.2.0/cmake/libprotoc.cmake index 29b3253873..248688495a 100644 --- a/third_party/protobuf/3.2.0/cmake/libprotoc.cmake +++ b/third_party/protobuf/3.2.0/cmake/libprotoc.cmake @@ -88,10 +88,12 @@ set(libprotoc_files ${protobuf_source_dir}/src/google/protobuf/compiler/php/php_generator.cc ${protobuf_source_dir}/src/google/protobuf/compiler/plugin.cc ${protobuf_source_dir}/src/google/protobuf/compiler/plugin.pb.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/profile.pb.cc ${protobuf_source_dir}/src/google/protobuf/compiler/python/python_generator.cc ${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(js_well_known_types_sources diff --git a/third_party/protobuf/3.2.0/cmake/tests.cmake b/third_party/protobuf/3.2.0/cmake/tests.cmake index 1470e4b036..31f225753e 100644 --- a/third_party/protobuf/3.2.0/cmake/tests.cmake +++ b/third_party/protobuf/3.2.0/cmake/tests.cmake @@ -43,6 +43,9 @@ set(tests_protos google/protobuf/unittest_empty.proto google/protobuf/unittest_import.proto google/protobuf/unittest_import_public.proto + google/protobuf/unittest_lazy_dependencies.proto + google/protobuf/unittest_lazy_dependencies_custom_option.proto + google/protobuf/unittest_lazy_dependencies_enum.proto google/protobuf/unittest_lite_imports_nonlite.proto google/protobuf/unittest_mset.proto google/protobuf/unittest_mset_wire_format.proto @@ -157,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 @@ -195,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 @@ -207,7 +213,7 @@ set(lite_test_files ${protobuf_source_dir}/src/google/protobuf/lite_unittest.cc ) add_executable(lite-test ${lite_test_files} ${common_lite_test_files} ${lite_test_proto_files}) -target_link_libraries(lite-test libprotobuf-lite) +target_link_libraries(lite-test libprotobuf-lite gmock_main) set(lite_arena_test_files ${protobuf_source_dir}/src/google/protobuf/lite_arena_unittest.cc diff --git a/third_party/protobuf/3.2.0/com_google_protobuf_java.BUILD b/third_party/protobuf/3.2.0/com_google_protobuf_java.BUILD index c507b8a4c6..4f2c4a5c5e 100644 --- a/third_party/protobuf/3.2.0/com_google_protobuf_java.BUILD +++ b/third_party/protobuf/3.2.0/com_google_protobuf_java.BUILD @@ -1,6 +1,6 @@ java_import( name = "protobuf", - jars = ["protobuf-java-3.2.0.jar"], + jars = ["libprotobuf_java.jar"], ) proto_lang_toolchain( diff --git a/third_party/protobuf/3.2.0/configure.ac b/third_party/protobuf/3.2.0/configure.ac index 531e25fbc8..82b221e84c 100644 --- a/third_party/protobuf/3.2.0/configure.ac +++ b/third_party/protobuf/3.2.0/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.2.0],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.3.0],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/third_party/protobuf/3.2.0/conformance/conformance_test.cc b/third_party/protobuf/3.2.0/conformance/conformance_test.cc index 1e5387a54c..0dd7787c0c 100644 --- a/third_party/protobuf/3.2.0/conformance/conformance_test.cc +++ b/third_party/protobuf/3.2.0/conformance/conformance_test.cc @@ -708,6 +708,21 @@ bool ConformanceTestSuite::CheckSetEmpty(const set& set_to_check, } } +void ConformanceTestSuite::TestIllegalTags() { + // field num 0 is illegal + string nullfield[] = { + "\1DEADBEEF", + "\2\1\1", + "\3\4", + "\5DEAD" + }; + for (int i = 0; i < 4; i++) { + string name = "IllegalZeroFieldNum_Case_0"; + name.back() += i; + ExpectParseFailureForProto(nullfield[i], name, REQUIRED); + } +} + bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, std::string* output) { runner_ = runner; @@ -728,6 +743,8 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, TestPrematureEOFForType(static_cast(i)); } + TestIllegalTags(); + int64 kInt64Min = -9223372036854775808ULL; int64 kInt64Max = 9223372036854775807ULL; uint64 kUint64Max = 18446744073709551615ULL; diff --git a/third_party/protobuf/3.2.0/conformance/conformance_test.h b/third_party/protobuf/3.2.0/conformance/conformance_test.h index 5f05a25bcb..4e40a6acf3 100644 --- a/third_party/protobuf/3.2.0/conformance/conformance_test.h +++ b/third_party/protobuf/3.2.0/conformance/conformance_test.h @@ -201,6 +201,7 @@ class ConformanceTestSuite { const std::string& test_name, ConformanceLevel level); void TestPrematureEOFForType(google::protobuf::FieldDescriptor::Type type); + void TestIllegalTags(); void TestValidDataForType( google::protobuf::FieldDescriptor::Type, std::vector> values); diff --git a/third_party/protobuf/3.2.0/conformance/failure_list_cpp.txt b/third_party/protobuf/3.2.0/conformance/failure_list_cpp.txt index 8cfd74da6e..8a4fa7eb11 100644 --- a/third_party/protobuf/3.2.0/conformance/failure_list_cpp.txt +++ b/third_party/protobuf/3.2.0/conformance/failure_list_cpp.txt @@ -32,7 +32,6 @@ Recommended.JsonInput.TrailingCommaInAnObject Recommended.JsonInput.TrailingCommaInAnObjectWithNewlines Recommended.JsonInput.TrailingCommaInAnObjectWithSpace Recommended.JsonInput.TrailingCommaInAnObjectWithSpaceCommaSpace -Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.MESSAGE Required.ProtobufInput.PrematureEofInDelimitedDataForKnownNonRepeatedValue.MESSAGE Required.ProtobufInput.PrematureEofInDelimitedDataForKnownRepeatedValue.MESSAGE Required.ProtobufInput.PrematureEofInPackedField.BOOL @@ -43,4 +42,3 @@ Required.ProtobufInput.PrematureEofInPackedField.SINT32 Required.ProtobufInput.PrematureEofInPackedField.SINT64 Required.ProtobufInput.PrematureEofInPackedField.UINT32 Required.ProtobufInput.PrematureEofInPackedField.UINT64 -Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.MESSAGE diff --git a/third_party/protobuf/3.2.0/conformance/failure_list_csharp.txt b/third_party/protobuf/3.2.0/conformance/failure_list_csharp.txt index e69de29bb2..922db94c09 100644 --- a/third_party/protobuf/3.2.0/conformance/failure_list_csharp.txt +++ b/third_party/protobuf/3.2.0/conformance/failure_list_csharp.txt @@ -0,0 +1,4 @@ +Required.ProtobufInput.IllegalZeroFieldNum_Case_0 +Required.ProtobufInput.IllegalZeroFieldNum_Case_1 +Required.ProtobufInput.IllegalZeroFieldNum_Case_2 +Required.ProtobufInput.IllegalZeroFieldNum_Case_3 diff --git a/third_party/protobuf/3.2.0/conformance/failure_list_objc.txt b/third_party/protobuf/3.2.0/conformance/failure_list_objc.txt index dd538c1036..6e0da6cf3e 100644 --- a/third_party/protobuf/3.2.0/conformance/failure_list_objc.txt +++ b/third_party/protobuf/3.2.0/conformance/failure_list_objc.txt @@ -1,4 +1,6 @@ -# All tests currently passing. -# # JSON input or output tests are skipped (in conformance_objc.m) as mobile # platforms don't support JSON wire format to avoid code bloat. +Required.ProtobufInput.IllegalZeroFieldNum_Case_0 +Required.ProtobufInput.IllegalZeroFieldNum_Case_1 +Required.ProtobufInput.IllegalZeroFieldNum_Case_2 +Required.ProtobufInput.IllegalZeroFieldNum_Case_3 diff --git a/third_party/protobuf/3.2.0/conformance/failure_list_php_c.txt b/third_party/protobuf/3.2.0/conformance/failure_list_php_c.txt index 05cb218a61..f53449f7d5 100644 --- a/third_party/protobuf/3.2.0/conformance/failure_list_php_c.txt +++ b/third_party/protobuf/3.2.0/conformance/failure_list_php_c.txt @@ -8,6 +8,7 @@ Recommended.JsonInput.DurationHas6FractionalDigits.Validator Recommended.JsonInput.DurationHas9FractionalDigits.Validator Recommended.JsonInput.DurationHasZeroFractionalDigit.Validator Recommended.JsonInput.Int64FieldBeString.Validator +Recommended.JsonInput.MapFieldValueIsNull Recommended.JsonInput.OneofZeroBool.JsonOutput Recommended.JsonInput.OneofZeroBool.ProtobufOutput Recommended.JsonInput.OneofZeroBytes.JsonOutput @@ -24,6 +25,8 @@ Recommended.JsonInput.OneofZeroUint32.JsonOutput Recommended.JsonInput.OneofZeroUint32.ProtobufOutput Recommended.JsonInput.OneofZeroUint64.JsonOutput Recommended.JsonInput.OneofZeroUint64.ProtobufOutput +Recommended.JsonInput.RepeatedFieldMessageElementIsNull +Recommended.JsonInput.RepeatedFieldPrimitiveElementIsNull Recommended.JsonInput.StringEndsWithEscapeChar Recommended.JsonInput.StringFieldSurrogateInWrongOrder Recommended.JsonInput.StringFieldUnpairedHighSurrogate @@ -127,24 +130,12 @@ Required.JsonInput.Int32FieldStringValue.JsonOutput Required.JsonInput.Int32FieldStringValue.ProtobufOutput Required.JsonInput.Int32FieldStringValueEscaped.JsonOutput Required.JsonInput.Int32FieldStringValueEscaped.ProtobufOutput -Required.JsonInput.Int32MapEscapedKey.JsonOutput -Required.JsonInput.Int32MapEscapedKey.ProtobufOutput -Required.JsonInput.Int32MapField.JsonOutput -Required.JsonInput.Int32MapField.ProtobufOutput Required.JsonInput.Int64FieldMaxValue.JsonOutput Required.JsonInput.Int64FieldMaxValue.ProtobufOutput Required.JsonInput.Int64FieldMinValue.JsonOutput Required.JsonInput.Int64FieldMinValue.ProtobufOutput -Required.JsonInput.Int64MapEscapedKey.JsonOutput -Required.JsonInput.Int64MapEscapedKey.ProtobufOutput -Required.JsonInput.Int64MapField.JsonOutput -Required.JsonInput.Int64MapField.ProtobufOutput Required.JsonInput.MessageField.JsonOutput Required.JsonInput.MessageField.ProtobufOutput -Required.JsonInput.MessageMapField.JsonOutput -Required.JsonInput.MessageMapField.ProtobufOutput -Required.JsonInput.MessageRepeatedField.JsonOutput -Required.JsonInput.MessageRepeatedField.ProtobufOutput Required.JsonInput.OptionalBoolWrapper.JsonOutput Required.JsonInput.OptionalBoolWrapper.ProtobufOutput Required.JsonInput.OptionalBytesWrapper.JsonOutput @@ -165,14 +156,13 @@ Required.JsonInput.OptionalUint64Wrapper.JsonOutput Required.JsonInput.OptionalUint64Wrapper.ProtobufOutput Required.JsonInput.OptionalWrapperTypesWithNonDefaultValue.JsonOutput Required.JsonInput.OptionalWrapperTypesWithNonDefaultValue.ProtobufOutput -Required.JsonInput.PrimitiveRepeatedField.JsonOutput -Required.JsonInput.PrimitiveRepeatedField.ProtobufOutput Required.JsonInput.RepeatedBoolWrapper.JsonOutput Required.JsonInput.RepeatedBoolWrapper.ProtobufOutput Required.JsonInput.RepeatedBytesWrapper.JsonOutput Required.JsonInput.RepeatedBytesWrapper.ProtobufOutput Required.JsonInput.RepeatedDoubleWrapper.JsonOutput Required.JsonInput.RepeatedDoubleWrapper.ProtobufOutput +Required.JsonInput.RepeatedFieldWrongElementTypeExpectingMessagesGotInt Required.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotInt Required.JsonInput.RepeatedFloatWrapper.JsonOutput Required.JsonInput.RepeatedFloatWrapper.ProtobufOutput @@ -186,9 +176,15 @@ Required.JsonInput.RepeatedUint32Wrapper.JsonOutput Required.JsonInput.RepeatedUint32Wrapper.ProtobufOutput Required.JsonInput.RepeatedUint64Wrapper.JsonOutput Required.JsonInput.RepeatedUint64Wrapper.ProtobufOutput +Required.JsonInput.StringFieldEscape.JsonOutput +Required.JsonInput.StringFieldEscape.ProtobufOutput Required.JsonInput.StringFieldNotAString Required.JsonInput.StringFieldSurrogatePair.JsonOutput Required.JsonInput.StringFieldSurrogatePair.ProtobufOutput +Required.JsonInput.StringFieldUnicodeEscape.JsonOutput +Required.JsonInput.StringFieldUnicodeEscape.ProtobufOutput +Required.JsonInput.StringFieldUnicodeEscapeWithLowercaseHexLetters.JsonOutput +Required.JsonInput.StringFieldUnicodeEscapeWithLowercaseHexLetters.ProtobufOutput Required.JsonInput.Struct.JsonOutput Required.JsonInput.Struct.ProtobufOutput Required.JsonInput.TimestampMaxValue.JsonOutput @@ -203,12 +199,8 @@ Required.JsonInput.TimestampWithPositiveOffset.JsonOutput Required.JsonInput.TimestampWithPositiveOffset.ProtobufOutput Required.JsonInput.Uint32FieldMaxFloatValue.JsonOutput Required.JsonInput.Uint32FieldMaxFloatValue.ProtobufOutput -Required.JsonInput.Uint32MapField.JsonOutput -Required.JsonInput.Uint32MapField.ProtobufOutput Required.JsonInput.Uint64FieldMaxValue.JsonOutput Required.JsonInput.Uint64FieldMaxValue.ProtobufOutput -Required.JsonInput.Uint64MapField.JsonOutput -Required.JsonInput.Uint64MapField.ProtobufOutput Required.JsonInput.ValueAcceptBool.JsonOutput Required.JsonInput.ValueAcceptBool.ProtobufOutput Required.JsonInput.ValueAcceptFloat.JsonOutput diff --git a/third_party/protobuf/3.2.0/conformance/failure_list_python.txt b/third_party/protobuf/3.2.0/conformance/failure_list_python.txt index 9d556a036b..965b8212a5 100644 --- a/third_party/protobuf/3.2.0/conformance/failure_list_python.txt +++ b/third_party/protobuf/3.2.0/conformance/failure_list_python.txt @@ -11,3 +11,7 @@ Required.JsonInput.FloatFieldTooLarge Required.JsonInput.FloatFieldTooSmall Required.JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotBool Required.JsonInput.TimestampJsonInputLowercaseT +Required.ProtobufInput.IllegalZeroFieldNum_Case_0 +Required.ProtobufInput.IllegalZeroFieldNum_Case_1 +Required.ProtobufInput.IllegalZeroFieldNum_Case_2 +Required.ProtobufInput.IllegalZeroFieldNum_Case_3 diff --git a/third_party/protobuf/3.2.0/csharp/Google.Protobuf.Tools.nuspec b/third_party/protobuf/3.2.0/csharp/Google.Protobuf.Tools.nuspec index 0b9cbcf423..182309bf13 100644 --- a/third_party/protobuf/3.2.0/csharp/Google.Protobuf.Tools.nuspec +++ b/third_party/protobuf/3.2.0/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers tools Tools for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.2.0 + 3.3.0 Google Inc. protobuf-packages https://github.com/google/protobuf/blob/master/LICENSE diff --git a/third_party/protobuf/3.2.0/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/third_party/protobuf/3.2.0/csharp/src/Google.Protobuf/Reflection/Descriptor.cs index d4b78daec9..2960d1cdcb 100644 --- a/third_party/protobuf/3.2.0/csharp/src/Google.Protobuf/Reflection/Descriptor.cs +++ b/third_party/protobuf/3.2.0/csharp/src/Google.Protobuf/Reflection/Descriptor.cs @@ -95,57 +95,58 @@ namespace Google.Protobuf.Reflection { "X3ByZWZpeBgoIAEoCRJDChR1bmludGVycHJldGVkX29wdGlvbhjnByADKAsy", "JC5nb29nbGUucHJvdG9idWYuVW5pbnRlcnByZXRlZE9wdGlvbiI6CgxPcHRp", "bWl6ZU1vZGUSCQoFU1BFRUQQARINCglDT0RFX1NJWkUQAhIQCgxMSVRFX1JV", - "TlRJTUUQAyoJCOgHEICAgIACSgQIJhAnIuwBCg5NZXNzYWdlT3B0aW9ucxIm", + "TlRJTUUQAyoJCOgHEICAgIACSgQIJhAnIvIBCg5NZXNzYWdlT3B0aW9ucxIm", "ChdtZXNzYWdlX3NldF93aXJlX2Zvcm1hdBgBIAEoCDoFZmFsc2USLgofbm9f", "c3RhbmRhcmRfZGVzY3JpcHRvcl9hY2Nlc3NvchgCIAEoCDoFZmFsc2USGQoK", "ZGVwcmVjYXRlZBgDIAEoCDoFZmFsc2USEQoJbWFwX2VudHJ5GAcgASgIEkMK", "FHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1", - "Zi5VbmludGVycHJldGVkT3B0aW9uKgkI6AcQgICAgAJKBAgIEAkingMKDEZp", - "ZWxkT3B0aW9ucxI6CgVjdHlwZRgBIAEoDjIjLmdvb2dsZS5wcm90b2J1Zi5G", - "aWVsZE9wdGlvbnMuQ1R5cGU6BlNUUklORxIOCgZwYWNrZWQYAiABKAgSPwoG", - "anN0eXBlGAYgASgOMiQuZ29vZ2xlLnByb3RvYnVmLkZpZWxkT3B0aW9ucy5K", - "U1R5cGU6CUpTX05PUk1BTBITCgRsYXp5GAUgASgIOgVmYWxzZRIZCgpkZXBy", - "ZWNhdGVkGAMgASgIOgVmYWxzZRITCgR3ZWFrGAogASgIOgVmYWxzZRJDChR1", - "bmludGVycHJldGVkX29wdGlvbhjnByADKAsyJC5nb29nbGUucHJvdG9idWYu", - "VW5pbnRlcnByZXRlZE9wdGlvbiIvCgVDVHlwZRIKCgZTVFJJTkcQABIICgRD", - "T1JEEAESEAoMU1RSSU5HX1BJRUNFEAIiNQoGSlNUeXBlEg0KCUpTX05PUk1B", - "TBAAEg0KCUpTX1NUUklORxABEg0KCUpTX05VTUJFUhACKgkI6AcQgICAgAJK", - "BAgEEAUiXgoMT25lb2ZPcHRpb25zEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9u", + "Zi5VbmludGVycHJldGVkT3B0aW9uKgkI6AcQgICAgAJKBAgIEAlKBAgJEAoi", + "ngMKDEZpZWxkT3B0aW9ucxI6CgVjdHlwZRgBIAEoDjIjLmdvb2dsZS5wcm90", + "b2J1Zi5GaWVsZE9wdGlvbnMuQ1R5cGU6BlNUUklORxIOCgZwYWNrZWQYAiAB", + "KAgSPwoGanN0eXBlGAYgASgOMiQuZ29vZ2xlLnByb3RvYnVmLkZpZWxkT3B0", + "aW9ucy5KU1R5cGU6CUpTX05PUk1BTBITCgRsYXp5GAUgASgIOgVmYWxzZRIZ", + "CgpkZXByZWNhdGVkGAMgASgIOgVmYWxzZRITCgR3ZWFrGAogASgIOgVmYWxz", + "ZRJDChR1bmludGVycHJldGVkX29wdGlvbhjnByADKAsyJC5nb29nbGUucHJv", + "dG9idWYuVW5pbnRlcnByZXRlZE9wdGlvbiIvCgVDVHlwZRIKCgZTVFJJTkcQ", + "ABIICgRDT1JEEAESEAoMU1RSSU5HX1BJRUNFEAIiNQoGSlNUeXBlEg0KCUpT", + "X05PUk1BTBAAEg0KCUpTX1NUUklORxABEg0KCUpTX05VTUJFUhACKgkI6AcQ", + "gICAgAJKBAgEEAUiXgoMT25lb2ZPcHRpb25zEkMKFHVuaW50ZXJwcmV0ZWRf", + "b3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVk", + "T3B0aW9uKgkI6AcQgICAgAIikwEKC0VudW1PcHRpb25zEhMKC2FsbG93X2Fs", + "aWFzGAIgASgIEhkKCmRlcHJlY2F0ZWQYAyABKAg6BWZhbHNlEkMKFHVuaW50", + "ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5Vbmlu", + "dGVycHJldGVkT3B0aW9uKgkI6AcQgICAgAJKBAgFEAYifQoQRW51bVZhbHVl", + "T3B0aW9ucxIZCgpkZXByZWNhdGVkGAEgASgIOgVmYWxzZRJDChR1bmludGVy", + "cHJldGVkX29wdGlvbhjnByADKAsyJC5nb29nbGUucHJvdG9idWYuVW5pbnRl", + "cnByZXRlZE9wdGlvbioJCOgHEICAgIACInsKDlNlcnZpY2VPcHRpb25zEhkK", + "CmRlcHJlY2F0ZWQYISABKAg6BWZhbHNlEkMKFHVuaW50ZXJwcmV0ZWRfb3B0", + "aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0", + "aW9uKgkI6AcQgICAgAIirQIKDU1ldGhvZE9wdGlvbnMSGQoKZGVwcmVjYXRl", + "ZBghIAEoCDoFZmFsc2USXwoRaWRlbXBvdGVuY3lfbGV2ZWwYIiABKA4yLy5n", + "b29nbGUucHJvdG9idWYuTWV0aG9kT3B0aW9ucy5JZGVtcG90ZW5jeUxldmVs", + "OhNJREVNUE9URU5DWV9VTktOT1dOEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9u", "GOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9u", - "KgkI6AcQgICAgAIijQEKC0VudW1PcHRpb25zEhMKC2FsbG93X2FsaWFzGAIg", - "ASgIEhkKCmRlcHJlY2F0ZWQYAyABKAg6BWZhbHNlEkMKFHVuaW50ZXJwcmV0", - "ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJl", - "dGVkT3B0aW9uKgkI6AcQgICAgAIifQoQRW51bVZhbHVlT3B0aW9ucxIZCgpk", - "ZXByZWNhdGVkGAEgASgIOgVmYWxzZRJDChR1bmludGVycHJldGVkX29wdGlv", - "bhjnByADKAsyJC5nb29nbGUucHJvdG9idWYuVW5pbnRlcnByZXRlZE9wdGlv", - "bioJCOgHEICAgIACInsKDlNlcnZpY2VPcHRpb25zEhkKCmRlcHJlY2F0ZWQY", - "ISABKAg6BWZhbHNlEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIk", - "Lmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uKgkI6AcQgICA", - "gAIirQIKDU1ldGhvZE9wdGlvbnMSGQoKZGVwcmVjYXRlZBghIAEoCDoFZmFs", - "c2USXwoRaWRlbXBvdGVuY3lfbGV2ZWwYIiABKA4yLy5nb29nbGUucHJvdG9i", - "dWYuTWV0aG9kT3B0aW9ucy5JZGVtcG90ZW5jeUxldmVsOhNJREVNUE9URU5D", - "WV9VTktOT1dOEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdv", - "b2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uIlAKEElkZW1wb3Rl", - "bmN5TGV2ZWwSFwoTSURFTVBPVEVOQ1lfVU5LTk9XThAAEhMKD05PX1NJREVf", - "RUZGRUNUUxABEg4KCklERU1QT1RFTlQQAioJCOgHEICAgIACIp4CChNVbmlu", - "dGVycHJldGVkT3B0aW9uEjsKBG5hbWUYAiADKAsyLS5nb29nbGUucHJvdG9i", - "dWYuVW5pbnRlcnByZXRlZE9wdGlvbi5OYW1lUGFydBIYChBpZGVudGlmaWVy", - "X3ZhbHVlGAMgASgJEhoKEnBvc2l0aXZlX2ludF92YWx1ZRgEIAEoBBIaChJu", - "ZWdhdGl2ZV9pbnRfdmFsdWUYBSABKAMSFAoMZG91YmxlX3ZhbHVlGAYgASgB", - "EhQKDHN0cmluZ192YWx1ZRgHIAEoDBIXCg9hZ2dyZWdhdGVfdmFsdWUYCCAB", - "KAkaMwoITmFtZVBhcnQSEQoJbmFtZV9wYXJ0GAEgAigJEhQKDGlzX2V4dGVu", - "c2lvbhgCIAIoCCLVAQoOU291cmNlQ29kZUluZm8SOgoIbG9jYXRpb24YASAD", - "KAsyKC5nb29nbGUucHJvdG9idWYuU291cmNlQ29kZUluZm8uTG9jYXRpb24a", - "hgEKCExvY2F0aW9uEhAKBHBhdGgYASADKAVCAhABEhAKBHNwYW4YAiADKAVC", - "AhABEhgKEGxlYWRpbmdfY29tbWVudHMYAyABKAkSGQoRdHJhaWxpbmdfY29t", - "bWVudHMYBCABKAkSIQoZbGVhZGluZ19kZXRhY2hlZF9jb21tZW50cxgGIAMo", - "CSKnAQoRR2VuZXJhdGVkQ29kZUluZm8SQQoKYW5ub3RhdGlvbhgBIAMoCzIt", - "Lmdvb2dsZS5wcm90b2J1Zi5HZW5lcmF0ZWRDb2RlSW5mby5Bbm5vdGF0aW9u", - "Gk8KCkFubm90YXRpb24SEAoEcGF0aBgBIAMoBUICEAESEwoLc291cmNlX2Zp", - "bGUYAiABKAkSDQoFYmVnaW4YAyABKAUSCwoDZW5kGAQgASgFQowBChNjb20u", - "Z29vZ2xlLnByb3RvYnVmQhBEZXNjcmlwdG9yUHJvdG9zSAFaPmdpdGh1Yi5j", - "b20vZ29sYW5nL3Byb3RvYnVmL3Byb3RvYy1nZW4tZ28vZGVzY3JpcHRvcjtk", - "ZXNjcmlwdG9yogIDR1BCqgIaR29vZ2xlLlByb3RvYnVmLlJlZmxlY3Rpb24=")); + "IlAKEElkZW1wb3RlbmN5TGV2ZWwSFwoTSURFTVBPVEVOQ1lfVU5LTk9XThAA", + "EhMKD05PX1NJREVfRUZGRUNUUxABEg4KCklERU1QT1RFTlQQAioJCOgHEICA", + "gIACIp4CChNVbmludGVycHJldGVkT3B0aW9uEjsKBG5hbWUYAiADKAsyLS5n", + "b29nbGUucHJvdG9idWYuVW5pbnRlcnByZXRlZE9wdGlvbi5OYW1lUGFydBIY", + "ChBpZGVudGlmaWVyX3ZhbHVlGAMgASgJEhoKEnBvc2l0aXZlX2ludF92YWx1", + "ZRgEIAEoBBIaChJuZWdhdGl2ZV9pbnRfdmFsdWUYBSABKAMSFAoMZG91Ymxl", + "X3ZhbHVlGAYgASgBEhQKDHN0cmluZ192YWx1ZRgHIAEoDBIXCg9hZ2dyZWdh", + "dGVfdmFsdWUYCCABKAkaMwoITmFtZVBhcnQSEQoJbmFtZV9wYXJ0GAEgAigJ", + "EhQKDGlzX2V4dGVuc2lvbhgCIAIoCCLVAQoOU291cmNlQ29kZUluZm8SOgoI", + "bG9jYXRpb24YASADKAsyKC5nb29nbGUucHJvdG9idWYuU291cmNlQ29kZUlu", + "Zm8uTG9jYXRpb24ahgEKCExvY2F0aW9uEhAKBHBhdGgYASADKAVCAhABEhAK", + "BHNwYW4YAiADKAVCAhABEhgKEGxlYWRpbmdfY29tbWVudHMYAyABKAkSGQoR", + "dHJhaWxpbmdfY29tbWVudHMYBCABKAkSIQoZbGVhZGluZ19kZXRhY2hlZF9j", + "b21tZW50cxgGIAMoCSKnAQoRR2VuZXJhdGVkQ29kZUluZm8SQQoKYW5ub3Rh", + "dGlvbhgBIAMoCzItLmdvb2dsZS5wcm90b2J1Zi5HZW5lcmF0ZWRDb2RlSW5m", + "by5Bbm5vdGF0aW9uGk8KCkFubm90YXRpb24SEAoEcGF0aBgBIAMoBUICEAES", + "EwoLc291cmNlX2ZpbGUYAiABKAkSDQoFYmVnaW4YAyABKAUSCwoDZW5kGAQg", + "ASgFQowBChNjb20uZ29vZ2xlLnByb3RvYnVmQhBEZXNjcmlwdG9yUHJvdG9z", + "SAFaPmdpdGh1Yi5jb20vZ29sYW5nL3Byb3RvYnVmL3Byb3RvYy1nZW4tZ28v", + "ZGVzY3JpcHRvcjtkZXNjcmlwdG9yogIDR1BCqgIaR29vZ2xlLlByb3RvYnVm", + "LlJlZmxlY3Rpb24=")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { diff --git a/third_party/protobuf/3.2.0/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs b/third_party/protobuf/3.2.0/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs index 03b19c774c..94159cb84c 100644 --- a/third_party/protobuf/3.2.0/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs +++ b/third_party/protobuf/3.2.0/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs @@ -46,6 +46,8 @@ namespace Google.Protobuf.WellKnownTypes { /// two Timestamp values is a Duration and it can be added or subtracted /// from a Timestamp. Range is approximately +-10,000 years. /// + /// # Examples + /// /// Example 1: Compute Duration from two Timestamps in pseudo code. /// /// Timestamp start = ...; @@ -85,6 +87,16 @@ namespace Google.Protobuf.WellKnownTypes { /// td = datetime.timedelta(days=3, minutes=10) /// duration = Duration() /// duration.FromTimedelta(td) + /// + /// # JSON Mapping + /// + /// In JSON format, the Duration type is encoded as a string rather than an + /// object, where the string ends in the suffix "s" (indicating seconds) and + /// is preceded by the number of seconds, with nanoseconds expressed as + /// fractional seconds. For example, 3 seconds with 0 nanoseconds should be + /// encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should + /// be expressed in JSON format as "3.000000001s", and 3 seconds and 1 + /// microsecond should be expressed in JSON format as "3.000001s". /// public sealed partial class Duration : pb::IMessage { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Duration()); @@ -124,7 +136,8 @@ namespace Google.Protobuf.WellKnownTypes { private long seconds_; /// /// Signed seconds of the span of time. Must be from -315,576,000,000 - /// to +315,576,000,000 inclusive. + /// to +315,576,000,000 inclusive. Note: these bounds are computed from: + /// 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years /// [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public long Seconds { diff --git a/third_party/protobuf/3.2.0/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs b/third_party/protobuf/3.2.0/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs index b789f6da7b..911f797e01 100644 --- a/third_party/protobuf/3.2.0/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs +++ b/third_party/protobuf/3.2.0/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs @@ -51,6 +51,8 @@ namespace Google.Protobuf.WellKnownTypes { /// and from RFC 3339 date strings. /// See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt). /// + /// # Examples + /// /// Example 1: Compute Timestamp from POSIX `time()`. /// /// Timestamp timestamp; @@ -89,6 +91,29 @@ namespace Google.Protobuf.WellKnownTypes { /// /// timestamp = Timestamp() /// timestamp.GetCurrentTime() + /// + /// # JSON Mapping + /// + /// In JSON format, the Timestamp type is encoded as a string in the + /// [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the + /// format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" + /// where {year} is always expressed using four digits while {month}, {day}, + /// {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional + /// seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), + /// are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone + /// is required, though only UTC (as indicated by "Z") is presently supported. + /// + /// For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past + /// 01:30 UTC on January 15, 2017. + /// + /// In JavaScript, one can convert a Date object to this format using the + /// standard [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString] + /// method. In Python, a standard `datetime.datetime` object can be converted + /// to this format using [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) + /// with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one + /// can use the Joda Time's [`ISODateTimeFormat.dateTime()`]( + /// http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime()) + /// to obtain a formatter capable of generating timestamps in this format. /// public sealed partial class Timestamp : pb::IMessage { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Timestamp()); diff --git a/third_party/protobuf/3.2.0/csharp/src/Google.Protobuf/project.json b/third_party/protobuf/3.2.0/csharp/src/Google.Protobuf/project.json index 961e037e18..f437623895 100644 --- a/third_party/protobuf/3.2.0/csharp/src/Google.Protobuf/project.json +++ b/third_party/protobuf/3.2.0/csharp/src/Google.Protobuf/project.json @@ -1,5 +1,5 @@ { - "version": "3.2.0", + "version": "3.3.0", "title": "Google Protocol Buffers", "description": "See project site for more info.", "authors": [ "Google Inc." ], diff --git a/third_party/protobuf/3.2.0/docs/third_party.md b/third_party/protobuf/3.2.0/docs/third_party.md index a1f918a749..3def00359f 100644 --- a/third_party/protobuf/3.2.0/docs/third_party.md +++ b/third_party/protobuf/3.2.0/docs/third_party.md @@ -39,8 +39,8 @@ These are projects we know about implementing Protocol Buffers for other program * Erlang: https://github.com/basho/erlang_protobuffs * Erlang: https://github.com/tomas-abrahamsson/gpb * Go: https://github.com/golang/protobuf (Google-official implementation) -* Go: http://code.google.com/p/goprotobuf/ * Go: https://github.com/akunspy/gopbuf +* Go: https://github.com/gogo/protobuf * Haskell: http://hackage.haskell.org/package/hprotoc * Haxe: https://github.com/Atry/protoc-gen-haxe * Java: https://github.com/google/protobuf (Google-official implementation) @@ -154,3 +154,4 @@ There are miscellaneous other things you may find useful as a Protocol Buffers d * [Notepad++ Syntax Highlighting for .proto files](https://github.com/chai2010/notepadplus-protobuf) * [Linter for .proto files](https://github.com/ckaznocha/protoc-gen-lint) * [Protocol Buffers Dynamic Schema - create protobuf schemas programmatically (Java)] (https://github.com/os72/protobuf-dynamic) +* [Make protoc plugins in NodeJS](https://github.com/konsumer/node-protoc-plugin) diff --git a/third_party/protobuf/3.2.0/generate_descriptor_proto.sh b/third_party/protobuf/3.2.0/generate_descriptor_proto.sh index 809214cea5..229bec4355 100755 --- a/third_party/protobuf/3.2.0/generate_descriptor_proto.sh +++ b/third_party/protobuf/3.2.0/generate_descriptor_proto.sh @@ -41,6 +41,11 @@ declare -a RUNTIME_PROTO_FILES=(\ google/protobuf/type.proto \ google/protobuf/wrappers.proto) +declare -a COMPILER_PROTO_FILES=(\ + google/protobuf/compiler/plugin.proto \ + google/protobuf/compiler/profile.proto \ +) + CORE_PROTO_IS_CORRECT=0 PROCESS_ROUND=1 TMP=$(mktemp -d) @@ -57,9 +62,9 @@ do fi ./protoc --cpp_out=dllexport_decl=LIBPROTOBUF_EXPORT:$TMP ${RUNTIME_PROTO_FILES[@]} && \ - ./protoc --cpp_out=dllexport_decl=LIBPROTOC_EXPORT:$TMP google/protobuf/compiler/plugin.proto + ./protoc --cpp_out=dllexport_decl=LIBPROTOC_EXPORT:$TMP ${COMPILER_PROTO_FILES[@]} - for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]}; do + for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]} ${COMPILER_PROTO_FILES[@]}; do BASE_NAME=${PROTO_FILE%.*} diff ${BASE_NAME}.pb.h $TMP/${BASE_NAME}.pb.h > /dev/null if test $? -ne 0; then @@ -71,24 +76,14 @@ do fi done - diff google/protobuf/compiler/plugin.pb.h $TMP/google/protobuf/compiler/plugin.pb.h > /dev/null - if test $? -ne 0; then - CORE_PROTO_IS_CORRECT=0 - fi - diff google/protobuf/compiler/plugin.pb.cc $TMP/google/protobuf/compiler/plugin.pb.cc > /dev/null - if test $? -ne 0; then - CORE_PROTO_IS_CORRECT=0 - fi - # Only override the output if the files are different to avoid re-compilation # of the protoc. if [ $CORE_PROTO_IS_CORRECT -ne 1 ]; then - for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]}; do + for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]} ${COMPILER_PROTO_FILES[@]}; do BASE_NAME=${PROTO_FILE%.*} mv $TMP/${BASE_NAME}.pb.h ${BASE_NAME}.pb.h mv $TMP/${BASE_NAME}.pb.cc ${BASE_NAME}.pb.cc done - mv $TMP/google/protobuf/compiler/plugin.pb.* google/protobuf/compiler/ fi PROCESS_ROUND=$((PROCESS_ROUND + 1)) diff --git a/third_party/protobuf/3.2.0/java/core/pom.xml b/third_party/protobuf/3.2.0/java/core/pom.xml index be0da5eade..9c4e1b930b 100644 --- a/third_party/protobuf/3.2.0/java/core/pom.xml +++ b/third_party/protobuf/3.2.0/java/core/pom.xml @@ -6,7 +6,7 @@ com.google.protobuf protobuf-parent - 3.2.0 + 3.3.0 protobuf-java @@ -34,6 +34,11 @@ easymockclassextension test + + com.google.truth + truth + test + diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/AbstractMessage.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/AbstractMessage.java index 37180da857..b5043eb543 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/AbstractMessage.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/AbstractMessage.java @@ -34,7 +34,6 @@ import com.google.protobuf.Descriptors.EnumValueDescriptor; import com.google.protobuf.Descriptors.FieldDescriptor; import com.google.protobuf.Descriptors.OneofDescriptor; import com.google.protobuf.Internal.EnumLite; - import java.io.IOException; import java.io.InputStream; import java.util.Arrays; @@ -328,7 +327,8 @@ public abstract class AbstractMessage extends AbstractMessageLite.Builder implements Message.Builder { // The compiler produces an error if this is not declared explicitly. - // Method isn't abstract to bypass Java 1.6 compiler issue http://bugs.java.com/view_bug.do?bug_id=6908259 + // Method isn't abstract to bypass Java 1.6 compiler issue: + // http://bugs.java.com/view_bug.do?bug_id=6908259 @Override public BuilderType clone() { throw new UnsupportedOperationException("clone() should be implemented in subclasses."); diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java index 4f691dfdfb..99787fcc7e 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java @@ -30,6 +30,8 @@ package com.google.protobuf; +import static com.google.protobuf.Internal.checkNotNull; + import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; @@ -351,22 +353,23 @@ public abstract class AbstractMessageLite< */ protected static void addAll(final Iterable values, final Collection list) { - if (values == null) { - throw new NullPointerException(); - } + checkNotNull(values); if (values instanceof LazyStringList) { // For StringOrByteStringLists, check the underlying elements to avoid // forcing conversions of ByteStrings to Strings. + // TODO(dweis): Could we just prohibit nulls in all protobuf lists and get rid of this? Is + // if even possible to hit this condition as all protobuf methods check for null first, + // right? checkForNullValues(((LazyStringList) values).getUnderlyingElements()); list.addAll((Collection) values); } else if (values instanceof Collection) { - checkForNullValues(values); + if (!(values instanceof PrimitiveNonBoxingCollection)) { + checkForNullValues(values); + } list.addAll((Collection) values); } else { for (final T value : values) { - if (value == null) { - throw new NullPointerException(); - } + checkNotNull(value); list.add(value); } } @@ -374,9 +377,7 @@ public abstract class AbstractMessageLite< private static void checkForNullValues(final Iterable values) { for (final Object value : values) { - if (value == null) { - throw new NullPointerException(); - } + checkNotNull(value); } } } diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/AbstractParser.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/AbstractParser.java index 7ff73ba4d1..ba570e3df1 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/AbstractParser.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/AbstractParser.java @@ -31,9 +31,9 @@ package com.google.protobuf; import com.google.protobuf.AbstractMessageLite.Builder.LimitedInputStream; - import java.io.IOException; import java.io.InputStream; +import java.nio.ByteBuffer; /** * A partial implementation of the {@link Parser} interface which implements @@ -130,6 +130,30 @@ public abstract class AbstractParser return parseFrom(data, EMPTY_REGISTRY); } + @Override + public MessageType parseFrom(ByteBuffer data, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + MessageType message; + try { + CodedInputStream input = CodedInputStream.newInstance(data); + message = parsePartialFrom(input, extensionRegistry); + try { + input.checkLastTagWas(0); + } catch (InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(message); + } + } catch (InvalidProtocolBufferException e) { + throw e; + } + + return checkMessageInitialized(message); + } + + @Override + public MessageType parseFrom(ByteBuffer data) throws InvalidProtocolBufferException { + return parseFrom(data, EMPTY_REGISTRY); + } + @Override public MessageType parsePartialFrom( byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry) diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java index 0d9f87ba01..fd4c142b33 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java @@ -30,8 +30,9 @@ package com.google.protobuf; -import com.google.protobuf.Internal.BooleanList; +import static com.google.protobuf.Internal.checkNotNull; +import com.google.protobuf.Internal.BooleanList; import java.util.Arrays; import java.util.Collection; import java.util.RandomAccess; @@ -41,9 +42,8 @@ import java.util.RandomAccess; * * @author dweis@google.com (Daniel Weis) */ -final class BooleanArrayList - extends AbstractProtobufList - implements BooleanList, RandomAccess { +final class BooleanArrayList extends AbstractProtobufList + implements BooleanList, RandomAccess, PrimitiveNonBoxingCollection { private static final BooleanArrayList EMPTY_LIST = new BooleanArrayList(); static { @@ -198,9 +198,7 @@ final class BooleanArrayList public boolean addAll(Collection collection) { ensureIsMutable(); - if (collection == null) { - throw new NullPointerException(); - } + checkNotNull(collection); // We specialize when adding another BooleanArrayList to avoid boxing elements. if (!(collection instanceof BooleanArrayList)) { diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/CodedInputStream.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/CodedInputStream.java index 239798e440..3dfbcb0ae4 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/CodedInputStream.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/CodedInputStream.java @@ -355,8 +355,8 @@ public abstract class CodedInputStream { *

Set the maximum message size. In order to prevent malicious messages from exhausting memory * or causing integer overflows, {@code CodedInputStream} limits how large a message may be. The * default limit is {@code Integer.MAX_INT}. You should set this limit as small as you can without - * harming your app's functionality. Note that size limits only apply when reading from an - * {@code InputStream}, not when constructed around a raw byte array. + * harming your app's functionality. Note that size limits only apply when reading from an {@code + * InputStream}, not when constructed around a raw byte array. * *

If you want to read several messages from a single CodedInputStream, you could call {@link * #resetSizeCounter()} after each one to avoid hitting the size limit. diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java index 3e32c2c536..da0e9b12c3 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java @@ -184,7 +184,7 @@ public abstract class CodedOutputStream extends ByteOutput { * maps are sorted on the lexicographical order of the UTF8 encoded keys. * */ - void useDeterministicSerialization() { + public void useDeterministicSerialization() { serializationDeterministic = true; } @@ -1854,7 +1854,7 @@ public abstract class CodedOutputStream extends ByteOutput { } static boolean isSupported() { - return UnsafeUtil.hasUnsafeByteBufferOperations(); + return UnsafeUtil.hasUnsafeByteBufferOperations() && UnsafeUtil.hasUnsafeCopyMemory(); } @Override diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/Descriptors.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/Descriptors.java index 38346f1559..75b16fe30e 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/Descriptors.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/Descriptors.java @@ -30,9 +30,10 @@ package com.google.protobuf; +import static com.google.protobuf.Internal.checkNotNull; + import com.google.protobuf.DescriptorProtos.*; import com.google.protobuf.Descriptors.FileDescriptor.Syntax; - import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Arrays; @@ -682,9 +683,7 @@ public final class Descriptors { /** Determines if the given field name is reserved. */ public boolean isReservedName(final String name) { - if (name == null) { - throw new NullPointerException(); - } + checkNotNull(name); for (final String reservedName : proto.getReservedNameList()) { if (reservedName.equals(name)) { return true; diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java index 6177f3cab9..867b85ce86 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java @@ -30,8 +30,9 @@ package com.google.protobuf; -import com.google.protobuf.Internal.DoubleList; +import static com.google.protobuf.Internal.checkNotNull; +import com.google.protobuf.Internal.DoubleList; import java.util.Arrays; import java.util.Collection; import java.util.RandomAccess; @@ -41,9 +42,8 @@ import java.util.RandomAccess; * * @author dweis@google.com (Daniel Weis) */ -final class DoubleArrayList - extends AbstractProtobufList - implements DoubleList, RandomAccess { +final class DoubleArrayList extends AbstractProtobufList + implements DoubleList, RandomAccess, PrimitiveNonBoxingCollection { private static final DoubleArrayList EMPTY_LIST = new DoubleArrayList(); static { @@ -199,9 +199,7 @@ final class DoubleArrayList public boolean addAll(Collection collection) { ensureIsMutable(); - if (collection == null) { - throw new NullPointerException(); - } + checkNotNull(collection); // We specialize when adding another DoubleArrayList to avoid boxing elements. if (!(collection instanceof DoubleArrayList)) { diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/DynamicMessage.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/DynamicMessage.java index e6358c3bae..2631db7475 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/DynamicMessage.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/DynamicMessage.java @@ -30,11 +30,12 @@ package com.google.protobuf; +import static com.google.protobuf.Internal.checkNotNull; + import com.google.protobuf.Descriptors.Descriptor; import com.google.protobuf.Descriptors.EnumValueDescriptor; import com.google.protobuf.Descriptors.FieldDescriptor; import com.google.protobuf.Descriptors.OneofDescriptor; - import java.io.IOException; import java.io.InputStream; import java.util.Collections; @@ -631,9 +632,7 @@ public final class DynamicMessage extends AbstractMessage { /** Verifies that the value is EnumValueDescriptor and matches Enum Type. */ private void ensureSingularEnumValueDescriptor( FieldDescriptor field, Object value) { - if (value == null) { - throw new NullPointerException(); - } + checkNotNull(value); if (!(value instanceof EnumValueDescriptor)) { throw new IllegalArgumentException( "DynamicMessage should use EnumValueDescriptor to set Enum Value."); diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/FieldSet.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/FieldSet.java index a828f30edb..8a9239edef 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/FieldSet.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/FieldSet.java @@ -30,8 +30,9 @@ package com.google.protobuf; -import com.google.protobuf.LazyField.LazyIterator; +import static com.google.protobuf.Internal.checkNotNull; +import com.google.protobuf.LazyField.LazyIterator; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; @@ -385,9 +386,7 @@ final class FieldSet - implements FloatList, RandomAccess { +final class FloatArrayList extends AbstractProtobufList + implements FloatList, RandomAccess, PrimitiveNonBoxingCollection { private static final FloatArrayList EMPTY_LIST = new FloatArrayList(); static { @@ -198,9 +198,7 @@ final class FloatArrayList public boolean addAll(Collection collection) { ensureIsMutable(); - if (collection == null) { - throw new NullPointerException(); - } + checkNotNull(collection); // We specialize when adding another FloatArrayList to avoid boxing elements. if (!(collection instanceof FloatArrayList)) { diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java index 2d7fd33413..cf3486e1d9 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java @@ -34,6 +34,7 @@ import com.google.protobuf.AbstractMessageLite.Builder.LimitedInputStream; import com.google.protobuf.GeneratedMessageLite.EqualsVisitor.NotEqualsException; import com.google.protobuf.Internal.BooleanList; import com.google.protobuf.Internal.DoubleList; +import com.google.protobuf.Internal.EnumLiteMap; import com.google.protobuf.Internal.FloatList; import com.google.protobuf.Internal.IntList; import com.google.protobuf.Internal.LongList; @@ -45,6 +46,7 @@ import java.io.ObjectStreamException; import java.io.Serializable; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -136,6 +138,7 @@ public abstract class GeneratedMessageLite< return false; } + try { visit(EqualsVisitor.INSTANCE, (MessageType) other); } catch (NotEqualsException e) { @@ -1154,6 +1157,7 @@ public abstract class GeneratedMessageLite< } } + /** * Lite equivalent to {@link GeneratedMessage.GeneratedExtension}. * @@ -1527,6 +1531,20 @@ public abstract class GeneratedMessageLite< return message; } + // Validates last tag. + protected static > T parseFrom( + T defaultInstance, ByteBuffer data, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return checkMessageInitialized( + parseFrom(defaultInstance, CodedInputStream.newInstance(data), extensionRegistry)); + } + + // Validates last tag. + protected static > T parseFrom( + T defaultInstance, ByteBuffer data) throws InvalidProtocolBufferException { + return parseFrom(defaultInstance, data, ExtensionRegistryLite.getEmptyRegistry()); + } + // Validates last tag. protected static > T parseFrom( T defaultInstance, ByteString data) @@ -1979,13 +1997,13 @@ public abstract class GeneratedMessageLite< /** * Implements hashCode by accumulating state. */ - private static class HashCodeVisitor implements Visitor { + static class HashCodeVisitor implements Visitor { // The caller must ensure that the visitor is invoked parameterized with this and this such that // other is this. This is required due to how oneof cases are handled. See the class comment // on Visitor for more information. - private int hashCode = 0; + int hashCode = 0; @Override public boolean visitBoolean( diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java index fd051e751d..b949cd1772 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java @@ -41,7 +41,7 @@ import com.google.protobuf.Descriptors.OneofDescriptor; // class without breaking binary compatibility with old generated code that still subclasses // the old GeneratedMessageV3 class. To allow these different GeneratedMessageV3V? classes to // interoperate (e.g., a GeneratedMessageV3V3 object has a message extension field whose class -// type is GeneratedMessageV3V4), these classes still share a common parent class AbstarctMessage +// type is GeneratedMessageV3V4), these classes still share a common parent class AbstractMessage // and are using the same GeneratedMessage.GeneratedExtension class for extension definitions. // Since this class becomes GeneratedMessageV3V? in opensource, we have to add an import here // to be able to use GeneratedMessage.GeneratedExtension. The GeneratedExtension definition in diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/IntArrayList.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/IntArrayList.java index 2f526e3fd8..aff5c21b26 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/IntArrayList.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/IntArrayList.java @@ -30,8 +30,9 @@ package com.google.protobuf; -import com.google.protobuf.Internal.IntList; +import static com.google.protobuf.Internal.checkNotNull; +import com.google.protobuf.Internal.IntList; import java.util.Arrays; import java.util.Collection; import java.util.RandomAccess; @@ -41,9 +42,8 @@ import java.util.RandomAccess; * * @author dweis@google.com (Daniel Weis) */ -final class IntArrayList - extends AbstractProtobufList - implements IntList, RandomAccess { +final class IntArrayList extends AbstractProtobufList + implements IntList, RandomAccess, PrimitiveNonBoxingCollection { private static final IntArrayList EMPTY_LIST = new IntArrayList(); static { @@ -198,9 +198,7 @@ final class IntArrayList public boolean addAll(Collection collection) { ensureIsMutable(); - if (collection == null) { - throw new NullPointerException(); - } + checkNotNull(collection); // We specialize when adding another IntArrayList to avoid boxing elements. if (!(collection instanceof IntArrayList)) { diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/Internal.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/Internal.java index c234559ce3..36bdece306 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/Internal.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/Internal.java @@ -59,6 +59,16 @@ public final class Internal { static final Charset UTF_8 = Charset.forName("UTF-8"); static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1"); + /** + * Throws an appropriate {@link NullPointerException} if the given objects is {@code null}. + */ + static T checkNotNull(T obj) { + if (obj == null) { + throw new NullPointerException(); + } + return obj; + } + /** * Throws an appropriate {@link NullPointerException} if the given objects is {@code null}. */ @@ -420,6 +430,11 @@ public final class Internal { CodedInputStream.newInstance(EMPTY_BYTE_ARRAY); + /** Helper method to merge two MessageLite instances. */ + static Object mergeMessage(Object destination, Object source) { + return ((MessageLite) destination).toBuilder().mergeFrom((MessageLite) source).buildPartial(); + } + /** * Provides an immutable view of {@code List} around a {@code List}. * diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/LazyFieldLite.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/LazyFieldLite.java index 4b0ba0fd6b..49ecfc0be6 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/LazyFieldLite.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/LazyFieldLite.java @@ -394,6 +394,7 @@ public class LazyFieldLite { } } + /** * Might lazily parse the bytes that were previously passed in. Is thread-safe. */ diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/LongArrayList.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/LongArrayList.java index 5a772e3aa8..fc146e232b 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/LongArrayList.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/LongArrayList.java @@ -30,8 +30,9 @@ package com.google.protobuf; -import com.google.protobuf.Internal.LongList; +import static com.google.protobuf.Internal.checkNotNull; +import com.google.protobuf.Internal.LongList; import java.util.Arrays; import java.util.Collection; import java.util.RandomAccess; @@ -41,9 +42,8 @@ import java.util.RandomAccess; * * @author dweis@google.com (Daniel Weis) */ -final class LongArrayList - extends AbstractProtobufList - implements LongList, RandomAccess { +final class LongArrayList extends AbstractProtobufList + implements LongList, RandomAccess, PrimitiveNonBoxingCollection { private static final LongArrayList EMPTY_LIST = new LongArrayList(); static { @@ -198,9 +198,7 @@ final class LongArrayList public boolean addAll(Collection collection) { ensureIsMutable(); - if (collection == null) { - throw new NullPointerException(); - } + checkNotNull(collection); // We specialize when adding another LongArrayList to avoid boxing elements. if (!(collection instanceof LongArrayList)) { diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/MapEntry.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/MapEntry.java index 7e8e9aad54..0849b821cf 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/MapEntry.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/MapEntry.java @@ -33,7 +33,6 @@ package com.google.protobuf; import com.google.protobuf.Descriptors.Descriptor; import com.google.protobuf.Descriptors.EnumValueDescriptor; import com.google.protobuf.Descriptors.FieldDescriptor; - import java.io.IOException; import java.util.Collections; import java.util.Map; @@ -171,7 +170,7 @@ public final class MapEntry extends AbstractMessage { @Override public Builder toBuilder() { - return new Builder(metadata, key, value); + return new Builder(metadata, key, value, true, true); } @Override @@ -247,15 +246,19 @@ public final class MapEntry extends AbstractMessage { private final Metadata metadata; private K key; private V value; + private boolean hasKey; + private boolean hasValue; private Builder(Metadata metadata) { - this(metadata, metadata.defaultKey, metadata.defaultValue); + this(metadata, metadata.defaultKey, metadata.defaultValue, false, false); } - private Builder(Metadata metadata, K key, V value) { + private Builder(Metadata metadata, K key, V value, boolean hasKey, boolean hasValue) { this.metadata = metadata; this.key = key; this.value = value; + this.hasKey = hasKey; + this.hasValue = hasValue; } public K getKey() { @@ -268,21 +271,25 @@ public final class MapEntry extends AbstractMessage { public Builder setKey(K key) { this.key = key; + this.hasKey = true; return this; } public Builder clearKey() { this.key = metadata.defaultKey; + this.hasKey = false; return this; } public Builder setValue(V value) { this.value = value; + this.hasValue = true; return this; } public Builder clearValue() { this.value = metadata.defaultValue; + this.hasValue = false; return this; } @@ -404,7 +411,7 @@ public final class MapEntry extends AbstractMessage { @Override public boolean hasField(FieldDescriptor field) { checkFieldDescriptor(field); - return true; + return field.getNumber() == 1 ? hasKey : hasValue; } @Override @@ -438,7 +445,7 @@ public final class MapEntry extends AbstractMessage { @Override @SuppressWarnings("unchecked") public Builder clone() { - return new Builder(metadata, key, value); + return new Builder(metadata, key, value, hasKey, hasValue); } } @@ -448,4 +455,9 @@ public final class MapEntry extends AbstractMessage { } return true; } + + /** Returns the metadata only for experimental runtime. */ + final Metadata getMetadata() { + return metadata; + } } diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/MapEntryLite.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/MapEntryLite.java index 22aef8f93d..dcb5dfad3d 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/MapEntryLite.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/MapEntryLite.java @@ -223,4 +223,9 @@ public class MapEntryLite { input.popLimit(oldLimit); map.put(key, value); } + + /** For experimental runtime internal use only. */ + Metadata getMetadata() { + return metadata; + } } diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/MapField.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/MapField.java index 805defe29f..ad8ceb02a9 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/MapField.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/MapField.java @@ -30,6 +30,8 @@ package com.google.protobuf; +import static com.google.protobuf.Internal.checkNotNull; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -329,6 +331,8 @@ public class MapField implements MutabilityOracle { @Override public V put(K key, V value) { mutabilityOracle.ensureMutable(); + checkNotNull(key); + checkNotNull(value); return delegate.put(key, value); } @@ -341,6 +345,10 @@ public class MapField implements MutabilityOracle { @Override public void putAll(Map m) { mutabilityOracle.ensureMutable(); + for (K key : m.keySet()) { + checkNotNull(key); + checkNotNull(m.get(key)); + } delegate.putAll(m); } diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/MapFieldLite.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/MapFieldLite.java index 4264027911..a8b3dd8849 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/MapFieldLite.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/MapFieldLite.java @@ -30,8 +30,9 @@ package com.google.protobuf; -import com.google.protobuf.Internal.EnumLite; +import static com.google.protobuf.Internal.checkNotNull; +import com.google.protobuf.Internal.EnumLite; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; @@ -88,6 +89,9 @@ public final class MapFieldLite extends LinkedHashMap { @Override public V put(K key, V value) { ensureMutable(); + checkNotNull(key); + + checkNotNull(value); return super.put(key, value); } @@ -97,6 +101,7 @@ public final class MapFieldLite extends LinkedHashMap { @Override public void putAll(Map m) { ensureMutable(); + checkForNullKeysAndValues(m); super.putAll(m); } @@ -105,6 +110,13 @@ public final class MapFieldLite extends LinkedHashMap { return super.remove(key); } + private static void checkForNullKeysAndValues(Map m) { + for (Object key : m.keySet()) { + checkNotNull(key); + checkNotNull(m.get(key)); + } + } + private static boolean equals(Object a, Object b) { if (a instanceof byte[] && b instanceof byte[]) { return Arrays.equals((byte[]) a, (byte[]) b); diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/Parser.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/Parser.java index cfbcb44257..e07c68959a 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/Parser.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/Parser.java @@ -31,6 +31,7 @@ package com.google.protobuf; import java.io.InputStream; +import java.nio.ByteBuffer; /** * Abstract interface for parsing Protocol Messages. @@ -92,6 +93,18 @@ public interface Parser { // --------------------------------------------------------------- // Convenience methods. + /** + * Parses {@code data} as a message of {@code MessageType}. This is just a small wrapper around + * {@link #parseFrom(CodedInputStream)}. + */ + public MessageType parseFrom(ByteBuffer data) throws InvalidProtocolBufferException; + + /** + * Parses {@code data} as a message of {@code MessageType}. This is just a small wrapper around + * {@link #parseFrom(CodedInputStream, ExtensionRegistryLite)}. + */ + public MessageType parseFrom(ByteBuffer data, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException; /** * Parses {@code data} as a message of {@code MessageType}. * This is just a small wrapper around {@link #parseFrom(CodedInputStream)}. diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/PrimitiveNonBoxingCollection.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/PrimitiveNonBoxingCollection.java new file mode 100644 index 0000000000..79b5769d19 --- /dev/null +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/PrimitiveNonBoxingCollection.java @@ -0,0 +1,34 @@ +// 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. + +package com.google.protobuf; + +/** A marker interface indicating that the collection supports primitives and is non-boxing. */ +interface PrimitiveNonBoxingCollection {} diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java index 77b61b5f3c..30c991d40b 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java @@ -30,6 +30,8 @@ package com.google.protobuf; +import static com.google.protobuf.Internal.checkNotNull; + import java.util.AbstractList; import java.util.ArrayList; import java.util.Collection; @@ -290,9 +292,7 @@ public class RepeatedFieldBuilderV3 */ public RepeatedFieldBuilderV3 setMessage( int index, MType message) { - if (message == null) { - throw new NullPointerException(); - } + checkNotNull(message); ensureMutableMessageList(); messages.set(index, message); if (builders != null) { @@ -315,9 +315,7 @@ public class RepeatedFieldBuilderV3 */ public RepeatedFieldBuilderV3 addMessage( MType message) { - if (message == null) { - throw new NullPointerException(); - } + checkNotNull(message); ensureMutableMessageList(); messages.add(message); if (builders != null) { @@ -339,9 +337,7 @@ public class RepeatedFieldBuilderV3 */ public RepeatedFieldBuilderV3 addMessage( int index, MType message) { - if (message == null) { - throw new NullPointerException(); - } + checkNotNull(message); ensureMutableMessageList(); messages.add(index, message); if (builders != null) { @@ -363,9 +359,7 @@ public class RepeatedFieldBuilderV3 public RepeatedFieldBuilderV3 addAllMessages( Iterable values) { for (final MType value : values) { - if (value == null) { - throw new NullPointerException(); - } + checkNotNull(value); } // If we can inspect the size, we can more efficiently add messages. diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java index fb1f76a731..8ab0f26d90 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java @@ -30,6 +30,8 @@ package com.google.protobuf; +import static com.google.protobuf.Internal.checkNotNull; + /** * {@code SingleFieldBuilderV3} implements a structure that a protocol * message uses to hold a single field of another protocol message. It supports @@ -84,10 +86,7 @@ public class SingleFieldBuilderV3 MType message, AbstractMessage.BuilderParent parent, boolean isClean) { - if (message == null) { - throw new NullPointerException(); - } - this.message = message; + this.message = checkNotNull(message); this.parent = parent; this.isClean = isClean; } @@ -169,10 +168,7 @@ public class SingleFieldBuilderV3 */ public SingleFieldBuilderV3 setMessage( MType message) { - if (message == null) { - throw new NullPointerException(); - } - this.message = message; + this.message = checkNotNull(message); if (builder != null) { builder.dispose(); builder = null; diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/TextFormat.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/TextFormat.java index 4970824215..53dead801a 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/TextFormat.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/TextFormat.java @@ -1442,7 +1442,7 @@ public final class TextFormat { /** * Parse a single field from {@code tokenizer} and merge it into - * {@code builder}. + * {@code target}. */ private void mergeField(final Tokenizer tokenizer, final ExtensionRegistry extensionRegistry, @@ -1712,6 +1712,8 @@ public final class TextFormat { } if (field.isRepeated()) { + // TODO(b/29122459): If field.isMapField() and FORBID_SINGULAR_OVERWRITES mode, + // check for duplicate map keys here. target.addRepeatedField(field, value); } else if ((singularOverwritePolicy == SingularOverwritePolicy.FORBID_SINGULAR_OVERWRITES) diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java index 2bef27e923..d938113554 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java @@ -91,7 +91,7 @@ public final class UnknownFieldSet implements MessageLite { * Construct an {@code UnknownFieldSet} around the given map. The map is * expected to be immutable. */ - private UnknownFieldSet(final Map fields, + UnknownFieldSet(final Map fields, final Map fieldsDescending) { this.fields = fields; } @@ -715,7 +715,7 @@ public final class UnknownFieldSet implements MessageLite { * @see UnknownFieldSet */ public static final class Field { - private Field() {} + Field() {} /** Construct a new {@link Builder}. */ public static Builder newBuilder() { diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/UnsafeUtil.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/UnsafeUtil.java index 5f7bafd602..ca80d9464a 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/UnsafeUtil.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/UnsafeUtil.java @@ -33,19 +33,23 @@ package com.google.protobuf; import java.lang.reflect.Field; import java.nio.Buffer; import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.security.AccessController; import java.security.PrivilegedExceptionAction; -import sun.misc.Unsafe; +import java.util.logging.Level; +import java.util.logging.Logger; /** Utility class for working with unsafe operations. */ -// TODO(nathanmittler): Add support for Android Memory/MemoryBlock final class UnsafeUtil { + private static final Logger logger = Logger.getLogger(UnsafeUtil.class.getName()); private static final sun.misc.Unsafe UNSAFE = getUnsafe(); + private static final MemoryAccessor MEMORY_ACCESSOR = getMemoryAccessor(); private static final boolean HAS_UNSAFE_BYTEBUFFER_OPERATIONS = supportsUnsafeByteBufferOperations(); private static final boolean HAS_UNSAFE_ARRAY_OPERATIONS = supportsUnsafeArrayOperations(); + private static final boolean HAS_UNSAFE_COPY_MEMORY = supportsUnsafeCopyMemory(); private static final long ARRAY_BASE_OFFSET = byteArrayBaseOffset(); - private static final long BUFFER_ADDRESS_OFFSET = fieldOffset(field(Buffer.class, "address")); + private static final long BUFFER_ADDRESS_OFFSET = fieldOffset(bufferAddressField()); private UnsafeUtil() {} @@ -53,20 +57,16 @@ final class UnsafeUtil { return HAS_UNSAFE_ARRAY_OPERATIONS; } - static boolean hasUnsafeByteBufferOperations() { - return HAS_UNSAFE_BYTEBUFFER_OPERATIONS; + static boolean hasUnsafeCopyMemory() { + return HAS_UNSAFE_COPY_MEMORY; } - static Object allocateInstance(Class clazz) { - try { - return UNSAFE.allocateInstance(clazz); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } + static boolean hasUnsafeByteBufferOperations() { + return HAS_UNSAFE_BYTEBUFFER_OPERATIONS; } static long objectFieldOffset(Field field) { - return UNSAFE.objectFieldOffset(field); + return MEMORY_ACCESSOR.objectFieldOffset(field); } static long getArrayBaseOffset() { @@ -74,103 +74,103 @@ final class UnsafeUtil { } static byte getByte(Object target, long offset) { - return UNSAFE.getByte(target, offset); + return MEMORY_ACCESSOR.getByte(target, offset); } static void putByte(Object target, long offset, byte value) { - UNSAFE.putByte(target, offset, value); + MEMORY_ACCESSOR.putByte(target, offset, value); } static int getInt(Object target, long offset) { - return UNSAFE.getInt(target, offset); + return MEMORY_ACCESSOR.getInt(target, offset); } static void putInt(Object target, long offset, int value) { - UNSAFE.putInt(target, offset, value); + MEMORY_ACCESSOR.putInt(target, offset, value); } static long getLong(Object target, long offset) { - return UNSAFE.getLong(target, offset); + return MEMORY_ACCESSOR.getLong(target, offset); } static void putLong(Object target, long offset, long value) { - UNSAFE.putLong(target, offset, value); + MEMORY_ACCESSOR.putLong(target, offset, value); } static boolean getBoolean(Object target, long offset) { - return UNSAFE.getBoolean(target, offset); + return MEMORY_ACCESSOR.getBoolean(target, offset); } static void putBoolean(Object target, long offset, boolean value) { - UNSAFE.putBoolean(target, offset, value); + MEMORY_ACCESSOR.putBoolean(target, offset, value); } static float getFloat(Object target, long offset) { - return UNSAFE.getFloat(target, offset); + return MEMORY_ACCESSOR.getFloat(target, offset); } static void putFloat(Object target, long offset, float value) { - UNSAFE.putFloat(target, offset, value); + MEMORY_ACCESSOR.putFloat(target, offset, value); } static double getDouble(Object target, long offset) { - return UNSAFE.getDouble(target, offset); + return MEMORY_ACCESSOR.getDouble(target, offset); } static void putDouble(Object target, long offset, double value) { - UNSAFE.putDouble(target, offset, value); + MEMORY_ACCESSOR.putDouble(target, offset, value); } static Object getObject(Object target, long offset) { - return UNSAFE.getObject(target, offset); + return MEMORY_ACCESSOR.getObject(target, offset); } static void putObject(Object target, long offset, Object value) { - UNSAFE.putObject(target, offset, value); + MEMORY_ACCESSOR.putObject(target, offset, value); } static void copyMemory( Object src, long srcOffset, Object target, long targetOffset, long length) { - UNSAFE.copyMemory(src, srcOffset, target, targetOffset, length); + MEMORY_ACCESSOR.copyMemory(src, srcOffset, target, targetOffset, length); } static byte getByte(long address) { - return UNSAFE.getByte(address); + return MEMORY_ACCESSOR.getByte(address); } static void putByte(long address, byte value) { - UNSAFE.putByte(address, value); + MEMORY_ACCESSOR.putByte(address, value); } static int getInt(long address) { - return UNSAFE.getInt(address); + return MEMORY_ACCESSOR.getInt(address); } static void putInt(long address, int value) { - UNSAFE.putInt(address, value); + MEMORY_ACCESSOR.putInt(address, value); } static long getLong(long address) { - return UNSAFE.getLong(address); + return MEMORY_ACCESSOR.getLong(address); } static void putLong(long address, long value) { - UNSAFE.putLong(address, value); + MEMORY_ACCESSOR.putLong(address, value); } static void copyMemory(long srcAddress, long targetAddress, long length) { - UNSAFE.copyMemory(srcAddress, targetAddress, length); - } - - static void setMemory(long address, long numBytes, byte value) { - UNSAFE.setMemory(address, numBytes, value); + MEMORY_ACCESSOR.copyMemory(srcAddress, targetAddress, length); } /** * Gets the offset of the {@code address} field of the given direct {@link ByteBuffer}. */ static long addressOffset(ByteBuffer buffer) { - return UNSAFE.getLong(buffer, BUFFER_ADDRESS_OFFSET); + return MEMORY_ACCESSOR.getLong(buffer, BUFFER_ADDRESS_OFFSET); + } + + static Object getStaticObject(Field field) { + return MEMORY_ACCESSOR.getStaticObject(field); } /** @@ -181,7 +181,7 @@ final class UnsafeUtil { try { unsafe = AccessController.doPrivileged( - new PrivilegedExceptionAction() { + new PrivilegedExceptionAction() { @Override public sun.misc.Unsafe run() throws Exception { Class k = sun.misc.Unsafe.class; @@ -204,69 +204,114 @@ final class UnsafeUtil { return unsafe; } + /** Get a {@link MemoryAccessor} appropriate for the platform, or null if not supported. */ + private static MemoryAccessor getMemoryAccessor() { + if (UNSAFE == null) { + return null; + } + return new JvmMemoryAccessor(UNSAFE); + } + /** Indicates whether or not unsafe array operations are supported on this platform. */ private static boolean supportsUnsafeArrayOperations() { - boolean supported = false; - if (UNSAFE != null) { - try { - Class clazz = UNSAFE.getClass(); - clazz.getMethod("objectFieldOffset", Field.class); - clazz.getMethod("allocateInstance", Class.class); - clazz.getMethod("arrayBaseOffset", Class.class); - clazz.getMethod("getByte", Object.class, long.class); - clazz.getMethod("putByte", Object.class, long.class, byte.class); - clazz.getMethod("getBoolean", Object.class, long.class); - clazz.getMethod("putBoolean", Object.class, long.class, boolean.class); - clazz.getMethod("getInt", Object.class, long.class); - clazz.getMethod("putInt", Object.class, long.class, int.class); - clazz.getMethod("getLong", Object.class, long.class); - clazz.getMethod("putLong", Object.class, long.class, long.class); - clazz.getMethod("getFloat", Object.class, long.class); - clazz.getMethod("putFloat", Object.class, long.class, float.class); - clazz.getMethod("getDouble", Object.class, long.class); - clazz.getMethod("putDouble", Object.class, long.class, double.class); - clazz.getMethod("getObject", Object.class, long.class); - clazz.getMethod("putObject", Object.class, long.class, Object.class); - clazz.getMethod( - "copyMemory", Object.class, long.class, Object.class, long.class, long.class); - supported = true; - } catch (Throwable e) { - // Do nothing. - } - } - return supported; + if (UNSAFE == null) { + return false; + } + try { + Class clazz = UNSAFE.getClass(); + clazz.getMethod("objectFieldOffset", Field.class); + clazz.getMethod("arrayBaseOffset", Class.class); + clazz.getMethod("getInt", Object.class, long.class); + clazz.getMethod("putInt", Object.class, long.class, int.class); + clazz.getMethod("getLong", Object.class, long.class); + clazz.getMethod("putLong", Object.class, long.class, long.class); + clazz.getMethod("getObject", Object.class, long.class); + clazz.getMethod("putObject", Object.class, long.class, Object.class); + clazz.getMethod("getByte", Object.class, long.class); + clazz.getMethod("putByte", Object.class, long.class, byte.class); + clazz.getMethod("getBoolean", Object.class, long.class); + clazz.getMethod("putBoolean", Object.class, long.class, boolean.class); + clazz.getMethod("getFloat", Object.class, long.class); + clazz.getMethod("putFloat", Object.class, long.class, float.class); + clazz.getMethod("getDouble", Object.class, long.class); + clazz.getMethod("putDouble", Object.class, long.class, double.class); + + return true; + } catch (Throwable e) { + logger.log( + Level.WARNING, + "platform method missing - proto runtime falling back to safer methods: " + e); + } + return false; + } + + /** + * Indicates whether or not unsafe copyMemory(object, long, object, long, long) operations are + * supported on this platform. + */ + private static boolean supportsUnsafeCopyMemory() { + if (UNSAFE == null) { + return false; + } + try { + Class clazz = UNSAFE.getClass(); + clazz.getMethod("copyMemory", Object.class, long.class, Object.class, long.class, long.class); + + return true; + } catch (Throwable e) { + logger.log( + Level.WARNING, + "copyMemory is missing from platform - proto runtime falling back to safer methods."); + } + return false; } private static boolean supportsUnsafeByteBufferOperations() { - boolean supported = false; - if (UNSAFE != null) { - try { - Class clazz = UNSAFE.getClass(); - // Methods for getting direct buffer address. - clazz.getMethod("objectFieldOffset", Field.class); - clazz.getMethod("getLong", Object.class, long.class); - - clazz.getMethod("getByte", long.class); - clazz.getMethod("putByte", long.class, byte.class); - clazz.getMethod("getInt", long.class); - clazz.getMethod("putInt", long.class, int.class); - clazz.getMethod("getLong", long.class); - clazz.getMethod("putLong", long.class, long.class); - clazz.getMethod("setMemory", long.class, long.class, byte.class); - clazz.getMethod("copyMemory", long.class, long.class, long.class); - supported = true; - } catch (Throwable e) { - // Do nothing. - } - } - return supported; + if (UNSAFE == null) { + return false; + } + try { + Class clazz = UNSAFE.getClass(); + // Methods for getting direct buffer address. + clazz.getMethod("objectFieldOffset", Field.class); + clazz.getMethod("getLong", Object.class, long.class); + + clazz.getMethod("getByte", long.class); + clazz.getMethod("putByte", long.class, byte.class); + clazz.getMethod("getInt", long.class); + clazz.getMethod("putInt", long.class, int.class); + clazz.getMethod("getLong", long.class); + clazz.getMethod("putLong", long.class, long.class); + clazz.getMethod("copyMemory", long.class, long.class, long.class); + return true; + } catch (Throwable e) { + logger.log( + Level.WARNING, + "platform method missing - proto runtime falling back to safer methods: " + e); + } + return false; + } + + + @SuppressWarnings("unchecked") + private static Class getClassForName(String name) { + try { + return (Class) Class.forName(name); + } catch (Throwable e) { + return null; + } + } + + /** Finds the address field within a direct {@link Buffer}. */ + private static Field bufferAddressField() { + return field(Buffer.class, "address"); } /** * Get the base offset for byte arrays, or {@code -1} if {@code sun.misc.Unsafe} is not available. */ private static int byteArrayBaseOffset() { - return HAS_UNSAFE_ARRAY_OPERATIONS ? UNSAFE.arrayBaseOffset(byte[].class) : -1; + return HAS_UNSAFE_ARRAY_OPERATIONS ? MEMORY_ACCESSOR.arrayBaseOffset(byte[].class) : -1; } /** @@ -274,7 +319,7 @@ final class UnsafeUtil { * available. */ private static long fieldOffset(Field field) { - return field == null || UNSAFE == null ? -1 : UNSAFE.objectFieldOffset(field); + return field == null || MEMORY_ACCESSOR == null ? -1 : MEMORY_ACCESSOR.objectFieldOffset(field); } /** @@ -292,4 +337,174 @@ final class UnsafeUtil { } return field; } + + private abstract static class MemoryAccessor { + + sun.misc.Unsafe unsafe; + + MemoryAccessor(sun.misc.Unsafe unsafe) { + this.unsafe = unsafe; + } + + public final long objectFieldOffset(Field field) { + return unsafe.objectFieldOffset(field); + } + + public abstract byte getByte(Object target, long offset); + + public abstract void putByte(Object target, long offset, byte value); + + public final int getInt(Object target, long offset) { + return unsafe.getInt(target, offset); + } + + public final void putInt(Object target, long offset, int value) { + unsafe.putInt(target, offset, value); + } + + public final long getLong(Object target, long offset) { + return unsafe.getLong(target, offset); + } + + public final void putLong(Object target, long offset, long value) { + unsafe.putLong(target, offset, value); + } + + public abstract boolean getBoolean(Object target, long offset); + + public abstract void putBoolean(Object target, long offset, boolean value); + + public abstract float getFloat(Object target, long offset); + + public abstract void putFloat(Object target, long offset, float value); + + public abstract double getDouble(Object target, long offset); + + public abstract void putDouble(Object target, long offset, double value); + + public final Object getObject(Object target, long offset) { + return unsafe.getObject(target, offset); + } + + public final void putObject(Object target, long offset, Object value) { + unsafe.putObject(target, offset, value); + } + + public final int arrayBaseOffset(Class clazz) { + return unsafe.arrayBaseOffset(clazz); + } + + public abstract byte getByte(long address); + + public abstract void putByte(long address, byte value); + + public abstract int getInt(long address); + + public abstract void putInt(long address, int value); + + public abstract long getLong(long address); + + public abstract void putLong(long address, long value); + + public abstract void copyMemory(long srcAddress, long targetAddress, long length); + + public abstract void copyMemory( + Object src, long srcOffset, Object target, long targetOffset, long length); + + public abstract Object getStaticObject(Field field); + } + + private static final class JvmMemoryAccessor extends MemoryAccessor { + + JvmMemoryAccessor(sun.misc.Unsafe unsafe) { + super(unsafe); + } + + @Override + public byte getByte(long address) { + return unsafe.getByte(address); + } + + @Override + public void putByte(long address, byte value) { + unsafe.putByte(address, value); + } + + @Override + public int getInt(long address) { + return unsafe.getInt(address); + } + + @Override + public void putInt(long address, int value) { + unsafe.putInt(address, value); + } + + @Override + public long getLong(long address) { + return unsafe.getLong(address); + } + + @Override + public void putLong(long address, long value) { + unsafe.putLong(address, value); + } + + @Override + public byte getByte(Object target, long offset) { + return unsafe.getByte(target, offset); + } + + @Override + public void putByte(Object target, long offset, byte value) { + unsafe.putByte(target, offset, value); + } + + @Override + public boolean getBoolean(Object target, long offset) { + return unsafe.getBoolean(target, offset); + } + + @Override + public void putBoolean(Object target, long offset, boolean value) { + unsafe.putBoolean(target, offset, value); + } + + @Override + public float getFloat(Object target, long offset) { + return unsafe.getFloat(target, offset); + } + + @Override + public void putFloat(Object target, long offset, float value) { + unsafe.putFloat(target, offset, value); + } + + @Override + public double getDouble(Object target, long offset) { + return unsafe.getDouble(target, offset); + } + + @Override + public void putDouble(Object target, long offset, double value) { + unsafe.putDouble(target, offset, value); + } + + @Override + public void copyMemory( + Object src, long srcOffset, Object target, long targetOffset, long length) { + unsafe.copyMemory(src, srcOffset, target, targetOffset, length); + } + + @Override + public void copyMemory(long srcAddress, long targetAddress, long length) { + unsafe.copyMemory(srcAddress, targetAddress, length); + } + + @Override + public Object getStaticObject(Field field) { + return getObject(unsafe.staticFieldBase(field), unsafe.staticFieldOffset(field)); + } + } + } diff --git a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/Utf8.java b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/Utf8.java index 5b80d405eb..be7b746e5a 100644 --- a/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/Utf8.java +++ b/third_party/protobuf/3.2.0/java/core/src/main/java/com/google/protobuf/Utf8.java @@ -1332,7 +1332,7 @@ final class Utf8 { // the index (relative to the start of the array) is also 8-byte aligned. We do this by // ANDing the index with 7 to determine the number of bytes that need to be read before // we're 8-byte aligned. - final int unaligned = (int) offset & 7; + final int unaligned = 8 - ((int) offset & 7); for (int j = unaligned; j > 0; j--) { if (UnsafeUtil.getByte(bytes, offset++) < 0) { return unaligned - j; diff --git a/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/LazyFieldTest.java b/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/LazyFieldTest.java index 5f013f3ce3..f27e8e51b2 100644 --- a/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/LazyFieldTest.java +++ b/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/LazyFieldTest.java @@ -32,7 +32,6 @@ package com.google.protobuf; import protobuf_unittest.UnittestProto.TestAllExtensions; import protobuf_unittest.UnittestProto.TestAllTypes; -import java.io.IOException; import junit.framework.TestCase; /** @@ -89,6 +88,7 @@ public class LazyFieldTest extends TestCase { assertFalse(message.equals(lazyField.getValue())); } + @SuppressWarnings("EqualsIncompatibleType") // LazyField.equals() is not symmetric public void testEqualsObjectEx() throws Exception { TestAllExtensions message = TestUtil.getAllExtensionsSet(); LazyField lazyField = createLazyFieldFromMessage(message); diff --git a/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/LiteTest.java b/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/LiteTest.java index 538432f7c1..98c637a95a 100644 --- a/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/LiteTest.java +++ b/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/LiteTest.java @@ -52,6 +52,7 @@ import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.BarPrime; import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.Foo; import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.TestOneofEquals; import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.TestRecursiveOneof; +import java.nio.ByteBuffer; import junit.framework.TestCase; /** @@ -2174,6 +2175,24 @@ public class LiteTest extends TestCase { assertFalse(bar.equals(barPrime)); } + public void testEqualsAndHashCodeForTrickySchemaTypes() { + Foo foo1 = Foo.newBuilder() + .build(); + Foo foo2 = Foo.newBuilder() + .setSint64(1) + .build(); + Foo foo3 = Foo.newBuilder() + .putMyMap("key", "value2") + .build(); + Foo foo4 = Foo.newBuilder() + .setMyGroup(Foo.MyGroup.newBuilder().setValue(4).build()) + .build(); + + assertEqualsAndHashCodeAreFalse(foo1, foo2); + assertEqualsAndHashCodeAreFalse(foo1, foo3); + assertEqualsAndHashCodeAreFalse(foo1, foo4); + } + public void testOneofEquals() throws Exception { TestOneofEquals.Builder builder = TestOneofEquals.newBuilder(); TestOneofEquals message1 = builder.build(); @@ -2270,4 +2289,93 @@ public class LiteTest extends TestCase { // This tests that we don't infinite loop. TestRecursiveOneof.getDefaultInstance().hashCode(); } + + public void testParseFromByteBuffer() throws Exception { + TestAllTypesLite message = + TestAllTypesLite.newBuilder() + .setOptionalInt32(123) + .addRepeatedString("hello") + .setOptionalNestedMessage(TestAllTypesLite.NestedMessage.newBuilder().setBb(7)) + .build(); + + TestAllTypesLite copy = + TestAllTypesLite.parseFrom(message.toByteString().asReadOnlyByteBuffer()); + + assertEquals(message, copy); + } + + public void testParseFromByteBufferThrows() { + try { + TestAllTypesLite.parseFrom(ByteBuffer.wrap(new byte[] { 0x5 })); + fail(); + } catch (InvalidProtocolBufferException expected) { + } + + TestAllTypesLite message = + TestAllTypesLite.newBuilder() + .setOptionalInt32(123) + .addRepeatedString("hello") + .build(); + + ByteBuffer buffer = ByteBuffer.wrap(message.toByteArray(), 0, message.getSerializedSize() - 1); + try { + TestAllTypesLite.parseFrom(buffer); + fail(); + } catch (InvalidProtocolBufferException expected) { + assertEquals( + TestAllTypesLite.newBuilder() + .setOptionalInt32(123) + .build(), + expected.getUnfinishedMessage()); + } + } + + public void testParseFromByteBuffer_extensions() throws Exception { + TestAllExtensionsLite message = + TestAllExtensionsLite.newBuilder() + .setExtension(UnittestLite.optionalInt32ExtensionLite, 123) + .addExtension(UnittestLite.repeatedStringExtensionLite, "hello") + .setExtension( + UnittestLite.optionalNestedEnumExtensionLite, TestAllTypesLite.NestedEnum.BAZ) + .setExtension( + UnittestLite.optionalNestedMessageExtensionLite, + TestAllTypesLite.NestedMessage.newBuilder().setBb(7).build()) + .build(); + + ExtensionRegistryLite registry = ExtensionRegistryLite.newInstance(); + UnittestLite.registerAllExtensions(registry); + + TestAllExtensionsLite copy = + TestAllExtensionsLite.parseFrom(message.toByteString().asReadOnlyByteBuffer(), registry); + + assertEquals(message, copy); + } + + public void testParseFromByteBufferThrows_extensions() { + ExtensionRegistryLite registry = ExtensionRegistryLite.newInstance(); + UnittestLite.registerAllExtensions(registry); + try { + TestAllExtensionsLite.parseFrom(ByteBuffer.wrap(new byte[] { 0x5 }), registry); + fail(); + } catch (InvalidProtocolBufferException expected) { + } + + TestAllExtensionsLite message = + TestAllExtensionsLite.newBuilder() + .setExtension(UnittestLite.optionalInt32ExtensionLite, 123) + .addExtension(UnittestLite.repeatedStringExtensionLite, "hello") + .build(); + + ByteBuffer buffer = ByteBuffer.wrap(message.toByteArray(), 0, message.getSerializedSize() - 1); + try { + TestAllExtensionsLite.parseFrom(buffer, registry); + fail(); + } catch (InvalidProtocolBufferException expected) { + assertEquals( + TestAllExtensionsLite.newBuilder() + .setExtension(UnittestLite.optionalInt32ExtensionLite, 123) + .build(), + expected.getUnfinishedMessage()); + } + } } diff --git a/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java b/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java index cfe4c4536e..453d39286d 100644 --- a/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java +++ b/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java @@ -759,6 +759,7 @@ public class MapForProto2Test extends TestCase { assertEquals(55, message.getInt32ToInt32Field().get(55).intValue()); } + // See additional coverage in TextFormatTest.java. public void testTextFormat() throws Exception { TestMap.Builder builder = TestMap.newBuilder(); setMapValuesUsingAccessors(builder); diff --git a/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/MapTest.java b/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/MapTest.java index 81e951ccf7..45019537ec 100644 --- a/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/MapTest.java +++ b/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/MapTest.java @@ -30,7 +30,7 @@ package com.google.protobuf; - +import static org.junit.Assert.assertArrayEquals; import com.google.protobuf.Descriptors.Descriptor; import com.google.protobuf.Descriptors.EnumDescriptor; import com.google.protobuf.Descriptors.EnumValueDescriptor; @@ -490,19 +490,13 @@ public class MapTest extends TestCase { public void testPutForUnknownEnumValues() throws Exception { TestMap.Builder builder = TestMap.newBuilder() .putInt32ToEnumFieldValue(0, 0) - .putInt32ToEnumFieldValue(1, 1); - - try { - builder.putInt32ToEnumFieldValue(2, 1000); // unknown value. - fail(); - } catch (IllegalArgumentException e) { - // expected - } - + .putInt32ToEnumFieldValue(1, 1) + .putInt32ToEnumFieldValue(2, 1000); // unknown value. TestMap message = builder.build(); assertEquals(0, message.getInt32ToEnumFieldValueOrThrow(0)); assertEquals(1, message.getInt32ToEnumFieldValueOrThrow(1)); - assertEquals(2, message.getInt32ToEnumFieldCount()); + assertEquals(1000, message.getInt32ToEnumFieldValueOrThrow(2)); + assertEquals(3, message.getInt32ToEnumFieldCount()); } public void testPutChecksNullKeysAndValues() throws Exception { @@ -870,6 +864,7 @@ public class MapTest extends TestCase { assertEquals(55, message.getInt32ToInt32Field().get(55).intValue()); } + // See additional coverage in TextFormatTest.java. public void testTextFormat() throws Exception { TestMap.Builder builder = TestMap.newBuilder(); setMapValuesUsingAccessors(builder); @@ -1250,12 +1245,9 @@ public class MapTest extends TestCase { builder.putInt32ToEnumFieldValue(1, TestMap.EnumValue.BAR.getNumber()); assertEquals( TestMap.EnumValue.BAR.getNumber(), builder.getInt32ToEnumFieldValueOrThrow(1)); - try { - builder.putInt32ToEnumFieldValue(1, -1); - fail(); - } catch (IllegalArgumentException e) { - // expected - } + builder.putInt32ToEnumFieldValue(1, -1); + assertEquals(-1, builder.getInt32ToEnumFieldValueOrThrow(1)); + assertEquals(TestMap.EnumValue.UNRECOGNIZED, builder.getInt32ToEnumFieldOrThrow(1)); builder.putStringToInt32Field("a", 1); assertEquals(1, builder.getStringToInt32FieldOrThrow("a")); @@ -1492,4 +1484,41 @@ public class MapTest extends TestCase { map.put(key3, value3); return map; } + + public void testMap_withNulls() { + TestMap.Builder builder = TestMap.newBuilder(); + + try { + builder.putStringToInt32Field(null, 3); + fail(); + } catch (NullPointerException expected) { + } + + try { + builder.putAllStringToInt32Field(newMap(null, 3, "hi", 4)); + fail(); + } catch (NullPointerException expected) { + } + + try { + builder.putInt32ToMessageField(3, null); + fail(); + } catch (NullPointerException expected) { + } + + try { + builder.putAllInt32ToMessageField( + MapTest.newMap(4, null, 5, null)); + fail(); + } catch (NullPointerException expected) { + } + + try { + builder.putAllInt32ToMessageField(null); + fail(); + } catch (NullPointerException expected) { + } + + assertArrayEquals(new byte[0], builder.build().toByteArray()); + } } diff --git a/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/ParserTest.java b/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/ParserTest.java index 8c2e4c261c..4bd34112d6 100644 --- a/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/ParserTest.java +++ b/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/ParserTest.java @@ -79,6 +79,8 @@ public class ParserTest extends TestCase { new ByteArrayInputStream(data), registry)); assertMessageEquals(message, parser.parseFrom( CodedInputStream.newInstance(data), registry)); + assertMessageEquals( + message, parser.parseFrom(message.toByteString().asReadOnlyByteBuffer(), registry)); } @SuppressWarnings("unchecked") @@ -99,6 +101,7 @@ public class ParserTest extends TestCase { new ByteArrayInputStream(data))); assertMessageEquals(message, parser.parseFrom( CodedInputStream.newInstance(data))); + assertMessageEquals(message, parser.parseFrom(message.toByteString().asReadOnlyByteBuffer())); } private void assertMessageEquals( @@ -178,6 +181,9 @@ public class ParserTest extends TestCase { public void testParseExtensions() throws Exception { assertRoundTripEquals(TestUtil.getAllExtensionsSet(), TestUtil.getExtensionRegistry()); + } + + public void testParseExtensionsLite() throws Exception { assertRoundTripEquals( TestUtilLite.getAllLiteExtensionsSet(), TestUtilLite.getExtensionRegistryLite()); } @@ -186,6 +192,9 @@ public class ParserTest extends TestCase { assertRoundTripEquals(TestUtil.getPackedSet()); assertRoundTripEquals(TestUtil.getPackedExtensionsSet(), TestUtil.getExtensionRegistry()); + } + + public void testParsePackedLite() throws Exception { assertRoundTripEquals( TestUtilLite.getLitePackedExtensionsSet(), TestUtilLite.getExtensionRegistryLite()); } @@ -195,15 +204,26 @@ public class ParserTest extends TestCase { TestAllTypes normalMessage = TestUtil.getAllSet(); ByteArrayOutputStream output = new ByteArrayOutputStream(); normalMessage.writeDelimitedTo(output); + normalMessage.writeDelimitedTo(output); + InputStream input = new ByteArrayInputStream(output.toByteArray()); + assertMessageEquals(normalMessage, normalMessage.getParserForType().parseDelimitedFrom(input)); + assertMessageEquals(normalMessage, normalMessage.getParserForType().parseDelimitedFrom(input)); + } + + public void testParseDelimitedToLite() throws Exception { // Write MessageLite with packed extension fields. TestPackedExtensionsLite packedMessage = TestUtilLite.getLitePackedExtensionsSet(); + ByteArrayOutputStream output = new ByteArrayOutputStream(); + packedMessage.writeDelimitedTo(output); packedMessage.writeDelimitedTo(output); InputStream input = new ByteArrayInputStream(output.toByteArray()); assertMessageEquals( - normalMessage, - normalMessage.getParserForType().parseDelimitedFrom(input)); + packedMessage, + packedMessage + .getParserForType() + .parseDelimitedFrom(input, TestUtilLite.getExtensionRegistryLite())); assertMessageEquals( packedMessage, packedMessage @@ -314,8 +334,7 @@ public class ParserTest extends TestCase { public void testParsingMergeLite() throws Exception { // Build messages. - TestAllTypesLite.Builder builder = - TestAllTypesLite.newBuilder(); + TestAllTypesLite.Builder builder = TestAllTypesLite.newBuilder(); TestAllTypesLite msg1 = builder.setOptionalInt32(1).build(); builder.clear(); TestAllTypesLite msg2 = builder.setOptionalInt64(2).build(); diff --git a/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/TestUtil.java b/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/TestUtil.java index c1bd21db5c..e96adf0763 100644 --- a/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/TestUtil.java +++ b/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/TestUtil.java @@ -2622,6 +2622,8 @@ public final class TestUtil { break; case FOO_NOT_SET: break; + default: + // TODO(b/18683919): go/enum-switch-lsc } } diff --git a/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/TextFormatTest.java b/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/TextFormatTest.java index 6a91b02f03..249d7c5ed2 100644 --- a/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/TextFormatTest.java +++ b/third_party/protobuf/3.2.0/java/core/src/test/java/com/google/protobuf/TextFormatTest.java @@ -30,9 +30,12 @@ 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; +import map_test.MapTestProto.TestMap; import protobuf_unittest.UnittestMset.TestMessageSetExtension1; import protobuf_unittest.UnittestMset.TestMessageSetExtension2; import protobuf_unittest.UnittestProto.OneString; @@ -940,6 +943,7 @@ public class TextFormatTest extends TestCase { } + // See additional coverage in testOneofOverwriteForbidden and testMapOverwriteForbidden. public void testParseNonRepeatedFields() throws Exception { assertParseSuccessWithOverwriteForbidden( "repeated_int32: 1\n" + @@ -950,6 +954,7 @@ public class TextFormatTest extends TestCase { assertParseSuccessWithOverwriteForbidden( "repeated_nested_message { bb: 1 }\n" + "repeated_nested_message { bb: 2 }\n"); + assertParseErrorWithOverwriteForbidden( "3:17: Non-repeated field " + "\"protobuf_unittest.TestAllTypes.optional_int32\" " + @@ -988,6 +993,7 @@ public class TextFormatTest extends TestCase { assertParseSuccessWithOverwriteForbidden("repeated_int32: [ 1, 2 ]\n"); assertParseSuccessWithOverwriteForbidden("RepeatedGroup [{ a: 1 },{ a: 2 }]\n"); assertParseSuccessWithOverwriteForbidden("repeated_nested_message [{ bb: 1 }, { bb: 2 }]\n"); + // See also testMapShortForm. } public void testParseShortRepeatedFormOfEmptyRepeatedFields() throws Exception { @@ -995,6 +1001,7 @@ public class TextFormatTest extends TestCase { assertParseSuccessWithOverwriteForbidden("repeated_int32: []\n"); assertParseSuccessWithOverwriteForbidden("RepeatedGroup []\n"); assertParseSuccessWithOverwriteForbidden("repeated_nested_message []\n"); + // See also testMapShortFormEmpty. } public void testParseShortRepeatedFormWithTrailingComma() throws Exception { @@ -1010,6 +1017,7 @@ public class TextFormatTest extends TestCase { assertParseErrorWithOverwriteForbidden( "1:37: Expected \"{\".", "repeated_nested_message [{ bb: 1 }, ]\n"); + // See also testMapShortFormTrailingComma. } public void testParseShortRepeatedFormOfNonRepeatedFields() throws Exception { @@ -1057,6 +1065,90 @@ public class TextFormatTest extends TestCase { assertTrue(oneof.hasFooInt()); } + // ======================================================================= + // test map + + public void testMapTextFormat() throws Exception { + TestMap message = + TestMap.newBuilder() + .putInt32ToStringField(10, "apple") + .putInt32ToStringField(20, "banana") + .putInt32ToStringField(30, "cherry") + .build(); + String text = TextFormat.printToUnicodeString(message); + { + TestMap.Builder dest = TestMap.newBuilder(); + TextFormat.merge(text, dest); + assertThat(dest.build()).isEqualTo(message); + } + { + TestMap.Builder dest = TestMap.newBuilder(); + parserWithOverwriteForbidden.merge(text, dest); + assertThat(dest.build()).isEqualTo(message); + } + } + + public void testMapShortForm() throws Exception { + String text = + "string_to_int32_field [{ key: 'x' value: 10 }, { key: 'y' value: 20 }]\n" + + "int32_to_message_field " + + "[{ key: 1 value { value: 100 } }, { key: 2 value: { value: 200 } }]\n"; + 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); + } + + public void testMapShortFormEmpty() throws Exception { + String text = "string_to_int32_field []\n" + + "int32_to_message_field: []\n"; + 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); + } + + public void testMapShortFormTrailingComma() throws Exception { + String text = "string_to_int32_field [{ key: 'x' value: 10 }, ]\n"; + TestMap.Builder dest = TestMap.newBuilder(); + try { + parserWithOverwriteForbidden.merge(text, dest); + fail("Expected parse exception."); + } catch (TextFormat.ParseException e) { + assertThat(e).hasMessageThat().isEqualTo("1:48: Expected \"{\"."); + } + } + + public void testMapOverwrite() throws Exception { + String text = + "int32_to_int32_field { key: 1 value: 10 }\n" + + "int32_to_int32_field { key: 2 value: 20 }\n" + + "int32_to_int32_field { key: 1 value: 30 }\n"; + + { + // With default parser, last value set for the key holds. + 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); + } + + { + // With overwrite forbidden, same behavior. + // TODO(b/29122459): Expect parse exception here. + 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); + } + } + // ======================================================================= // test location information diff --git a/third_party/protobuf/3.2.0/java/core/src/test/proto/com/google/protobuf/lite_equals_and_hash.proto b/third_party/protobuf/3.2.0/java/core/src/test/proto/com/google/protobuf/lite_equals_and_hash.proto index 6eef42c578..b18b0d79f2 100644 --- a/third_party/protobuf/3.2.0/java/core/src/test/proto/com/google/protobuf/lite_equals_and_hash.proto +++ b/third_party/protobuf/3.2.0/java/core/src/test/proto/com/google/protobuf/lite_equals_and_hash.proto @@ -46,6 +46,14 @@ message TestOneofEquals { message Foo { optional int32 value = 1; repeated Bar bar = 2; + map my_map = 3; + oneof Single { + sint64 sint64 = 4; + // LINT: ALLOW_GROUPS + group MyGroup = 5 { + optional int32 value = 1; + } + } extensions 100 to max; } diff --git a/third_party/protobuf/3.2.0/java/lite/pom.xml b/third_party/protobuf/3.2.0/java/lite/pom.xml index d7b150972d..c902f8192a 100644 --- a/third_party/protobuf/3.2.0/java/lite/pom.xml +++ b/third_party/protobuf/3.2.0/java/lite/pom.xml @@ -137,6 +137,7 @@ **/MutabilityOracle.java **/NioByteString.java **/Parser.java + **/PrimitiveNonBoxingCollection.java **/ProtobufArrayList.java **/ProtocolStringList.java **/RopeByteString.java diff --git a/third_party/protobuf/3.2.0/java/pom.xml b/third_party/protobuf/3.2.0/java/pom.xml index f89e442246..81ffc48a31 100644 --- a/third_party/protobuf/3.2.0/java/pom.xml +++ b/third_party/protobuf/3.2.0/java/pom.xml @@ -11,7 +11,7 @@ com.google.protobuf protobuf-parent - 3.2.0 + 3.3.0 pom Protocol Buffers [Parent] @@ -84,7 +84,13 @@ com.google.guava guava - 18.0 + 20.0 + + + com.google.truth + truth + test + 0.32 diff --git a/third_party/protobuf/3.2.0/java/util/pom.xml b/third_party/protobuf/3.2.0/java/util/pom.xml index ac771f6ecc..c72fa65090 100644 --- a/third_party/protobuf/3.2.0/java/util/pom.xml +++ b/third_party/protobuf/3.2.0/java/util/pom.xml @@ -6,7 +6,7 @@ com.google.protobuf protobuf-parent - 3.2.0 + 3.3.0 protobuf-java-util diff --git a/third_party/protobuf/3.2.0/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java b/third_party/protobuf/3.2.0/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java index 838700f7f6..e1c2d73dd5 100644 --- a/third_party/protobuf/3.2.0/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java +++ b/third_party/protobuf/3.2.0/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java @@ -30,6 +30,7 @@ package com.google.protobuf.util; +import com.google.common.base.Preconditions; import com.google.common.io.BaseEncoding; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -102,7 +103,9 @@ public class JsonFormat { * Creates a {@link Printer} with default configurations. */ public static Printer printer() { - return new Printer(TypeRegistry.getEmptyTypeRegistry(), false, false, false); + return new Printer( + TypeRegistry.getEmptyTypeRegistry(), false, Collections.emptySet(), + false, false); } /** @@ -110,16 +113,27 @@ public class JsonFormat { */ public static class Printer { private final TypeRegistry registry; - private final boolean includingDefaultValueFields; + // NOTE: There are 3 states for these *defaultValueFields variables: + // 1) Default - alwaysOutput is false & including is empty set. Fields only output if they are + // set to non-default values. + // 2) No-args includingDefaultValueFields() called - alwaysOutput is true & including is + // irrelevant (but set to empty set). All fields are output regardless of their values. + // 3) includingDefaultValueFields(Set) called - alwaysOutput is false & + // including is set to the specified set. Fields in that set are always output & fields not + // in that set are only output if set to non-default values. + private boolean alwaysOutputDefaultValueFields; + private Set includingDefaultValueFields; private final boolean preservingProtoFieldNames; private final boolean omittingInsignificantWhitespace; private Printer( TypeRegistry registry, - boolean includingDefaultValueFields, + boolean alwaysOutputDefaultValueFields, + Set includingDefaultValueFields, boolean preservingProtoFieldNames, boolean omittingInsignificantWhitespace) { this.registry = registry; + this.alwaysOutputDefaultValueFields = alwaysOutputDefaultValueFields; this.includingDefaultValueFields = includingDefaultValueFields; this.preservingProtoFieldNames = preservingProtoFieldNames; this.omittingInsignificantWhitespace = omittingInsignificantWhitespace; @@ -137,6 +151,7 @@ public class JsonFormat { } return new Printer( registry, + alwaysOutputDefaultValueFields, includingDefaultValueFields, preservingProtoFieldNames, omittingInsignificantWhitespace); @@ -149,8 +164,41 @@ public class JsonFormat { * {@link Printer}. */ public Printer includingDefaultValueFields() { + checkUnsetIncludingDefaultValueFields(); return new Printer( - registry, true, preservingProtoFieldNames, omittingInsignificantWhitespace); + registry, + true, + Collections.emptySet(), + preservingProtoFieldNames, + omittingInsignificantWhitespace); + } + + /** + * Creates a new {@link Printer} that will also print default-valued fields if their + * FieldDescriptors are found in the supplied set. Empty repeated fields and map fields will be + * printed as well, if they match. The new Printer clones all other configurations from the + * current {@link Printer}. Call includingDefaultValueFields() with no args to unconditionally + * output all fields. + */ + public Printer includingDefaultValueFields(Set fieldsToAlwaysOutput) { + Preconditions.checkArgument( + null != fieldsToAlwaysOutput && !fieldsToAlwaysOutput.isEmpty(), + "Non-empty Set must be supplied for includingDefaultValueFields."); + + checkUnsetIncludingDefaultValueFields(); + return new Printer( + registry, + false, + fieldsToAlwaysOutput, + preservingProtoFieldNames, + omittingInsignificantWhitespace); + } + + private void checkUnsetIncludingDefaultValueFields() { + if (alwaysOutputDefaultValueFields || !includingDefaultValueFields.isEmpty()) { + throw new IllegalStateException( + "JsonFormat includingDefaultValueFields has already been set."); + } } /** @@ -161,15 +209,20 @@ public class JsonFormat { */ public Printer preservingProtoFieldNames() { return new Printer( - registry, includingDefaultValueFields, true, omittingInsignificantWhitespace); + registry, + alwaysOutputDefaultValueFields, + includingDefaultValueFields, + true, + omittingInsignificantWhitespace); } /** - * Create a new {@link Printer} that will omit all insignificant whitespace - * in the JSON output. This new Printer clones all other configurations from the - * current Printer. Insignificant whitespace is defined by the JSON spec as whitespace - * that appear between JSON structural elements: + * Create a new {@link Printer} that will omit all insignificant whitespace in the JSON output. + * This new Printer clones all other configurations from the current Printer. Insignificant + * whitespace is defined by the JSON spec as whitespace that appear between JSON structural + * elements: + * *

      * ws = *(
      * %x20 /              ; Space
@@ -177,18 +230,24 @@ public class JsonFormat {
      * %x0A /              ; Line feed or New line
      * %x0D )              ; Carriage return
      * 
+ * * See https://tools.ietf.org/html/rfc7159 * current {@link Printer}. */ public Printer omittingInsignificantWhitespace() { - return new Printer(registry, includingDefaultValueFields, preservingProtoFieldNames, true); + return new Printer( + registry, + alwaysOutputDefaultValueFields, + includingDefaultValueFields, + preservingProtoFieldNames, + true); } /** * Converts a protobuf message to JSON format. * - * @throws InvalidProtocolBufferException if the message contains Any types - * that can't be resolved. + * @throws InvalidProtocolBufferException if the message contains Any types that can't be + * resolved. * @throws IOException if writing to the output fails. */ public void appendTo(MessageOrBuilder message, Appendable output) throws IOException { @@ -196,6 +255,7 @@ public class JsonFormat { // mobile. new PrinterImpl( registry, + alwaysOutputDefaultValueFields, includingDefaultValueFields, preservingProtoFieldNames, output, @@ -428,19 +488,16 @@ public class JsonFormat { this.output = output; } - /** - * ignored by compact printer - */ + /** ignored by compact printer */ + @Override public void indent() {} - /** - * ignored by compact printer - */ + /** ignored by compact printer */ + @Override public void outdent() {} - /** - * Print text to the output stream. - */ + /** Print text to the output stream. */ + @Override public void print(final CharSequence text) throws IOException { output.append(text); } @@ -458,18 +515,17 @@ public class JsonFormat { } /** - * Indent text by two spaces. After calling Indent(), two spaces will be - * inserted at the beginning of each line of text. Indent() may be called - * multiple times to produce deeper indents. + * Indent text by two spaces. After calling Indent(), two spaces will be inserted at the + * beginning of each line of text. Indent() may be called multiple times to produce deeper + * indents. */ + @Override public void indent() { indent.append(" "); } - /** - * Reduces the current indent level by two spaces, or crashes if the indent - * level is zero. - */ + /** Reduces the current indent level by two spaces, or crashes if the indent level is zero. */ + @Override public void outdent() { final int length = indent.length(); if (length < 2) { @@ -478,9 +534,8 @@ public class JsonFormat { indent.delete(length - 2, length); } - /** - * Print text to the output stream. - */ + /** Print text to the output stream. */ + @Override public void print(final CharSequence text) throws IOException { final int size = text.length(); int pos = 0; @@ -512,7 +567,8 @@ public class JsonFormat { */ private static final class PrinterImpl { private final TypeRegistry registry; - private final boolean includingDefaultValueFields; + private final boolean alwaysOutputDefaultValueFields; + private final Set includingDefaultValueFields; private final boolean preservingProtoFieldNames; private final TextGenerator generator; // We use Gson to help handle string escapes. @@ -526,11 +582,13 @@ public class JsonFormat { PrinterImpl( TypeRegistry registry, - boolean includingDefaultValueFields, + boolean alwaysOutputDefaultValueFields, + Set includingDefaultValueFields, boolean preservingProtoFieldNames, Appendable jsonOutput, boolean omittingInsignificantWhitespace) { this.registry = registry; + this.alwaysOutputDefaultValueFields = alwaysOutputDefaultValueFields; this.includingDefaultValueFields = includingDefaultValueFields; this.preservingProtoFieldNames = preservingProtoFieldNames; this.gson = GsonHolder.DEFAULT_GSON; @@ -781,23 +839,26 @@ public class JsonFormat { printedField = true; } Map fieldsToPrint = null; - if (includingDefaultValueFields) { - fieldsToPrint = new TreeMap(); + if (alwaysOutputDefaultValueFields || !includingDefaultValueFields.isEmpty()) { + fieldsToPrint = new TreeMap(message.getAllFields()); for (FieldDescriptor field : message.getDescriptorForType().getFields()) { if (field.isOptional()) { if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE - && !message.hasField(field)){ + && !message.hasField(field)) { // Always skip empty optional message fields. If not we will recurse indefinitely if // a message has itself as a sub-field. continue; } OneofDescriptor oneof = field.getContainingOneof(); if (oneof != null && !message.hasField(field)) { - // Skip all oneof fields except the one that is actually set + // Skip all oneof fields except the one that is actually set continue; } } - fieldsToPrint.put(field, message.getField(field)); + if (!fieldsToPrint.containsKey(field) + && (alwaysOutputDefaultValueFields || includingDefaultValueFields.contains(field))) { + fieldsToPrint.put(field, message.getField(field)); + } } } else { fieldsToPrint = message.getAllFields(); @@ -1451,45 +1512,6 @@ public class JsonFormat { } } - /** - * Gets the default value for a field type. Note that we use proto3 - * language defaults and ignore any default values set through the - * proto "default" option. - */ - private Object getDefaultValue(FieldDescriptor field, Message.Builder builder) { - switch (field.getType()) { - case INT32: - case SINT32: - case SFIXED32: - case UINT32: - case FIXED32: - return 0; - case INT64: - case SINT64: - case SFIXED64: - case UINT64: - case FIXED64: - return 0L; - case FLOAT: - return 0.0f; - case DOUBLE: - return 0.0; - case BOOL: - return false; - case STRING: - return ""; - case BYTES: - return ByteString.EMPTY; - case ENUM: - return field.getEnumType().getValues().get(0); - case MESSAGE: - case GROUP: - return builder.newBuilderForField(field).getDefaultInstanceForType(); - default: - throw new IllegalStateException("Invalid field type: " + field.getType()); - } - } - private void mergeRepeatedField( FieldDescriptor field, JsonElement json, Message.Builder builder) throws InvalidProtocolBufferException { @@ -1536,7 +1558,7 @@ public class JsonFormat { BigDecimal value = new BigDecimal(json.getAsString()); return value.longValueExact(); } catch (Exception e) { - throw new InvalidProtocolBufferException("Not an int32 value: " + json); + throw new InvalidProtocolBufferException("Not an int64 value: " + json); } } diff --git a/third_party/protobuf/3.2.0/java/util/src/main/java/com/google/protobuf/util/Timestamps.java b/third_party/protobuf/3.2.0/java/util/src/main/java/com/google/protobuf/util/Timestamps.java index 1d631a2c58..d0bac417d5 100644 --- a/third_party/protobuf/3.2.0/java/util/src/main/java/com/google/protobuf/util/Timestamps.java +++ b/third_party/protobuf/3.2.0/java/util/src/main/java/com/google/protobuf/util/Timestamps.java @@ -297,7 +297,7 @@ public final class Timestamps { * Convert a Timestamp to the number of microseconds elapsed from the epoch. * *

The result will be rounded down to the nearest microsecond. E.g., if the timestamp - * represents "1969-12-31T23:59:59.999999999Z", it will be rounded to -1 millisecond. + * represents "1969-12-31T23:59:59.999999999Z", it will be rounded to -1 microsecond. */ public static long toMicros(Timestamp timestamp) { checkValid(timestamp); diff --git a/third_party/protobuf/3.2.0/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java b/third_party/protobuf/3.2.0/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java index de02c117e3..460b81f62a 100644 --- a/third_party/protobuf/3.2.0/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java +++ b/third_party/protobuf/3.2.0/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java @@ -34,6 +34,7 @@ import com.google.protobuf.Any; import com.google.protobuf.BoolValue; import com.google.protobuf.ByteString; import com.google.protobuf.BytesValue; +import com.google.protobuf.Descriptors.FieldDescriptor; import com.google.protobuf.DoubleValue; import com.google.protobuf.FloatValue; import com.google.protobuf.Int32Value; @@ -68,9 +69,12 @@ import java.io.Reader; import java.io.StringReader; import java.math.BigDecimal; import java.math.BigInteger; +import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Locale; import java.util.Map; +import java.util.Set; import junit.framework.TestCase; public class JsonFormatTest extends TestCase { @@ -229,9 +233,7 @@ public class JsonFormatTest extends TestCase { TestMap.Builder mapBuilder = TestMap.newBuilder(); mapBuilder.putInt32ToEnumMapValue(1, 0); - Map mapWithInvalidValues = new HashMap(); - mapWithInvalidValues.put(2, 12345); - mapBuilder.putAllInt32ToEnumMapValue(mapWithInvalidValues); + mapBuilder.putInt32ToEnumMapValue(2, 12345); TestMap mapMessage = mapBuilder.build(); assertEquals( "{\n" @@ -264,7 +266,7 @@ public class JsonFormatTest extends TestCase { assertRoundTripEquals(message); } - public void testParserAcceptStringForNumbericField() throws Exception { + public void testParserAcceptStringForNumericField() throws Exception { TestAllTypes.Builder builder = TestAllTypes.newBuilder(); mergeFromJson( "{\n" @@ -284,8 +286,8 @@ public class JsonFormatTest extends TestCase { assertEquals(9012, message.getOptionalSint32()); assertEquals(3456, message.getOptionalFixed32()); assertEquals(7890, message.getOptionalSfixed32()); - assertEquals(1.5f, message.getOptionalFloat()); - assertEquals(1.25, message.getOptionalDouble()); + assertEquals(1.5f, message.getOptionalFloat(), 0.0f); + assertEquals(1.25, message.getOptionalDouble(), 0.0); assertEquals(true, message.getOptionalBool()); } @@ -479,8 +481,8 @@ public class JsonFormatTest extends TestCase { TestAllTypes.Builder builder = TestAllTypes.newBuilder(); mergeFromJson( "{\n" - + " \"repeatedNestedMessage\": [null, null],\n" - + " \"repeated_nested_message\": [null, null]\n" + + " \"repeatedInt32\": [1, 2],\n" + + " \"repeated_int32\": [5, 6]\n" + "}", builder); fail(); @@ -488,7 +490,7 @@ public class JsonFormatTest extends TestCase { // Exception expected. } - // Duplicated oneof fields. + // Duplicated oneof fields, same name. try { TestOneof.Builder builder = TestOneof.newBuilder(); mergeFromJson("{\n" + " \"oneofInt32\": 1,\n" + " \"oneof_int32\": 2\n" + "}", builder); @@ -496,6 +498,16 @@ public class JsonFormatTest extends TestCase { } catch (InvalidProtocolBufferException e) { // Exception expected. } + + // Duplicated oneof fields, different name. + try { + TestOneof.Builder builder = TestOneof.newBuilder(); + mergeFromJson( + "{\n" + " \"oneofInt32\": 1,\n" + " \"oneofNullValue\": null\n" + "}", builder); + fail(); + } catch (InvalidProtocolBufferException e) { + // Exception expected. + } } public void testMapFields() throws Exception { @@ -1089,7 +1101,7 @@ public class JsonFormatTest extends TestCase { public void testParserUnexpectedTypeUrl() throws Exception { try { - TestAllTypes.Builder builder = TestAllTypes.newBuilder(); + Any.Builder builder = Any.newBuilder(); mergeFromJson( "{\n" + " \"@type\": \"type.googleapis.com/json_test.TestAllTypes\",\n" @@ -1215,6 +1227,115 @@ public class JsonFormatTest extends TestCase { + "}", JsonFormat.printer().includingDefaultValueFields().print(message)); + Set fixedFields = new HashSet(); + for (FieldDescriptor fieldDesc : TestAllTypes.getDescriptor().getFields()) { + if (fieldDesc.getName().contains("_fixed")) { + fixedFields.add(fieldDesc); + } + } + + assertEquals( + "{\n" + + " \"optionalFixed32\": 0,\n" + + " \"optionalFixed64\": \"0\",\n" + + " \"repeatedFixed32\": [],\n" + + " \"repeatedFixed64\": []\n" + + "}", + JsonFormat.printer().includingDefaultValueFields(fixedFields).print(message)); + + TestAllTypes messageNonDefaults = + message.toBuilder().setOptionalInt64(1234).setOptionalFixed32(3232).build(); + assertEquals( + "{\n" + + " \"optionalInt64\": \"1234\",\n" + + " \"optionalFixed32\": 3232,\n" + + " \"optionalFixed64\": \"0\",\n" + + " \"repeatedFixed32\": [],\n" + + " \"repeatedFixed64\": []\n" + + "}", + JsonFormat.printer().includingDefaultValueFields(fixedFields).print(messageNonDefaults)); + + try { + JsonFormat.printer().includingDefaultValueFields().includingDefaultValueFields(); + fail("IllegalStateException is expected."); + } catch (IllegalStateException e) { + // Expected. + assertTrue( + "Exception message should mention includingDefaultValueFields.", + e.getMessage().contains("includingDefaultValueFields")); + } + + try { + JsonFormat.printer().includingDefaultValueFields().includingDefaultValueFields(fixedFields); + fail("IllegalStateException is expected."); + } catch (IllegalStateException e) { + // Expected. + assertTrue( + "Exception message should mention includingDefaultValueFields.", + e.getMessage().contains("includingDefaultValueFields")); + } + + try { + JsonFormat.printer().includingDefaultValueFields(fixedFields).includingDefaultValueFields(); + fail("IllegalStateException is expected."); + } catch (IllegalStateException e) { + // Expected. + assertTrue( + "Exception message should mention includingDefaultValueFields.", + e.getMessage().contains("includingDefaultValueFields")); + } + + try { + JsonFormat.printer() + .includingDefaultValueFields(fixedFields) + .includingDefaultValueFields(fixedFields); + fail("IllegalStateException is expected."); + } catch (IllegalStateException e) { + // Expected. + assertTrue( + "Exception message should mention includingDefaultValueFields.", + e.getMessage().contains("includingDefaultValueFields")); + } + + Set intFields = new HashSet(); + for (FieldDescriptor fieldDesc : TestAllTypes.getDescriptor().getFields()) { + if (fieldDesc.getName().contains("_int")) { + intFields.add(fieldDesc); + } + } + + try { + JsonFormat.printer() + .includingDefaultValueFields(intFields) + .includingDefaultValueFields(fixedFields); + fail("IllegalStateException is expected."); + } catch (IllegalStateException e) { + // Expected. + assertTrue( + "Exception message should mention includingDefaultValueFields.", + e.getMessage().contains("includingDefaultValueFields")); + } + + try { + JsonFormat.printer().includingDefaultValueFields(null); + fail("IllegalArgumentException is expected."); + } catch (IllegalArgumentException e) { + // Expected. + assertTrue( + "Exception message should mention includingDefaultValueFields.", + e.getMessage().contains("includingDefaultValueFields")); + } + + try { + JsonFormat.printer().includingDefaultValueFields(Collections.emptySet()); + fail("IllegalArgumentException is expected."); + } catch (IllegalArgumentException e) { + // Expected. + assertTrue( + "Exception message should mention includingDefaultValueFields.", + e.getMessage().contains("includingDefaultValueFields")); + } + TestMap mapMessage = TestMap.getDefaultInstance(); assertEquals("{\n}", JsonFormat.printer().print(mapMessage)); assertEquals( @@ -1283,16 +1404,17 @@ public class JsonFormatTest extends TestCase { assertEquals("{\n}", JsonFormat.printer().includingDefaultValueFields().print(oneofMessage)); oneofMessage = TestOneof.newBuilder().setOneofInt32(42).build(); - assertEquals("{\n \"oneofInt32\": 42\n}", - JsonFormat.printer().print(oneofMessage)); - assertEquals("{\n \"oneofInt32\": 42\n}", + assertEquals("{\n \"oneofInt32\": 42\n}", JsonFormat.printer().print(oneofMessage)); + assertEquals( + "{\n \"oneofInt32\": 42\n}", JsonFormat.printer().includingDefaultValueFields().print(oneofMessage)); TestOneof.Builder oneofBuilder = TestOneof.newBuilder(); mergeFromJson("{\n" + " \"oneofNullValue\": null \n" + "}", oneofBuilder); oneofMessage = oneofBuilder.build(); assertEquals("{\n \"oneofNullValue\": null\n}", JsonFormat.printer().print(oneofMessage)); - assertEquals("{\n \"oneofNullValue\": null\n}", + assertEquals( + "{\n \"oneofNullValue\": null\n}", JsonFormat.printer().includingDefaultValueFields().print(oneofMessage)); } @@ -1424,11 +1546,12 @@ public class JsonFormatTest extends TestCase { // Test that we are not leaking out JSON exceptions. public void testJsonException() throws Exception { - InputStream throwingInputStream = new InputStream() { - public int read() throws IOException { - throw new IOException("12345"); - } - }; + InputStream throwingInputStream = + new InputStream() { + public int read() throws IOException { + throw new IOException("12345"); + } + }; InputStreamReader throwingReader = new InputStreamReader(throwingInputStream); // When the underlying reader throws IOException, JsonFormat should forward // through this IOException. diff --git a/third_party/protobuf/3.2.0/jenkins/buildcmds/pull_request_32.sh b/third_party/protobuf/3.2.0/jenkins/buildcmds/pull_request_32.sh index bf0fb7ffe3..99df297190 100755 --- a/third_party/protobuf/3.2.0/jenkins/buildcmds/pull_request_32.sh +++ b/third_party/protobuf/3.2.0/jenkins/buildcmds/pull_request_32.sh @@ -12,5 +12,5 @@ export DOCKERFILE_DIR=jenkins/docker32 export DOCKER_RUN_SCRIPT=jenkins/pull_request_in_docker.sh export OUTPUT_DIR=testoutput -export TEST_SET="php_all_32" +export TEST_SET="php_all" ./jenkins/build_and_run_docker.sh diff --git a/third_party/protobuf/3.2.0/jenkins/docker/Dockerfile b/third_party/protobuf/3.2.0/jenkins/docker/Dockerfile index 659336d825..9c9ee56b8c 100644 --- a/third_party/protobuf/3.2.0/jenkins/docker/Dockerfile +++ b/third_party/protobuf/3.2.0/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 6b27c1f981a9a93918e4039f236ead27165a8e91 && \ + git reset --hard c2b3b3e04e7a023efe06f2107705b45428847800 && \ ./autogen.sh && \ ./configure && \ make -j4 && \ @@ -147,6 +147,23 @@ RUN cd php-5.5.38 && ./configure --enable-maintainer-zts --prefix=/usr/local/php make && make install && cd .. RUN cd php-5.5.38 && make clean && ./configure --prefix=/usr/local/php-5.5 && \ make && make install && cd .. + +RUN wget http://am1.php.net/get/php-5.6.30.tar.bz2/from/this/mirror +RUN mv mirror php-5.6.30.tar.bz2 +RUN tar -xvf php-5.6.30.tar.bz2 +RUN cd php-5.6.30 && ./configure --enable-maintainer-zts --prefix=/usr/local/php-5.6-zts && \ + make && make install && cd .. +RUN cd php-5.6.30 && make clean && ./configure --prefix=/usr/local/php-5.6 && \ + make && make install && cd .. + +RUN wget http://am1.php.net/get/php-7.0.18.tar.bz2/from/this/mirror +RUN mv mirror php-7.0.18.tar.bz2 +RUN tar -xvf php-7.0.18.tar.bz2 +RUN cd php-7.0.18 && ./configure --enable-maintainer-zts --prefix=/usr/local/php-7.0-zts && \ + make && make install && cd .. +RUN cd php-7.0.18 && make clean && ./configure --prefix=/usr/local/php-7.0 && \ + 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 @@ -157,21 +174,21 @@ RUN cd /tmp && \ rm -rf protobuf && \ git clone https://github.com/google/protobuf.git && \ cd protobuf && \ - git reset 46ae90dc5e145b12fffa7e053a908a9f3e066286 && \ + git reset --hard 6b27c1f981a9a93918e4039f236ead27165a8e91 && \ cd php && \ 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/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 && \ + 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/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 && \ + 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 diff --git a/third_party/protobuf/3.2.0/jenkins/docker32/Dockerfile b/third_party/protobuf/3.2.0/jenkins/docker32/Dockerfile index 02e9df176c..ab3fd9578b 100644 --- a/third_party/protobuf/3.2.0/jenkins/docker32/Dockerfile +++ b/third_party/protobuf/3.2.0/jenkins/docker32/Dockerfile @@ -64,7 +64,7 @@ RUN php -r "unlink('composer-setup.php');" RUN cd /tmp && \ git clone https://github.com/google/protobuf.git && \ cd protobuf/php && \ - git reset 6b27c1f981a9a93918e4039f236ead27165a8e91 && \ + git reset --hard 6b27c1f981a9a93918e4039f236ead27165a8e91 && \ 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 && \ @@ -80,14 +80,31 @@ RUN cd /tmp && \ 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 RUN cd php-5.5.38 && ./configure --enable-maintainer-zts --prefix=/usr/local/php-5.5-zts && \ make && make install && make clean && cd .. -RUN cd php-5.5.38 && ./configure --enable-bcmath --prefix=/usr/local/php-5.5-bc && \ +RUN cd php-5.5.38 && make clean && ./configure --enable-bcmath --prefix=/usr/local/php-5.5 && \ make && make install && make clean && cd .. +RUN wget http://am1.php.net/get/php-5.6.30.tar.bz2/from/this/mirror +RUN mv mirror php-5.6.30.tar.bz2 +RUN tar -xvf php-5.6.30.tar.bz2 +RUN cd php-5.6.30 && ./configure --enable-maintainer-zts --prefix=/usr/local/php-5.6-zts && \ + make && make install && cd .. +RUN cd php-5.6.30 && make clean && ./configure --enable-bcmath --prefix=/usr/local/php-5.6 && \ + make && make install && cd .. + +RUN wget http://am1.php.net/get/php-7.0.18.tar.bz2/from/this/mirror +RUN mv mirror php-7.0.18.tar.bz2 +RUN tar -xvf php-7.0.18.tar.bz2 +RUN cd php-7.0.18 && ./configure --enable-maintainer-zts --prefix=/usr/local/php-7.0-zts && \ + make && make install && cd .. +RUN cd php-7.0.18 && make clean && ./configure --enable-bcmath --prefix=/usr/local/php-7.0 && \ + make && make install && cd .. + ################## # Python dependencies diff --git a/third_party/protobuf/3.2.0/js/binary/decoder.js b/third_party/protobuf/3.2.0/js/binary/decoder.js index 26bf359459..ad9cb01bd5 100644 --- a/third_party/protobuf/3.2.0/js/binary/decoder.js +++ b/third_party/protobuf/3.2.0/js/binary/decoder.js @@ -71,7 +71,7 @@ jspb.BinaryIterator = function(opt_decoder, opt_next, opt_elements) { */ this.nextMethod_ = null; - /** @private {Array.} */ + /** @private {?Array} */ this.elements_ = null; /** @private {number} */ @@ -100,7 +100,7 @@ jspb.BinaryIterator.prototype.init_ = this.decoder_ = opt_decoder; this.nextMethod_ = opt_next; } - this.elements_ = opt_elements ? opt_elements : null; + this.elements_ = opt_elements || null; this.cursor_ = 0; this.nextValue_ = null; this.atEnd_ = !this.decoder_ && !this.elements_; @@ -953,6 +953,7 @@ jspb.BinaryDecoder.prototype.readString = function(length) { var end = cursor + length; var codeUnits = []; + var result = ''; while (cursor < end) { var c = bytes[cursor++]; if (c < 128) { // Regular 7-bit ASCII. @@ -973,7 +974,7 @@ jspb.BinaryDecoder.prototype.readString = function(length) { var c2 = bytes[cursor++]; var c3 = bytes[cursor++]; var c4 = bytes[cursor++]; - // Characters written on 4 bytes have 21 bits for a codepoint. + // Characters written on 4 bytes have 21 bits for a codepoint. // We can't fit that on 16bit characters, so we use surrogates. var codepoint = ((c & 7) << 18) | ((c2 & 63) << 12) | ((c3 & 63) << 6) | (c4 & 63); // Surrogates formula from wikipedia. @@ -986,10 +987,14 @@ jspb.BinaryDecoder.prototype.readString = function(length) { var high = ((codepoint >> 10) & 1023) + 0xD800; codeUnits.push(high, low); } + + // Avoid exceeding the maximum stack size when calling {@code apply}. + if (codeUnits.length >= 8192) { + result += String.fromCharCode.apply(null, codeUnits); + codeUnits.length = 0; + } } - // String.fromCharCode.apply is faster than manually appending characters on - // Chrome 25+, and generates no additional cons string garbage. - var result = String.fromCharCode.apply(null, codeUnits); + result += String.fromCharCode.apply(null, codeUnits); this.cursor_ = cursor; return result; }; diff --git a/third_party/protobuf/3.2.0/js/binary/decoder_test.js b/third_party/protobuf/3.2.0/js/binary/decoder_test.js index cb8aff969d..d0139e293a 100644 --- a/third_party/protobuf/3.2.0/js/binary/decoder_test.js +++ b/third_party/protobuf/3.2.0/js/binary/decoder_test.js @@ -210,6 +210,25 @@ describe('binaryDecoderTest', function() { assertEquals(hashD, decoder.readFixedHash64()); }); + /** + * Tests reading and writing large strings + */ + it('testLargeStrings', function() { + var encoder = new jspb.BinaryEncoder(); + + var len = 150000; + var long_string = ''; + for (var i = 0; i < len; i++) { + long_string += 'a'; + } + + encoder.writeString(long_string); + + var decoder = jspb.BinaryDecoder.alloc(encoder.end()); + + assertEquals(long_string, decoder.readString(len)); + }); + /** * Test encoding and decoding utf-8. */ diff --git a/third_party/protobuf/3.2.0/js/binary/encoder.js b/third_party/protobuf/3.2.0/js/binary/encoder.js index aee33e7e68..f25935f1fa 100644 --- a/third_party/protobuf/3.2.0/js/binary/encoder.js +++ b/third_party/protobuf/3.2.0/js/binary/encoder.js @@ -355,8 +355,8 @@ jspb.BinaryEncoder.prototype.writeInt64 = function(value) { */ jspb.BinaryEncoder.prototype.writeInt64String = function(value) { goog.asserts.assert(value == Math.floor(value)); - goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_63) && - (value < jspb.BinaryConstants.TWO_TO_63)); + goog.asserts.assert((+value >= -jspb.BinaryConstants.TWO_TO_63) && + (+value < jspb.BinaryConstants.TWO_TO_63)); jspb.utils.splitHash64(jspb.utils.decimalStringToHash64(value)); this.writeSplitFixed64(jspb.utils.split64Low, jspb.utils.split64High); }; diff --git a/third_party/protobuf/3.2.0/js/binary/reader.js b/third_party/protobuf/3.2.0/js/binary/reader.js index 8c5a4e88db..d5d698f79d 100644 --- a/third_party/protobuf/3.2.0/js/binary/reader.js +++ b/third_party/protobuf/3.2.0/js/binary/reader.js @@ -971,7 +971,7 @@ jspb.BinaryReader.prototype.readFixedHash64 = function() { /** * Reads a packed scalar field using the supplied raw reader function. - * @param {function()} decodeMethod + * @param {function(this:jspb.BinaryDecoder)} decodeMethod * @return {!Array} * @private */ diff --git a/third_party/protobuf/3.2.0/js/binary/utils.js b/third_party/protobuf/3.2.0/js/binary/utils.js index 3ecd08e9f3..7702020b56 100644 --- a/third_party/protobuf/3.2.0/js/binary/utils.js +++ b/third_party/protobuf/3.2.0/js/binary/utils.js @@ -430,7 +430,7 @@ jspb.utils.joinHash64 = function(bitsLow, bitsHigh) { /** * Individual digits for number->string conversion. - * @const {!Array.} + * @const {!Array.} */ jspb.utils.DIGITS = [ '0', '1', '2', '3', '4', '5', '6', '7', diff --git a/third_party/protobuf/3.2.0/js/binary/writer.js b/third_party/protobuf/3.2.0/js/binary/writer.js index c3009dbb54..672e94bd29 100644 --- a/third_party/protobuf/3.2.0/js/binary/writer.js +++ b/third_party/protobuf/3.2.0/js/binary/writer.js @@ -596,8 +596,8 @@ jspb.BinaryWriter.prototype.writeSint64 = function(field, value) { */ jspb.BinaryWriter.prototype.writeSint64String = function(field, value) { if (value == null) return; - goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_63) && - (value < jspb.BinaryConstants.TWO_TO_63)); + goog.asserts.assert((+value >= -jspb.BinaryConstants.TWO_TO_63) && + (+value < jspb.BinaryConstants.TWO_TO_63)); this.writeZigzagVarint64String_(field, value); }; diff --git a/third_party/protobuf/3.2.0/js/binary/writer_test.js b/third_party/protobuf/3.2.0/js/binary/writer_test.js index 83fcdf917f..118eecfc6c 100644 --- a/third_party/protobuf/3.2.0/js/binary/writer_test.js +++ b/third_party/protobuf/3.2.0/js/binary/writer_test.js @@ -47,7 +47,7 @@ goog.require('jspb.BinaryWriter'); * @param {function()} func This function should throw an error when run. */ function assertFails(func) { - var e = assertThrows(func); + assertThrows(func); } diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/arith_test.js b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/arith_test.js new file mode 100644 index 0000000000..89796bf795 --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/arith_test.js @@ -0,0 +1,355 @@ +// 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. + +/** + * @fileoverview Test cases for Int64-manipulation functions. + * + * Test suite is written using Jasmine -- see http://jasmine.github.io/ + * + * @author cfallin@google.com (Chris Fallin) + */ + +goog.require('goog.testing.asserts'); +goog.require('jspb.arith.Int64'); +goog.require('jspb.arith.UInt64'); + + +describe('binaryArithTest', function() { + /** + * Tests comparison operations. + */ + it('testCompare', function() { + var a = new jspb.arith.UInt64(1234, 5678); + var b = new jspb.arith.UInt64(1234, 5678); + assertEquals(a.cmp(b), 0); + assertEquals(b.cmp(a), 0); + b.lo -= 1; + assertEquals(a.cmp(b), 1); + assertEquals(b.cmp(a), -1); + b.lo += 2; + assertEquals(a.cmp(b), -1); + assertEquals(b.cmp(a), 1); + b.lo = a.lo; + b.hi = a.hi - 1; + assertEquals(a.cmp(b), 1); + assertEquals(b.cmp(a), -1); + + assertEquals(a.zero(), false); + assertEquals(a.msb(), false); + assertEquals(a.lsb(), false); + a.hi = 0; + a.lo = 0; + assertEquals(a.zero(), true); + a.hi = 0x80000000; + assertEquals(a.zero(), false); + assertEquals(a.msb(), true); + a.lo = 0x00000001; + assertEquals(a.lsb(), true); + }); + + + /** + * Tests shifts. + */ + it('testShifts', function() { + var a = new jspb.arith.UInt64(1, 0); + assertEquals(a.lo, 1); + assertEquals(a.hi, 0); + var orig = a; + a = a.leftShift(); + assertEquals(orig.lo, 1); // original unmodified. + assertEquals(orig.hi, 0); + assertEquals(a.lo, 2); + assertEquals(a.hi, 0); + a = a.leftShift(); + assertEquals(a.lo, 4); + assertEquals(a.hi, 0); + for (var i = 0; i < 29; i++) { + a = a.leftShift(); + } + assertEquals(a.lo, 0x80000000); + assertEquals(a.hi, 0); + a = a.leftShift(); + assertEquals(a.lo, 0); + assertEquals(a.hi, 1); + a = a.leftShift(); + assertEquals(a.lo, 0); + assertEquals(a.hi, 2); + a = a.rightShift(); + a = a.rightShift(); + assertEquals(a.lo, 0x80000000); + assertEquals(a.hi, 0); + a = a.rightShift(); + assertEquals(a.lo, 0x40000000); + assertEquals(a.hi, 0); + }); + + + /** + * Tests additions. + */ + it('testAdd', function() { + var a = new jspb.arith.UInt64(/* lo = */ 0x89abcdef, + /* hi = */ 0x01234567); + var b = new jspb.arith.UInt64(/* lo = */ 0xff52ab91, + /* hi = */ 0x92fa2123); + // Addition with carry. + var c = a.add(b); + assertEquals(a.lo, 0x89abcdef); // originals unmodified. + assertEquals(a.hi, 0x01234567); + assertEquals(b.lo, 0xff52ab91); + assertEquals(b.hi, 0x92fa2123); + assertEquals(c.lo, 0x88fe7980); + assertEquals(c.hi, 0x941d668b); + + // Simple addition without carry. + a.lo = 2; + a.hi = 0; + b.lo = 3; + b.hi = 0; + c = a.add(b); + assertEquals(c.lo, 5); + assertEquals(c.hi, 0); + }); + + + /** + * Test subtractions. + */ + it('testSub', function() { + var kLength = 10; + var hiValues = [0x1682ef32, + 0x583902f7, + 0xb62f5955, + 0x6ea99bbf, + 0x25a39c20, + 0x0700a08b, + 0x00f7304d, + 0x91a5b5af, + 0x89077fd2, + 0xe09e347c]; + var loValues = [0xe1538b18, + 0xbeacd556, + 0x74100758, + 0x96e3cb26, + 0x56c37c3f, + 0xe00b3f7d, + 0x859f25d7, + 0xc2ee614a, + 0xe1d21cd7, + 0x30aae6a4]; + for (var i = 0; i < kLength; i++) { + for (var j = 0; j < kLength; j++) { + var a = new jspb.arith.UInt64(loValues[i], hiValues[j]); + var b = new jspb.arith.UInt64(loValues[j], hiValues[i]); + var c = a.add(b).sub(b); + assertEquals(c.hi, a.hi); + assertEquals(c.lo, a.lo); + } + } + }); + + + /** + * Tests 32-by-32 multiplication. + */ + it('testMul32x32', function() { + var testData = [ + // a b low(a*b) high(a*b) + [0xc0abe2f8, 0x1607898a, 0x5de711b0, 0x109471b8], + [0x915eb3cb, 0x4fb66d0e, 0xbd0d441a, 0x2d43d0bc], + [0xfe4efe70, 0x80b48c37, 0xbcddea10, 0x7fdada0c], + [0xe222fd4a, 0xe43d524a, 0xd5e0eb64, 0xc99d549c], + [0xd171f469, 0xb94ebd01, 0x4be17969, 0x979bc4fa], + [0x829cc1df, 0xe2598b38, 0xf4157dc8, 0x737c12ad], + [0xf10c3767, 0x8382881e, 0x942b3612, 0x7bd428b8], + [0xb0f6dd24, 0x232597e1, 0x079c98a4, 0x184bbce7], + [0xfcdb05a7, 0x902f55bc, 0x636199a4, 0x8e69f412], + [0x0dd0bfa9, 0x916e27b1, 0x6e2542d9, 0x07d92e65] + ]; + + for (var i = 0; i < testData.length; i++) { + var a = testData[i][0] >>> 0; + var b = testData[i][1] >>> 0; + var cLow = testData[i][2] >>> 0; + var cHigh = testData[i][3] >>> 0; + var c = jspb.arith.UInt64.mul32x32(a, b); + assertEquals(c.lo, cLow); + assertEquals(c.hi, cHigh); + } + }); + + + /** + * Tests 64-by-32 multiplication. + */ + it('testMul', function() { + // 64x32 bits produces 96 bits of product. The multiplication function under + // test truncates the top 32 bits, so we compare against a 64-bit expected + // product. + var testData = [ + // low(a) high(a) low(a*b) high(a*b) + [0xec10955b, 0x360eb168, 0x4b7f3f5b, 0xbfcb7c59, 0x9517da5f], + [0x42b000fc, 0x9d101642, 0x6fa1ab72, 0x2584c438, 0x6a9e6d2b], + [0xf42d4fb4, 0xae366403, 0xa65a1000, 0x92434000, 0x1ff978df], + [0x17e2f56b, 0x25487693, 0xf13f98c7, 0x73794e2d, 0xa96b0c6a], + [0x492f241f, 0x76c0eb67, 0x7377ac44, 0xd4336c3c, 0xfc4b1ebe], + [0xd6b92321, 0xe184fa48, 0xd6e76904, 0x93141584, 0xcbf44da1], + [0x4bf007ea, 0x968c0a9e, 0xf5e4026a, 0x4fdb1ae4, 0x61b9fb7d], + [0x10a83be7, 0x2d685ba6, 0xc9e5fb7f, 0x2ad43499, 0x3742473d], + [0x2f261829, 0x1aca681a, 0x3d3494e3, 0x8213205b, 0x283719f8], + [0xe4f2ce21, 0x2e74b7bd, 0xd801b38b, 0xbc17feeb, 0xc6c44e0f] + ]; + + for (var i = 0; i < testData.length; i++) { + var a = new jspb.arith.UInt64(testData[i][0], testData[i][1]); + var prod = a.mul(testData[i][2]); + assertEquals(prod.lo, testData[i][3]); + assertEquals(prod.hi, testData[i][4]); + } + }); + + + /** + * Tests 64-div-by-32 division. + */ + it('testDiv', function() { + // Compute a/b, yielding quot = a/b and rem = a%b. + var testData = [ + // --- divisors in (0, 2^32-1) to test full divisor range + // low(a) high(a) b low(quot) high(quot) rem + [0x712443f1, 0xe85cefcc, 0xc1a7050b, 0x332c79ad, 0x00000001, 0x92ffa882], + [0x11912915, 0xb2699eb5, 0x30467cbe, 0xb21b4be4, 0x00000003, 0x283465dd], + [0x0d917982, 0x201f2a6e, 0x3f35bf03, 0x8217c8e4, 0x00000000, 0x153402d6], + [0xa072c108, 0x74020c96, 0xc60568fd, 0x95f9613e, 0x00000000, 0x3f4676c2], + [0xd845d5d8, 0xcdd235c4, 0x20426475, 0x6154e78b, 0x00000006, 0x202fb751], + [0xa4dbf71f, 0x9e90465e, 0xf08e022f, 0xa8be947f, 0x00000000, 0xbe43b5ce], + [0x3dbe627f, 0xa791f4b9, 0x28a5bd89, 0x1f5dfe93, 0x00000004, 0x02bf9ed4], + [0x5c1c53ee, 0xccf5102e, 0x198576e7, 0x07e3ae31, 0x00000008, 0x02ea8fb7], + [0xfef1e581, 0x04714067, 0xca6540c1, 0x059e73ec, 0x00000000, 0x31658095], + [0x1e2dd90c, 0x13dd6667, 0x8b2184c3, 0x248d1a42, 0x00000000, 0x4ca6d0c6], + // --- divisors in (0, 2^16-1) to test larger quotient high-words + // low(a) high(a) b low(quot) high(quot) rem + [0x86722b47, 0x2cd57c9a, 0x00003123, 0x2ae41b7a, 0x0000e995, 0x00000f99], + [0x1dd7884c, 0xf5e839bc, 0x00009eeb, 0x5c886242, 0x00018c21, 0x000099b6], + [0x5c53d625, 0x899fc7e5, 0x000087d7, 0xd625007a, 0x0001035c, 0x000019af], + [0x6932d932, 0x9d0a5488, 0x000051fb, 0x9d976143, 0x0001ea63, 0x00004981], + [0x4d18bb85, 0x0c92fb31, 0x00001d9f, 0x03265ab4, 0x00006cac, 0x000001b9], + [0xbe756768, 0xdea67ccb, 0x00008a03, 0x58add442, 0x00019cff, 0x000056a2], + [0xe2466f9a, 0x2521f114, 0x0000c350, 0xa0c0860d, 0x000030ab, 0x0000a48a], + [0xf00ddad1, 0xe2f5446a, 0x00002cfc, 0x762697a6, 0x00050b96, 0x00000b69], + [0xa879152a, 0x0a70e0a5, 0x00007cdf, 0xb44151b3, 0x00001567, 0x0000363d], + [0x7179a74c, 0x46083fff, 0x0000253c, 0x4d39ba6e, 0x0001e17f, 0x00000f84] + ]; + + for (var i = 0; i < testData.length; i++) { + var a = new jspb.arith.UInt64(testData[i][0], testData[i][1]); + var result = a.div(testData[i][2]); + var quotient = result[0]; + var remainder = result[1]; + assertEquals(quotient.lo, testData[i][3]); + assertEquals(quotient.hi, testData[i][4]); + assertEquals(remainder.lo, testData[i][5]); + } + }); + + + /** + * Tests .toString() and .fromString(). + */ + it('testStrings', function() { + var testData = [ + [0x5e84c935, 0xcae33d0e, '14619595947299359029'], + [0x62b3b8b8, 0x93480544, '10612738313170434232'], + [0x319bfb13, 0xc01c4172, '13843011313344445203'], + [0x5b8a65fb, 0xa5885b31, '11927883880638080507'], + [0x6bdb80f1, 0xb0d1b16b, '12741159895737008369'], + [0x4b82b442, 0x2e0d8c97, '3318463081876730946'], + [0x780d5208, 0x7d76752c, '9040542135845999112'], + [0x2e46800f, 0x0993778d, '690026616168284175'], + [0xf00a7e32, 0xcd8e3931, '14811839111111540274'], + [0x1baeccd6, 0x923048c4, '10533999535534820566'], + [0x03669d29, 0xbff3ab72, '13831587386756603177'], + [0x2526073e, 0x01affc81, '121593346566522686'], + [0xc24244e0, 0xd7f40d0e, '15561076969511732448'], + [0xc56a341e, 0xa68b66a7, '12000798502816461854'], + [0x8738d64d, 0xbfe78604, '13828168534871037517'], + [0x5baff03b, 0xd7572aea, '15516918227177304123'], + [0x4a843d8a, 0x864e132b, '9677693725920476554'], + [0x25b4e94d, 0x22b54dc6, '2500990681505655117'], + [0x6bbe664b, 0x55a5cc0e, '6171563226690381387'], + [0xee916c81, 0xb00aabb3, '12685140089732426881'] + ]; + + for (var i = 0; i < testData.length; i++) { + var a = new jspb.arith.UInt64(testData[i][0], testData[i][1]); + var roundtrip = jspb.arith.UInt64.fromString(a.toString()); + assertEquals(roundtrip.lo, a.lo); + assertEquals(roundtrip.hi, a.hi); + assertEquals(a.toString(), testData[i][2]); + } + }); + + + /** + * Tests signed Int64s. These are built on UInt64s, so we only need to test + * the explicit overrides: .toString() and .fromString(). + */ + it('testSignedInt64', function() { + var testStrings = [ + '-7847499644178593666', + '3771946501229139523', + '2872856549054995060', + '-5780049594274350904', + '3383785956695105201', + '2973055184857072610', + '-3879428459215627206', + '4589812431064156631', + '8484075557333689940', + '1075325817098092407', + '-4346697501012292314', + '2488620459718316637', + '6112655187423520672', + '-3655278273928612104', + '3439154019435803196', + '1004112478843763757', + '-6587790776614368413', + '664320065099714586', + '4760412909973292912', + '-7911903989602274672' + ]; + + for (var i = 0; i < testStrings.length; i++) { + var roundtrip = + jspb.arith.Int64.fromString(testStrings[i]).toString(); + assertEquals(roundtrip, testStrings[i]); + } + }); +}); diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/decoder_test.js b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/decoder_test.js new file mode 100644 index 0000000000..ac31264847 --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/decoder_test.js @@ -0,0 +1,334 @@ +// 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. + +/** + * @fileoverview Test cases for jspb's binary protocol buffer decoder. + * + * There are two particular magic numbers that need to be pointed out - + * 2^64-1025 is the largest number representable as both a double and an + * unsigned 64-bit integer, and 2^63-513 is the largest number representable as + * both a double and a signed 64-bit integer. + * + * Test suite is written using Jasmine -- see http://jasmine.github.io/ + * + * @author aappleby@google.com (Austin Appleby) + */ + +goog.require('goog.testing.asserts'); +goog.require('jspb.BinaryConstants'); +goog.require('jspb.BinaryDecoder'); +goog.require('jspb.BinaryEncoder'); + + +/** + * Tests encoding and decoding of unsigned types. + * @param {Function} readValue + * @param {Function} writeValue + * @param {number} epsilon + * @param {number} upperLimit + * @param {Function} filter + * @suppress {missingProperties|visibility} + */ +function doTestUnsignedValue(readValue, + writeValue, epsilon, upperLimit, filter) { + var encoder = new jspb.BinaryEncoder(); + + // Encode zero and limits. + writeValue.call(encoder, filter(0)); + writeValue.call(encoder, filter(epsilon)); + writeValue.call(encoder, filter(upperLimit)); + + // Encode positive values. + for (var cursor = epsilon; cursor < upperLimit; cursor *= 1.1) { + writeValue.call(encoder, filter(cursor)); + } + + var decoder = jspb.BinaryDecoder.alloc(encoder.end()); + + // Check zero and limits. + assertEquals(filter(0), readValue.call(decoder)); + assertEquals(filter(epsilon), readValue.call(decoder)); + assertEquals(filter(upperLimit), readValue.call(decoder)); + + // Check positive values. + for (var cursor = epsilon; cursor < upperLimit; cursor *= 1.1) { + if (filter(cursor) != readValue.call(decoder)) throw 'fail!'; + } + + // Encoding values outside the valid range should assert. + assertThrows(function() {writeValue.call(encoder, -1);}); + assertThrows(function() {writeValue.call(encoder, upperLimit * 1.1);}); +} + + +/** + * Tests encoding and decoding of signed types. + * @param {Function} readValue + * @param {Function} writeValue + * @param {number} epsilon + * @param {number} lowerLimit + * @param {number} upperLimit + * @param {Function} filter + * @suppress {missingProperties} + */ +function doTestSignedValue(readValue, + writeValue, epsilon, lowerLimit, upperLimit, filter) { + var encoder = new jspb.BinaryEncoder(); + + // Encode zero and limits. + writeValue.call(encoder, filter(lowerLimit)); + writeValue.call(encoder, filter(-epsilon)); + writeValue.call(encoder, filter(0)); + writeValue.call(encoder, filter(epsilon)); + writeValue.call(encoder, filter(upperLimit)); + + var inputValues = []; + + // Encode negative values. + for (var cursor = lowerLimit; cursor < -epsilon; cursor /= 1.1) { + var val = filter(cursor); + writeValue.call(encoder, val); + inputValues.push(val); + } + + // Encode positive values. + for (var cursor = epsilon; cursor < upperLimit; cursor *= 1.1) { + var val = filter(cursor); + writeValue.call(encoder, val); + inputValues.push(val); + } + + var decoder = jspb.BinaryDecoder.alloc(encoder.end()); + + // Check zero and limits. + assertEquals(filter(lowerLimit), readValue.call(decoder)); + assertEquals(filter(-epsilon), readValue.call(decoder)); + assertEquals(filter(0), readValue.call(decoder)); + assertEquals(filter(epsilon), readValue.call(decoder)); + assertEquals(filter(upperLimit), readValue.call(decoder)); + + // Verify decoded values. + for (var i = 0; i < inputValues.length; i++) { + assertEquals(inputValues[i], readValue.call(decoder)); + } + + // Encoding values outside the valid range should assert. + assertThrows(function() {writeValue.call(encoder, lowerLimit * 1.1);}); + assertThrows(function() {writeValue.call(encoder, upperLimit * 1.1);}); +} + +describe('binaryDecoderTest', function() { + /** + * Tests the decoder instance cache. + */ + it('testInstanceCache', /** @suppress {visibility} */ function() { + // Empty the instance caches. + jspb.BinaryDecoder.instanceCache_ = []; + + // Allocating and then freeing a decoder should put it in the instance + // cache. + jspb.BinaryDecoder.alloc().free(); + + assertEquals(1, jspb.BinaryDecoder.instanceCache_.length); + + // Allocating and then freeing three decoders should leave us with three in + // the cache. + + var decoder1 = jspb.BinaryDecoder.alloc(); + var decoder2 = jspb.BinaryDecoder.alloc(); + var decoder3 = jspb.BinaryDecoder.alloc(); + decoder1.free(); + decoder2.free(); + decoder3.free(); + + assertEquals(3, jspb.BinaryDecoder.instanceCache_.length); + }); + + + /** + * Tests reading 64-bit integers as hash strings. + */ + it('testHashStrings', function() { + var encoder = new jspb.BinaryEncoder(); + + var hashA = String.fromCharCode(0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00); + var hashB = String.fromCharCode(0x12, 0x34, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00); + var hashC = String.fromCharCode(0x12, 0x34, 0x56, 0x78, + 0x87, 0x65, 0x43, 0x21); + var hashD = String.fromCharCode(0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF); + + encoder.writeVarintHash64(hashA); + encoder.writeVarintHash64(hashB); + encoder.writeVarintHash64(hashC); + encoder.writeVarintHash64(hashD); + + encoder.writeFixedHash64(hashA); + encoder.writeFixedHash64(hashB); + encoder.writeFixedHash64(hashC); + encoder.writeFixedHash64(hashD); + + var decoder = jspb.BinaryDecoder.alloc(encoder.end()); + + assertEquals(hashA, decoder.readVarintHash64()); + assertEquals(hashB, decoder.readVarintHash64()); + assertEquals(hashC, decoder.readVarintHash64()); + assertEquals(hashD, decoder.readVarintHash64()); + + assertEquals(hashA, decoder.readFixedHash64()); + assertEquals(hashB, decoder.readFixedHash64()); + assertEquals(hashC, decoder.readFixedHash64()); + assertEquals(hashD, decoder.readFixedHash64()); + }); + + + /** + * Verifies that misuse of the decoder class triggers assertions. + * @suppress {checkTypes|visibility} + */ + it('testDecodeErrors', function() { + // Reading a value past the end of the stream should trigger an assertion. + var decoder = jspb.BinaryDecoder.alloc([0, 1, 2]); + assertThrows(function() {decoder.readUint64()}); + + // Overlong varints should trigger assertions. + decoder.setBlock([255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 0]); + assertThrows(function() {decoder.readUnsignedVarint64()}); + decoder.reset(); + assertThrows(function() {decoder.readSignedVarint64()}); + decoder.reset(); + assertThrows(function() {decoder.readZigzagVarint64()}); + + // Positive 32-bit varints encoded with 1 bits in positions 33 through 35 + // should trigger assertions. + decoder.setBlock([255, 255, 255, 255, 0x1F]); + assertThrows(function() {decoder.readUnsignedVarint32()}); + + decoder.setBlock([255, 255, 255, 255, 0x2F]); + assertThrows(function() {decoder.readUnsignedVarint32()}); + + decoder.setBlock([255, 255, 255, 255, 0x4F]); + assertThrows(function() {decoder.readUnsignedVarint32()}); + + // Negative 32-bit varints encoded with non-1 bits in the high dword should + // trigger assertions. + decoder.setBlock([255, 255, 255, 255, 255, 255, 0, 255, 255, 1]); + assertThrows(function() {decoder.readUnsignedVarint32()}); + + decoder.setBlock([255, 255, 255, 255, 255, 255, 255, 255, 255, 0]); + assertThrows(function() {decoder.readUnsignedVarint32()}); + }); + + + /** + * Tests encoding and decoding of unsigned integers. + */ + it('testUnsignedIntegers', function() { + doTestUnsignedValue( + jspb.BinaryDecoder.prototype.readUint8, + jspb.BinaryEncoder.prototype.writeUint8, + 1, 0xFF, Math.round); + + doTestUnsignedValue( + jspb.BinaryDecoder.prototype.readUint16, + jspb.BinaryEncoder.prototype.writeUint16, + 1, 0xFFFF, Math.round); + + doTestUnsignedValue( + jspb.BinaryDecoder.prototype.readUint32, + jspb.BinaryEncoder.prototype.writeUint32, + 1, 0xFFFFFFFF, Math.round); + + doTestUnsignedValue( + jspb.BinaryDecoder.prototype.readUint64, + jspb.BinaryEncoder.prototype.writeUint64, + 1, Math.pow(2, 64) - 1025, Math.round); + }); + + + /** + * Tests encoding and decoding of signed integers. + */ + it('testSignedIntegers', function() { + doTestSignedValue( + jspb.BinaryDecoder.prototype.readInt8, + jspb.BinaryEncoder.prototype.writeInt8, + 1, -0x80, 0x7F, Math.round); + + doTestSignedValue( + jspb.BinaryDecoder.prototype.readInt16, + jspb.BinaryEncoder.prototype.writeInt16, + 1, -0x8000, 0x7FFF, Math.round); + + doTestSignedValue( + jspb.BinaryDecoder.prototype.readInt32, + jspb.BinaryEncoder.prototype.writeInt32, + 1, -0x80000000, 0x7FFFFFFF, Math.round); + + doTestSignedValue( + jspb.BinaryDecoder.prototype.readInt64, + jspb.BinaryEncoder.prototype.writeInt64, + 1, -Math.pow(2, 63), Math.pow(2, 63) - 513, Math.round); + }); + + + /** + * Tests encoding and decoding of floats. + */ + it('testFloats', function() { + /** + * @param {number} x + * @return {number} + */ + function truncate(x) { + var temp = new Float32Array(1); + temp[0] = x; + return temp[0]; + } + doTestSignedValue( + jspb.BinaryDecoder.prototype.readFloat, + jspb.BinaryEncoder.prototype.writeFloat, + jspb.BinaryConstants.FLOAT32_EPS, + -jspb.BinaryConstants.FLOAT32_MAX, + jspb.BinaryConstants.FLOAT32_MAX, + truncate); + + doTestSignedValue( + jspb.BinaryDecoder.prototype.readDouble, + jspb.BinaryEncoder.prototype.writeDouble, + jspb.BinaryConstants.FLOAT64_EPS * 10, + -jspb.BinaryConstants.FLOAT64_MAX, + jspb.BinaryConstants.FLOAT64_MAX, + function(x) { return x; }); + }); +}); diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/proto_test.js b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/proto_test.js new file mode 100644 index 0000000000..14d0f42e95 --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/proto_test.js @@ -0,0 +1,628 @@ +// 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. + +// Test suite is written using Jasmine -- see http://jasmine.github.io/ + +goog.require('goog.crypt.base64'); +goog.require('goog.testing.asserts'); +goog.require('jspb.Message'); + +// CommonJS-LoadFromFile: ../testbinary_pb proto.jspb.test +goog.require('proto.jspb.test.ExtendsWithMessage'); +goog.require('proto.jspb.test.ForeignEnum'); +goog.require('proto.jspb.test.ForeignMessage'); +goog.require('proto.jspb.test.TestAllTypes'); +goog.require('proto.jspb.test.TestExtendable'); +goog.require('proto.jspb.test.extendOptionalBool'); +goog.require('proto.jspb.test.extendOptionalBytes'); +goog.require('proto.jspb.test.extendOptionalDouble'); +goog.require('proto.jspb.test.extendOptionalFixed32'); +goog.require('proto.jspb.test.extendOptionalFixed64'); +goog.require('proto.jspb.test.extendOptionalFloat'); +goog.require('proto.jspb.test.extendOptionalForeignEnum'); +goog.require('proto.jspb.test.extendOptionalInt32'); +goog.require('proto.jspb.test.extendOptionalInt64'); +goog.require('proto.jspb.test.extendOptionalSfixed32'); +goog.require('proto.jspb.test.extendOptionalSfixed64'); +goog.require('proto.jspb.test.extendOptionalSint32'); +goog.require('proto.jspb.test.extendOptionalSint64'); +goog.require('proto.jspb.test.extendOptionalString'); +goog.require('proto.jspb.test.extendOptionalUint32'); +goog.require('proto.jspb.test.extendOptionalUint64'); +goog.require('proto.jspb.test.extendPackedRepeatedBoolList'); +goog.require('proto.jspb.test.extendPackedRepeatedDoubleList'); +goog.require('proto.jspb.test.extendPackedRepeatedFixed32List'); +goog.require('proto.jspb.test.extendPackedRepeatedFixed64List'); +goog.require('proto.jspb.test.extendPackedRepeatedFloatList'); +goog.require('proto.jspb.test.extendPackedRepeatedForeignEnumList'); +goog.require('proto.jspb.test.extendPackedRepeatedInt32List'); +goog.require('proto.jspb.test.extendPackedRepeatedInt64List'); +goog.require('proto.jspb.test.extendPackedRepeatedSfixed32List'); +goog.require('proto.jspb.test.extendPackedRepeatedSfixed64List'); +goog.require('proto.jspb.test.extendPackedRepeatedSint32List'); +goog.require('proto.jspb.test.extendPackedRepeatedSint64List'); +goog.require('proto.jspb.test.extendPackedRepeatedUint32List'); +goog.require('proto.jspb.test.extendPackedRepeatedUint64List'); +goog.require('proto.jspb.test.extendRepeatedBoolList'); +goog.require('proto.jspb.test.extendRepeatedBytesList'); +goog.require('proto.jspb.test.extendRepeatedDoubleList'); +goog.require('proto.jspb.test.extendRepeatedFixed32List'); +goog.require('proto.jspb.test.extendRepeatedFixed64List'); +goog.require('proto.jspb.test.extendRepeatedFloatList'); +goog.require('proto.jspb.test.extendRepeatedForeignEnumList'); +goog.require('proto.jspb.test.extendRepeatedInt32List'); +goog.require('proto.jspb.test.extendRepeatedInt64List'); +goog.require('proto.jspb.test.extendRepeatedSfixed32List'); +goog.require('proto.jspb.test.extendRepeatedSfixed64List'); +goog.require('proto.jspb.test.extendRepeatedSint32List'); +goog.require('proto.jspb.test.extendRepeatedSint64List'); +goog.require('proto.jspb.test.extendRepeatedStringList'); +goog.require('proto.jspb.test.extendRepeatedUint32List'); +goog.require('proto.jspb.test.extendRepeatedUint64List'); + + +var suite = {}; + +var BYTES = new Uint8Array([1, 2, 8, 9]); + +var BYTES_B64 = goog.crypt.base64.encodeByteArray(BYTES); + + +/** + * Helper: fill all fields on a TestAllTypes message. + * @param {proto.jspb.test.TestAllTypes} msg + */ +function fillAllFields(msg) { + msg.setOptionalInt32(-42); + // can be exactly represented by JS number (64-bit double, i.e., 52-bit + // mantissa). + msg.setOptionalInt64(-0x7fffffff00000000); + msg.setOptionalUint32(0x80000000); + msg.setOptionalUint64(0xf000000000000000); + msg.setOptionalSint32(-100); + msg.setOptionalSint64(-0x8000000000000000); + msg.setOptionalFixed32(1234); + msg.setOptionalFixed64(0x1234567800000000); + msg.setOptionalSfixed32(-1234); + msg.setOptionalSfixed64(-0x1234567800000000); + msg.setOptionalFloat(1.5); + msg.setOptionalDouble(-1.5); + msg.setOptionalBool(true); + msg.setOptionalString('hello world'); + msg.setOptionalBytes(BYTES); + msg.setOptionalGroup(new proto.jspb.test.TestAllTypes.OptionalGroup()); + msg.getOptionalGroup().setA(100); + var submsg = new proto.jspb.test.ForeignMessage(); + submsg.setC(16); + msg.setOptionalForeignMessage(submsg); + msg.setOptionalForeignEnum(proto.jspb.test.ForeignEnum.FOREIGN_FOO); + msg.setOneofString('oneof'); + + + msg.setRepeatedInt32List([-42]); + msg.setRepeatedInt64List([-0x7fffffff00000000]); + msg.setRepeatedUint32List([0x80000000]); + msg.setRepeatedUint64List([0xf000000000000000]); + msg.setRepeatedSint32List([-100]); + msg.setRepeatedSint64List([-0x8000000000000000]); + msg.setRepeatedFixed32List([1234]); + msg.setRepeatedFixed64List([0x1234567800000000]); + msg.setRepeatedSfixed32List([-1234]); + msg.setRepeatedSfixed64List([-0x1234567800000000]); + msg.setRepeatedFloatList([1.5]); + msg.setRepeatedDoubleList([-1.5]); + msg.setRepeatedBoolList([true]); + msg.setRepeatedStringList(['hello world']); + msg.setRepeatedBytesList([BYTES, BYTES]); + msg.setRepeatedGroupList([new proto.jspb.test.TestAllTypes.RepeatedGroup()]); + msg.getRepeatedGroupList()[0].setA(100); + submsg = new proto.jspb.test.ForeignMessage(); + submsg.setC(1000); + msg.setRepeatedForeignMessageList([submsg]); + msg.setRepeatedForeignEnumList([proto.jspb.test.ForeignEnum.FOREIGN_FOO]); + + msg.setPackedRepeatedInt32List([-42]); + msg.setPackedRepeatedInt64List([-0x7fffffff00000000]); + msg.setPackedRepeatedUint32List([0x80000000]); + msg.setPackedRepeatedUint64List([0xf000000000000000]); + msg.setPackedRepeatedSint32List([-100]); + msg.setPackedRepeatedSint64List([-0x8000000000000000]); + msg.setPackedRepeatedFixed32List([1234]); + msg.setPackedRepeatedFixed64List([0x1234567800000000]); + msg.setPackedRepeatedSfixed32List([-1234]); + msg.setPackedRepeatedSfixed64List([-0x1234567800000000]); + msg.setPackedRepeatedFloatList([1.5]); + msg.setPackedRepeatedDoubleList([-1.5]); + msg.setPackedRepeatedBoolList([true]); + +} + + +/** + * Helper: compare a bytes field to an expected value + * @param {Uint8Array|string} arr + * @param {Uint8Array} expected + * @return {boolean} + */ +function bytesCompare(arr, expected) { + if (goog.isString(arr)) { + arr = goog.crypt.base64.decodeStringToUint8Array(arr); + } + if (arr.length != expected.length) { + return false; + } + for (var i = 0; i < arr.length; i++) { + if (arr[i] != expected[i]) { + return false; + } + } + return true; +} + + +/** + * Helper: verify contents of given TestAllTypes message as set by + * fillAllFields(). + * @param {proto.jspb.test.TestAllTypes} original + * @param {proto.jspb.test.TestAllTypes} copy + */ +function checkAllFields(original, copy) { + assertTrue(jspb.Message.equals(original, copy)); + + assertEquals(copy.getOptionalInt32(), -42); + assertEquals(copy.getOptionalInt64(), -0x7fffffff00000000); + assertEquals(copy.getOptionalUint32(), 0x80000000); + assertEquals(copy.getOptionalUint64(), 0xf000000000000000); + assertEquals(copy.getOptionalSint32(), -100); + assertEquals(copy.getOptionalSint64(), -0x8000000000000000); + assertEquals(copy.getOptionalFixed32(), 1234); + assertEquals(copy.getOptionalFixed64(), 0x1234567800000000); + assertEquals(copy.getOptionalSfixed32(), -1234); + assertEquals(copy.getOptionalSfixed64(), -0x1234567800000000); + assertEquals(copy.getOptionalFloat(), 1.5); + assertEquals(copy.getOptionalDouble(), -1.5); + assertEquals(copy.getOptionalBool(), true); + assertEquals(copy.getOptionalString(), 'hello world'); + assertEquals(true, bytesCompare(copy.getOptionalBytes(), BYTES)); + assertEquals(true, bytesCompare(copy.getOptionalBytes_asU8(), BYTES)); + assertEquals( + copy.getOptionalBytes_asB64(), goog.crypt.base64.encodeByteArray(BYTES)); + + assertEquals(copy.getOptionalGroup().getA(), 100); + assertEquals(copy.getOptionalForeignMessage().getC(), 16); + assertEquals(copy.getOptionalForeignEnum(), + proto.jspb.test.ForeignEnum.FOREIGN_FOO); + + + assertEquals(copy.getOneofString(), 'oneof'); + assertEquals(copy.getOneofFieldCase(), + proto.jspb.test.TestAllTypes.OneofFieldCase.ONEOF_STRING); + + assertElementsEquals(copy.getRepeatedInt32List(), [-42]); + assertElementsEquals(copy.getRepeatedInt64List(), [-0x7fffffff00000000]); + assertElementsEquals(copy.getRepeatedUint32List(), [0x80000000]); + assertElementsEquals(copy.getRepeatedUint64List(), [0xf000000000000000]); + assertElementsEquals(copy.getRepeatedSint32List(), [-100]); + assertElementsEquals(copy.getRepeatedSint64List(), [-0x8000000000000000]); + assertElementsEquals(copy.getRepeatedFixed32List(), [1234]); + assertElementsEquals(copy.getRepeatedFixed64List(), [0x1234567800000000]); + assertElementsEquals(copy.getRepeatedSfixed32List(), [-1234]); + assertElementsEquals(copy.getRepeatedSfixed64List(), [-0x1234567800000000]); + assertElementsEquals(copy.getRepeatedFloatList(), [1.5]); + assertElementsEquals(copy.getRepeatedDoubleList(), [-1.5]); + assertElementsEquals(copy.getRepeatedBoolList(), [true]); + assertElementsEquals(copy.getRepeatedStringList(), ['hello world']); + assertEquals(copy.getRepeatedBytesList().length, 2); + assertEquals(true, bytesCompare(copy.getRepeatedBytesList_asU8()[0], BYTES)); + assertEquals(true, bytesCompare(copy.getRepeatedBytesList()[0], BYTES)); + assertEquals(true, bytesCompare(copy.getRepeatedBytesList_asU8()[1], BYTES)); + assertEquals(copy.getRepeatedBytesList_asB64()[0], BYTES_B64); + assertEquals(copy.getRepeatedBytesList_asB64()[1], BYTES_B64); + assertEquals(copy.getRepeatedGroupList().length, 1); + assertEquals(copy.getRepeatedGroupList()[0].getA(), 100); + assertEquals(copy.getRepeatedForeignMessageList().length, 1); + assertEquals(copy.getRepeatedForeignMessageList()[0].getC(), 1000); + assertElementsEquals(copy.getRepeatedForeignEnumList(), + [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); + + assertElementsEquals(copy.getPackedRepeatedInt32List(), [-42]); + assertElementsEquals(copy.getPackedRepeatedInt64List(), + [-0x7fffffff00000000]); + assertElementsEquals(copy.getPackedRepeatedUint32List(), [0x80000000]); + assertElementsEquals(copy.getPackedRepeatedUint64List(), + [0xf000000000000000]); + assertElementsEquals(copy.getPackedRepeatedSint32List(), [-100]); + assertElementsEquals(copy.getPackedRepeatedSint64List(), + [-0x8000000000000000]); + assertElementsEquals(copy.getPackedRepeatedFixed32List(), [1234]); + assertElementsEquals(copy.getPackedRepeatedFixed64List(), + [0x1234567800000000]); + assertElementsEquals(copy.getPackedRepeatedSfixed32List(), [-1234]); + assertElementsEquals(copy.getPackedRepeatedSfixed64List(), + [-0x1234567800000000]); + assertElementsEquals(copy.getPackedRepeatedFloatList(), [1.5]); + assertElementsEquals(copy.getPackedRepeatedDoubleList(), [-1.5]); + +} + + +/** + * Helper: verify that all expected extensions are present. + * @param {!proto.jspb.test.TestExtendable} msg + */ +function checkExtensions(msg) { + assertEquals(-42, + msg.getExtension(proto.jspb.test.extendOptionalInt32)); + assertEquals(-0x7fffffff00000000, + msg.getExtension(proto.jspb.test.extendOptionalInt64)); + assertEquals(0x80000000, + msg.getExtension(proto.jspb.test.extendOptionalUint32)); + assertEquals(0xf000000000000000, + msg.getExtension(proto.jspb.test.extendOptionalUint64)); + assertEquals(-100, + msg.getExtension(proto.jspb.test.extendOptionalSint32)); + assertEquals(-0x8000000000000000, + msg.getExtension(proto.jspb.test.extendOptionalSint64)); + assertEquals(1234, + msg.getExtension(proto.jspb.test.extendOptionalFixed32)); + assertEquals(0x1234567800000000, + msg.getExtension(proto.jspb.test.extendOptionalFixed64)); + assertEquals(-1234, + msg.getExtension(proto.jspb.test.extendOptionalSfixed32)); + assertEquals(-0x1234567800000000, + msg.getExtension(proto.jspb.test.extendOptionalSfixed64)); + assertEquals(1.5, + msg.getExtension(proto.jspb.test.extendOptionalFloat)); + assertEquals(-1.5, + msg.getExtension(proto.jspb.test.extendOptionalDouble)); + assertEquals(true, + msg.getExtension(proto.jspb.test.extendOptionalBool)); + assertEquals('hello world', + msg.getExtension(proto.jspb.test.extendOptionalString)); + assertEquals( + true, bytesCompare( + msg.getExtension(proto.jspb.test.extendOptionalBytes), BYTES)); + assertEquals(16, + msg.getExtension( + proto.jspb.test.ExtendsWithMessage.optionalExtension).getFoo()); + + + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendRepeatedInt32List), + [-42]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendRepeatedInt64List), + [-0x7fffffff00000000]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendRepeatedUint32List), + [0x80000000]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendRepeatedUint64List), + [0xf000000000000000]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendRepeatedSint32List), + [-100]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendRepeatedSint64List), + [-0x8000000000000000]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendRepeatedFixed32List), + [1234]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendRepeatedFixed64List), + [0x1234567800000000]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendRepeatedSfixed32List), + [-1234]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendRepeatedSfixed64List), + [-0x1234567800000000]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendRepeatedFloatList), + [1.5]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendRepeatedDoubleList), + [-1.5]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendRepeatedBoolList), + [true]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendRepeatedStringList), + ['hello world']); + assertEquals( + true, + bytesCompare( + msg.getExtension(proto.jspb.test.extendRepeatedBytesList)[0], BYTES)); + assertEquals(1000, + msg.getExtension( + proto.jspb.test.ExtendsWithMessage.repeatedExtensionList)[0] + .getFoo()); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendRepeatedForeignEnumList), + [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); + + + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendPackedRepeatedInt32List), + [-42]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendPackedRepeatedInt64List), + [-0x7fffffff00000000]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendPackedRepeatedUint32List), + [0x80000000]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendPackedRepeatedUint64List), + [0xf000000000000000]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendPackedRepeatedSint32List), + [-100]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendPackedRepeatedSint64List), + [-0x8000000000000000]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendPackedRepeatedFixed32List), + [1234]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendPackedRepeatedFixed64List), + [0x1234567800000000]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendPackedRepeatedSfixed32List), + [-1234]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendPackedRepeatedSfixed64List), + [-0x1234567800000000]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendPackedRepeatedFloatList), + [1.5]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendPackedRepeatedDoubleList), + [-1.5]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendPackedRepeatedBoolList), + [true]); + assertElementsEquals( + msg.getExtension(proto.jspb.test.extendPackedRepeatedForeignEnumList), + [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); + +} + + +describe('protoBinaryTest', function() { + /** + * Tests a basic serialization-deserializaton round-trip with all supported + * field types (on the TestAllTypes message type). + */ + it('testRoundTrip', function() { + var msg = new proto.jspb.test.TestAllTypes(); + fillAllFields(msg); + var encoded = msg.serializeBinary(); + var decoded = proto.jspb.test.TestAllTypes.deserializeBinary(encoded); + checkAllFields(msg, decoded); + }); + + /** + * Test that base64 string and Uint8Array are interchangeable in bytes fields. + */ + it('testBytesFieldsGettersInterop', function() { + var msg = new proto.jspb.test.TestAllTypes(); + // Set from a base64 string and check all the getters work. + msg.setOptionalBytes(BYTES_B64); + assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES)); + assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES)); + assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); + + // Test binary serialize round trip doesn't break it. + msg = proto.jspb.test.TestAllTypes.deserializeBinary(msg.serializeBinary()); + assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES)); + assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES)); + assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); + + msg = new proto.jspb.test.TestAllTypes(); + // Set from a Uint8Array and check all the getters work. + msg.setOptionalBytes(BYTES); + assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES)); + assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES)); + assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); + + }); + + /** + * Test that bytes setters will receive result of any of the getters. + */ + it('testBytesFieldsSettersInterop', function() { + var msg = new proto.jspb.test.TestAllTypes(); + msg.setOptionalBytes(BYTES); + assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); + + msg.setOptionalBytes(msg.getOptionalBytes()); + assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); + msg.setOptionalBytes(msg.getOptionalBytes_asB64()); + assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); + msg.setOptionalBytes(msg.getOptionalBytes_asU8()); + assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); + }); + + /** + * Test that bytes setters will receive result of any of the getters. + */ + it('testRepeatedBytesGetters', function() { + var msg = new proto.jspb.test.TestAllTypes(); + + function assertGetters() { + assertTrue(goog.isString(msg.getRepeatedBytesList_asB64()[0])); + assertTrue(goog.isString(msg.getRepeatedBytesList_asB64()[1])); + assertTrue(msg.getRepeatedBytesList_asU8()[0] instanceof Uint8Array); + assertTrue(msg.getRepeatedBytesList_asU8()[1] instanceof Uint8Array); + + assertTrue(bytesCompare(msg.getRepeatedBytesList()[0], BYTES)); + assertTrue(bytesCompare(msg.getRepeatedBytesList()[1], BYTES)); + assertTrue(bytesCompare(msg.getRepeatedBytesList_asB64()[0], BYTES)); + assertTrue(bytesCompare(msg.getRepeatedBytesList_asB64()[1], BYTES)); + assertTrue(bytesCompare(msg.getRepeatedBytesList_asU8()[0], BYTES)); + assertTrue(bytesCompare(msg.getRepeatedBytesList_asU8()[1], BYTES)); + } + + msg.setRepeatedBytesList([BYTES, BYTES]); + assertGetters(); + + msg.setRepeatedBytesList([BYTES_B64, BYTES_B64]); + assertGetters(); + + msg.setRepeatedBytesList(null); + assertEquals(0, msg.getRepeatedBytesList().length); + assertEquals(0, msg.getRepeatedBytesList_asB64().length); + assertEquals(0, msg.getRepeatedBytesList_asU8().length); + }); + + /** + * Helper: fill all extension values. + * @param {proto.jspb.test.TestExtendable} msg + */ + function fillExtensions(msg) { + msg.setExtension( + proto.jspb.test.extendOptionalInt32, -42); + msg.setExtension( + proto.jspb.test.extendOptionalInt64, -0x7fffffff00000000); + msg.setExtension( + proto.jspb.test.extendOptionalUint32, 0x80000000); + msg.setExtension( + proto.jspb.test.extendOptionalUint64, 0xf000000000000000); + msg.setExtension( + proto.jspb.test.extendOptionalSint32, -100); + msg.setExtension( + proto.jspb.test.extendOptionalSint64, -0x8000000000000000); + msg.setExtension( + proto.jspb.test.extendOptionalFixed32, 1234); + msg.setExtension( + proto.jspb.test.extendOptionalFixed64, 0x1234567800000000); + msg.setExtension( + proto.jspb.test.extendOptionalSfixed32, -1234); + msg.setExtension( + proto.jspb.test.extendOptionalSfixed64, -0x1234567800000000); + msg.setExtension( + proto.jspb.test.extendOptionalFloat, 1.5); + msg.setExtension( + proto.jspb.test.extendOptionalDouble, -1.5); + msg.setExtension( + proto.jspb.test.extendOptionalBool, true); + msg.setExtension( + proto.jspb.test.extendOptionalString, 'hello world'); + msg.setExtension(proto.jspb.test.extendOptionalBytes, BYTES); + var submsg = new proto.jspb.test.ExtendsWithMessage(); + submsg.setFoo(16); + msg.setExtension( + proto.jspb.test.ExtendsWithMessage.optionalExtension, submsg); + msg.setExtension( + proto.jspb.test.extendOptionalForeignEnum, + proto.jspb.test.ForeignEnum.FOREIGN_FOO); + + + msg.setExtension( + proto.jspb.test.extendRepeatedInt32List, [-42]); + msg.setExtension( + proto.jspb.test.extendRepeatedInt64List, [-0x7fffffff00000000]); + msg.setExtension( + proto.jspb.test.extendRepeatedUint32List, [0x80000000]); + msg.setExtension( + proto.jspb.test.extendRepeatedUint64List, [0xf000000000000000]); + msg.setExtension( + proto.jspb.test.extendRepeatedSint32List, [-100]); + msg.setExtension( + proto.jspb.test.extendRepeatedSint64List, [-0x8000000000000000]); + msg.setExtension( + proto.jspb.test.extendRepeatedFixed32List, [1234]); + msg.setExtension( + proto.jspb.test.extendRepeatedFixed64List, [0x1234567800000000]); + msg.setExtension( + proto.jspb.test.extendRepeatedSfixed32List, [-1234]); + msg.setExtension( + proto.jspb.test.extendRepeatedSfixed64List, [-0x1234567800000000]); + msg.setExtension( + proto.jspb.test.extendRepeatedFloatList, [1.5]); + msg.setExtension( + proto.jspb.test.extendRepeatedDoubleList, [-1.5]); + msg.setExtension( + proto.jspb.test.extendRepeatedBoolList, [true]); + msg.setExtension( + proto.jspb.test.extendRepeatedStringList, ['hello world']); + msg.setExtension(proto.jspb.test.extendRepeatedBytesList, [BYTES]); + submsg = new proto.jspb.test.ExtendsWithMessage(); + submsg.setFoo(1000); + msg.setExtension( + proto.jspb.test.ExtendsWithMessage.repeatedExtensionList, [submsg]); + msg.setExtension(proto.jspb.test.extendRepeatedForeignEnumList, + [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); + + + msg.setExtension( + proto.jspb.test.extendPackedRepeatedInt32List, [-42]); + msg.setExtension( + proto.jspb.test.extendPackedRepeatedInt64List, [-0x7fffffff00000000]); + msg.setExtension( + proto.jspb.test.extendPackedRepeatedUint32List, [0x80000000]); + msg.setExtension( + proto.jspb.test.extendPackedRepeatedUint64List, [0xf000000000000000]); + msg.setExtension( + proto.jspb.test.extendPackedRepeatedSint32List, [-100]); + msg.setExtension( + proto.jspb.test.extendPackedRepeatedSint64List, [-0x8000000000000000]); + msg.setExtension( + proto.jspb.test.extendPackedRepeatedFixed32List, [1234]); + msg.setExtension( + proto.jspb.test.extendPackedRepeatedFixed64List, [0x1234567800000000]); + msg.setExtension( + proto.jspb.test.extendPackedRepeatedSfixed32List, [-1234]); + msg.setExtension( + proto.jspb.test.extendPackedRepeatedSfixed64List, + [-0x1234567800000000]); + msg.setExtension( + proto.jspb.test.extendPackedRepeatedFloatList, [1.5]); + msg.setExtension( + proto.jspb.test.extendPackedRepeatedDoubleList, [-1.5]); + msg.setExtension( + proto.jspb.test.extendPackedRepeatedBoolList, [true]); + msg.setExtension(proto.jspb.test.extendPackedRepeatedForeignEnumList, + [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); + + } + + + /** + * Tests extension serialization and deserialization. + */ + it('testExtensions', function() { + var msg = new proto.jspb.test.TestExtendable(); + fillExtensions(msg); + var encoded = msg.serializeBinary(); + var decoded = proto.jspb.test.TestExtendable.deserializeBinary(encoded); + checkExtensions(decoded); + }); +}); diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/reader_test.js b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/reader_test.js new file mode 100644 index 0000000000..957113859e --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/reader_test.js @@ -0,0 +1,922 @@ +// 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. + +/** + * @fileoverview Test cases for jspb's binary protocol buffer reader. + * + * There are two particular magic numbers that need to be pointed out - + * 2^64-1025 is the largest number representable as both a double and an + * unsigned 64-bit integer, and 2^63-513 is the largest number representable as + * both a double and a signed 64-bit integer. + * + * Test suite is written using Jasmine -- see http://jasmine.github.io/ + * + * @author aappleby@google.com (Austin Appleby) + */ + +goog.require('goog.testing.asserts'); +goog.require('jspb.BinaryConstants'); +goog.require('jspb.BinaryDecoder'); +goog.require('jspb.BinaryReader'); +goog.require('jspb.BinaryWriter'); + + + +describe('binaryReaderTest', function() { + /** + * Tests the reader instance cache. + */ + it('testInstanceCaches', /** @suppress {visibility} */ function() { + var writer = new jspb.BinaryWriter(); + var dummyMessage = /** @type {!jspb.BinaryMessage} */({}); + writer.writeMessage(1, dummyMessage, goog.nullFunction); + writer.writeMessage(2, dummyMessage, goog.nullFunction); + + var buffer = writer.getResultBuffer(); + + // Empty the instance caches. + jspb.BinaryReader.instanceCache_ = []; + + // Allocating and then freeing three decoders should leave us with three in + // the cache. + + var decoder1 = jspb.BinaryDecoder.alloc(); + var decoder2 = jspb.BinaryDecoder.alloc(); + var decoder3 = jspb.BinaryDecoder.alloc(); + decoder1.free(); + decoder2.free(); + decoder3.free(); + + assertEquals(3, jspb.BinaryDecoder.instanceCache_.length); + assertEquals(0, jspb.BinaryReader.instanceCache_.length); + + // Allocating and then freeing a reader should remove one decoder from its + // cache, but it should stay stuck to the reader afterwards since we can't + // have a reader without a decoder. + jspb.BinaryReader.alloc().free(); + + assertEquals(2, jspb.BinaryDecoder.instanceCache_.length); + assertEquals(1, jspb.BinaryReader.instanceCache_.length); + + // Allocating a reader should remove a reader from the cache. + var reader = jspb.BinaryReader.alloc(buffer); + + assertEquals(2, jspb.BinaryDecoder.instanceCache_.length); + assertEquals(0, jspb.BinaryReader.instanceCache_.length); + + // Processing the message reuses the current reader. + reader.nextField(); + assertEquals(1, reader.getFieldNumber()); + reader.readMessage(dummyMessage, function() { + assertEquals(0, jspb.BinaryReader.instanceCache_.length); + }); + + reader.nextField(); + assertEquals(2, reader.getFieldNumber()); + reader.readMessage(dummyMessage, function() { + assertEquals(0, jspb.BinaryReader.instanceCache_.length); + }); + + assertEquals(false, reader.nextField()); + + assertEquals(2, jspb.BinaryDecoder.instanceCache_.length); + assertEquals(0, jspb.BinaryReader.instanceCache_.length); + + // Freeing the reader should put it back into the cache. + reader.free(); + + assertEquals(2, jspb.BinaryDecoder.instanceCache_.length); + assertEquals(1, jspb.BinaryReader.instanceCache_.length); + }); + + + /** + * @param {number} x + * @return {number} + */ + function truncate(x) { + var temp = new Float32Array(1); + temp[0] = x; + return temp[0]; + } + + + /** + * Verifies that misuse of the reader class triggers assertions. + */ + it('testReadErrors', /** @suppress {checkTypes|visibility} */ function() { + // Calling readMessage on a non-delimited field should trigger an + // assertion. + var reader = jspb.BinaryReader.alloc([8, 1]); + var dummyMessage = /** @type {!jspb.BinaryMessage} */({}); + reader.nextField(); + assertThrows(function() { + reader.readMessage(dummyMessage, goog.nullFunction); + }); + + // Reading past the end of the stream should trigger an assertion. + reader = jspb.BinaryReader.alloc([9, 1]); + reader.nextField(); + assertThrows(function() {reader.readFixed64()}); + + // Reading past the end of a submessage should trigger an assertion. + reader = jspb.BinaryReader.alloc([10, 4, 13, 1, 1, 1]); + reader.nextField(); + reader.readMessage(dummyMessage, function() { + reader.nextField(); + assertThrows(function() {reader.readFixed32()}); + }); + + // Skipping an invalid field should trigger an assertion. + reader = jspb.BinaryReader.alloc([12, 1]); + reader.nextWireType_ = 1000; + assertThrows(function() {reader.skipField()}); + + // Reading fields with the wrong wire type should assert. + reader = jspb.BinaryReader.alloc([9, 0, 0, 0, 0, 0, 0, 0, 0]); + reader.nextField(); + assertThrows(function() {reader.readInt32()}); + assertThrows(function() {reader.readInt32String()}); + assertThrows(function() {reader.readInt64()}); + assertThrows(function() {reader.readInt64String()}); + assertThrows(function() {reader.readUint32()}); + assertThrows(function() {reader.readUint32String()}); + assertThrows(function() {reader.readUint64()}); + assertThrows(function() {reader.readUint64String()}); + assertThrows(function() {reader.readSint32()}); + assertThrows(function() {reader.readBool()}); + assertThrows(function() {reader.readEnum()}); + + reader = jspb.BinaryReader.alloc([8, 1]); + reader.nextField(); + assertThrows(function() {reader.readFixed32()}); + assertThrows(function() {reader.readFixed64()}); + assertThrows(function() {reader.readSfixed32()}); + assertThrows(function() {reader.readSfixed64()}); + assertThrows(function() {reader.readFloat()}); + assertThrows(function() {reader.readDouble()}); + + assertThrows(function() {reader.readString()}); + assertThrows(function() {reader.readBytes()}); + }); + + + /** + * Tests encoding and decoding of unsigned field types. + * @param {Function} readField + * @param {Function} writeField + * @param {number} epsilon + * @param {number} upperLimit + * @param {Function} filter + * @private + * @suppress {missingProperties} + */ + var doTestUnsignedField_ = function(readField, + writeField, epsilon, upperLimit, filter) { + assertNotNull(readField); + assertNotNull(writeField); + + var writer = new jspb.BinaryWriter(); + + // Encode zero and limits. + writeField.call(writer, 1, filter(0)); + writeField.call(writer, 2, filter(epsilon)); + writeField.call(writer, 3, filter(upperLimit)); + + // Encode positive values. + for (var cursor = epsilon; cursor < upperLimit; cursor *= 1.1) { + writeField.call(writer, 4, filter(cursor)); + } + + var reader = jspb.BinaryReader.alloc(writer.getResultBuffer()); + + // Check zero and limits. + reader.nextField(); + assertEquals(1, reader.getFieldNumber()); + assertEquals(filter(0), readField.call(reader)); + + reader.nextField(); + assertEquals(2, reader.getFieldNumber()); + assertEquals(filter(epsilon), readField.call(reader)); + + reader.nextField(); + assertEquals(3, reader.getFieldNumber()); + assertEquals(filter(upperLimit), readField.call(reader)); + + // Check positive values. + for (var cursor = epsilon; cursor < upperLimit; cursor *= 1.1) { + reader.nextField(); + if (4 != reader.getFieldNumber()) throw 'fail!'; + if (filter(cursor) != readField.call(reader)) throw 'fail!'; + } + }; + + + /** + * Tests encoding and decoding of signed field types. + * @param {Function} readField + * @param {Function} writeField + * @param {number} epsilon + * @param {number} lowerLimit + * @param {number} upperLimit + * @param {Function} filter + * @private + * @suppress {missingProperties} + */ + var doTestSignedField_ = function(readField, + writeField, epsilon, lowerLimit, upperLimit, filter) { + var writer = new jspb.BinaryWriter(); + + // Encode zero and limits. + writeField.call(writer, 1, filter(lowerLimit)); + writeField.call(writer, 2, filter(-epsilon)); + writeField.call(writer, 3, filter(0)); + writeField.call(writer, 4, filter(epsilon)); + writeField.call(writer, 5, filter(upperLimit)); + + var inputValues = []; + + // Encode negative values. + for (var cursor = lowerLimit; cursor < -epsilon; cursor /= 1.1) { + var val = filter(cursor); + writeField.call(writer, 6, val); + inputValues.push({ + fieldNumber: 6, + value: val + }); + } + + // Encode positive values. + for (var cursor = epsilon; cursor < upperLimit; cursor *= 1.1) { + var val = filter(cursor); + writeField.call(writer, 7, val); + inputValues.push({ + fieldNumber: 7, + value: val + }); + } + + var reader = jspb.BinaryReader.alloc(writer.getResultBuffer()); + + // Check zero and limits. + reader.nextField(); + assertEquals(1, reader.getFieldNumber()); + assertEquals(filter(lowerLimit), readField.call(reader)); + + reader.nextField(); + assertEquals(2, reader.getFieldNumber()); + assertEquals(filter(-epsilon), readField.call(reader)); + + reader.nextField(); + assertEquals(3, reader.getFieldNumber()); + assertEquals(filter(0), readField.call(reader)); + + reader.nextField(); + assertEquals(4, reader.getFieldNumber()); + assertEquals(filter(epsilon), readField.call(reader)); + + reader.nextField(); + assertEquals(5, reader.getFieldNumber()); + assertEquals(filter(upperLimit), readField.call(reader)); + + for (var i = 0; i < inputValues.length; i++) { + var expected = inputValues[i]; + reader.nextField(); + assertEquals(expected.fieldNumber, reader.getFieldNumber()); + assertEquals(expected.value, readField.call(reader)); + } + }; + + + /** + * Tests fields that use varint encoding. + */ + it('testVarintFields', function() { + assertNotUndefined(jspb.BinaryReader.prototype.readUint32); + assertNotUndefined(jspb.BinaryWriter.prototype.writeUint32); + assertNotUndefined(jspb.BinaryReader.prototype.readUint64); + assertNotUndefined(jspb.BinaryWriter.prototype.writeUint64); + assertNotUndefined(jspb.BinaryReader.prototype.readBool); + assertNotUndefined(jspb.BinaryWriter.prototype.writeBool); + doTestUnsignedField_( + jspb.BinaryReader.prototype.readUint32, + jspb.BinaryWriter.prototype.writeUint32, + 1, Math.pow(2, 32) - 1, Math.round); + + doTestUnsignedField_( + jspb.BinaryReader.prototype.readUint64, + jspb.BinaryWriter.prototype.writeUint64, + 1, Math.pow(2, 64) - 1025, Math.round); + + doTestSignedField_( + jspb.BinaryReader.prototype.readInt32, + jspb.BinaryWriter.prototype.writeInt32, + 1, -Math.pow(2, 31), Math.pow(2, 31) - 1, Math.round); + + doTestSignedField_( + jspb.BinaryReader.prototype.readInt64, + jspb.BinaryWriter.prototype.writeInt64, + 1, -Math.pow(2, 63), Math.pow(2, 63) - 513, Math.round); + + doTestSignedField_( + jspb.BinaryReader.prototype.readEnum, + jspb.BinaryWriter.prototype.writeEnum, + 1, -Math.pow(2, 31), Math.pow(2, 31) - 1, Math.round); + + doTestUnsignedField_( + jspb.BinaryReader.prototype.readBool, + jspb.BinaryWriter.prototype.writeBool, + 1, 1, function(x) { return !!x; }); + }); + + + /** + * Tests reading a field from hexadecimal string (format: '08 BE EF'). + * @param {Function} readField + * @param {number} expected + * @param {string} hexString + */ + function doTestHexStringVarint_(readField, expected, hexString) { + var bytesCount = (hexString.length + 1) / 3; + var bytes = new Uint8Array(bytesCount); + for (var i = 0; i < bytesCount; i++) { + bytes[i] = parseInt(hexString.substring(i * 3, i * 3 + 2), 16); + } + var reader = jspb.BinaryReader.alloc(bytes); + reader.nextField(); + assertEquals(expected, readField.call(reader)); + } + + + /** + * Tests non-canonical redundant varint decoding. + */ + it('testRedundantVarintFields', function() { + assertNotNull(jspb.BinaryReader.prototype.readUint32); + assertNotNull(jspb.BinaryReader.prototype.readUint64); + assertNotNull(jspb.BinaryReader.prototype.readSint32); + assertNotNull(jspb.BinaryReader.prototype.readSint64); + + // uint32 and sint32 take no more than 5 bytes + // 08 - field prefix (type = 0 means varint) + doTestHexStringVarint_( + jspb.BinaryReader.prototype.readUint32, + 12, '08 8C 80 80 80 00'); + + // 11 stands for -6 in zigzag encoding + doTestHexStringVarint_( + jspb.BinaryReader.prototype.readSint32, + -6, '08 8B 80 80 80 00'); + + // uint64 and sint64 take no more than 10 bytes + // 08 - field prefix (type = 0 means varint) + doTestHexStringVarint_( + jspb.BinaryReader.prototype.readUint64, + 12, '08 8C 80 80 80 80 80 80 80 80 00'); + + // 11 stands for -6 in zigzag encoding + doTestHexStringVarint_( + jspb.BinaryReader.prototype.readSint64, + -6, '08 8B 80 80 80 80 80 80 80 80 00'); + }); + + + /** + * Tests 64-bit fields that are handled as strings. + */ + it('testStringInt64Fields', function() { + var writer = new jspb.BinaryWriter(); + + var testSignedData = [ + '2730538252207801776', + '-2688470994844604560', + '3398529779486536359', + '3568577411627971000', + '272477188847484900', + '-6649058714086158188', + '-7695254765712060806', + '-4525541438037104029', + '-4993706538836508568', + '4990160321893729138' + ]; + var testUnsignedData = [ + '7822732630241694882', + '6753602971916687352', + '2399935075244442116', + '8724292567325338867', + '16948784802625696584', + '4136275908516066934', + '3575388346793700364', + '5167142028379259461', + '1557573948689737699', + '17100725280812548567' + ]; + + for (var i = 0; i < testSignedData.length; i++) { + writer.writeInt64String(2 * i + 1, testSignedData[i]); + writer.writeUint64String(2 * i + 2, testUnsignedData[i]); + } + + var reader = jspb.BinaryReader.alloc(writer.getResultBuffer()); + + for (var i = 0; i < testSignedData.length; i++) { + reader.nextField(); + assertEquals(2 * i + 1, reader.getFieldNumber()); + assertEquals(testSignedData[i], reader.readInt64String()); + reader.nextField(); + assertEquals(2 * i + 2, reader.getFieldNumber()); + assertEquals(testUnsignedData[i], reader.readUint64String()); + } + }); + + + /** + * Tests fields that use zigzag encoding. + */ + it('testZigzagFields', function() { + doTestSignedField_( + jspb.BinaryReader.prototype.readSint32, + jspb.BinaryWriter.prototype.writeSint32, + 1, -Math.pow(2, 31), Math.pow(2, 31) - 1, Math.round); + + doTestSignedField_( + jspb.BinaryReader.prototype.readSint64, + jspb.BinaryWriter.prototype.writeSint64, + 1, -Math.pow(2, 63), Math.pow(2, 63) - 513, Math.round); + }); + + + /** + * Tests fields that use fixed-length encoding. + */ + it('testFixedFields', function() { + doTestUnsignedField_( + jspb.BinaryReader.prototype.readFixed32, + jspb.BinaryWriter.prototype.writeFixed32, + 1, Math.pow(2, 32) - 1, Math.round); + + doTestUnsignedField_( + jspb.BinaryReader.prototype.readFixed64, + jspb.BinaryWriter.prototype.writeFixed64, + 1, Math.pow(2, 64) - 1025, Math.round); + + doTestSignedField_( + jspb.BinaryReader.prototype.readSfixed32, + jspb.BinaryWriter.prototype.writeSfixed32, + 1, -Math.pow(2, 31), Math.pow(2, 31) - 1, Math.round); + + doTestSignedField_( + jspb.BinaryReader.prototype.readSfixed64, + jspb.BinaryWriter.prototype.writeSfixed64, + 1, -Math.pow(2, 63), Math.pow(2, 63) - 513, Math.round); + }); + + + /** + * Tests floating point fields. + */ + it('testFloatFields', function() { + doTestSignedField_( + jspb.BinaryReader.prototype.readFloat, + jspb.BinaryWriter.prototype.writeFloat, + jspb.BinaryConstants.FLOAT32_MIN, + -jspb.BinaryConstants.FLOAT32_MAX, + jspb.BinaryConstants.FLOAT32_MAX, + truncate); + + doTestSignedField_( + jspb.BinaryReader.prototype.readDouble, + jspb.BinaryWriter.prototype.writeDouble, + jspb.BinaryConstants.FLOAT64_EPS * 10, + -jspb.BinaryConstants.FLOAT64_MIN, + jspb.BinaryConstants.FLOAT64_MIN, + function(x) { return x; }); + }); + + + /** + * Tests length-delimited string fields. + */ + it('testStringFields', function() { + var s1 = 'The quick brown fox jumps over the lazy dog.'; + var s2 = '人人生而自由,在尊嚴和權利上一律平等。'; + + var writer = new jspb.BinaryWriter(); + + writer.writeString(1, s1); + writer.writeString(2, s2); + + var reader = jspb.BinaryReader.alloc(writer.getResultBuffer()); + + reader.nextField(); + assertEquals(1, reader.getFieldNumber()); + assertEquals(s1, reader.readString()); + + reader.nextField(); + assertEquals(2, reader.getFieldNumber()); + assertEquals(s2, reader.readString()); + }); + + + /** + * Tests length-delimited byte fields. + */ + it('testByteFields', function() { + var message = []; + var lowerLimit = 1; + var upperLimit = 256; + var scale = 1.1; + + var writer = new jspb.BinaryWriter(); + + for (var cursor = lowerLimit; cursor < upperLimit; cursor *= 1.1) { + var len = Math.round(cursor); + var bytes = []; + for (var i = 0; i < len; i++) bytes.push(i % 256); + + writer.writeBytes(len, bytes); + } + + var reader = jspb.BinaryReader.alloc(writer.getResultBuffer()); + + for (var cursor = lowerLimit; reader.nextField(); cursor *= 1.1) { + var len = Math.round(cursor); + if (len != reader.getFieldNumber()) throw 'fail!'; + + var bytes = reader.readBytes(); + if (len != bytes.length) throw 'fail!'; + for (var i = 0; i < bytes.length; i++) { + if (i % 256 != bytes[i]) throw 'fail!'; + } + } + }); + + + /** + * Tests nested messages. + */ + it('testNesting', function() { + var writer = new jspb.BinaryWriter(); + var dummyMessage = /** @type {!jspb.BinaryMessage} */({}); + + writer.writeInt32(1, 100); + + // Add one message with 3 int fields. + writer.writeMessage(2, dummyMessage, function() { + writer.writeInt32(3, 300); + writer.writeInt32(4, 400); + writer.writeInt32(5, 500); + }); + + // Add one empty message. + writer.writeMessage(6, dummyMessage, goog.nullFunction); + + writer.writeInt32(7, 700); + + var reader = jspb.BinaryReader.alloc(writer.getResultBuffer()); + + // Validate outermost message. + + reader.nextField(); + assertEquals(1, reader.getFieldNumber()); + assertEquals(100, reader.readInt32()); + + reader.nextField(); + assertEquals(2, reader.getFieldNumber()); + reader.readMessage(dummyMessage, function() { + // Validate embedded message 1. + reader.nextField(); + assertEquals(3, reader.getFieldNumber()); + assertEquals(300, reader.readInt32()); + + reader.nextField(); + assertEquals(4, reader.getFieldNumber()); + assertEquals(400, reader.readInt32()); + + reader.nextField(); + assertEquals(5, reader.getFieldNumber()); + assertEquals(500, reader.readInt32()); + + assertEquals(false, reader.nextField()); + }); + + reader.nextField(); + assertEquals(6, reader.getFieldNumber()); + reader.readMessage(dummyMessage, function() { + // Validate embedded message 2. + + assertEquals(false, reader.nextField()); + }); + + reader.nextField(); + assertEquals(7, reader.getFieldNumber()); + assertEquals(700, reader.readInt32()); + + assertEquals(false, reader.nextField()); + }); + + /** + * Tests skipping fields of each type by interleaving them with sentinel + * values and skipping everything that's not a sentinel. + */ + it('testSkipField', function() { + var writer = new jspb.BinaryWriter(); + + var sentinel = 123456789; + + // Write varint fields of different sizes. + writer.writeInt32(1, sentinel); + writer.writeInt32(1, 1); + writer.writeInt32(1, 1000); + writer.writeInt32(1, 1000000); + writer.writeInt32(1, 1000000000); + + // Write fixed 64-bit encoded fields. + writer.writeInt32(2, sentinel); + writer.writeDouble(2, 1); + writer.writeFixed64(2, 1); + writer.writeSfixed64(2, 1); + + // Write fixed 32-bit encoded fields. + writer.writeInt32(3, sentinel); + writer.writeFloat(3, 1); + writer.writeFixed32(3, 1); + writer.writeSfixed32(3, 1); + + // Write delimited fields. + writer.writeInt32(4, sentinel); + writer.writeBytes(4, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); + writer.writeString(4, 'The quick brown fox jumps over the lazy dog'); + + // Write a group with a nested group inside. + writer.writeInt32(5, sentinel); + var dummyMessage = /** @type {!jspb.BinaryMessage} */({}); + writer.writeGroup(5, dummyMessage, function() { + writer.writeInt64(42, 42); + writer.writeGroup(6, dummyMessage, function() { + writer.writeInt64(84, 42); + }); + }); + + // Write final sentinel. + writer.writeInt32(6, sentinel); + + var reader = jspb.BinaryReader.alloc(writer.getResultBuffer()); + + function skip(field, count) { + for (var i = 0; i < count; i++) { + reader.nextField(); + if (field != reader.getFieldNumber()) throw 'fail!'; + reader.skipField(); + } + } + + reader.nextField(); + assertEquals(1, reader.getFieldNumber()); + assertEquals(sentinel, reader.readInt32()); + skip(1, 4); + + reader.nextField(); + assertEquals(2, reader.getFieldNumber()); + assertEquals(sentinel, reader.readInt32()); + skip(2, 3); + + reader.nextField(); + assertEquals(3, reader.getFieldNumber()); + assertEquals(sentinel, reader.readInt32()); + skip(3, 3); + + reader.nextField(); + assertEquals(4, reader.getFieldNumber()); + assertEquals(sentinel, reader.readInt32()); + skip(4, 2); + + reader.nextField(); + assertEquals(5, reader.getFieldNumber()); + assertEquals(sentinel, reader.readInt32()); + skip(5, 1); + + reader.nextField(); + assertEquals(6, reader.getFieldNumber()); + assertEquals(sentinel, reader.readInt32()); + }); + + + /** + * Tests packed fields. + */ + it('testPackedFields', function() { + var writer = new jspb.BinaryWriter(); + + var sentinel = 123456789; + + var unsignedData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + var signedData = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]; + var floatData = [1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10]; + var doubleData = [1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10]; + var boolData = [true, false, true, true, false, false, true, false]; + + for (var i = 0; i < floatData.length; i++) { + floatData[i] = truncate(floatData[i]); + } + + writer.writeInt32(1, sentinel); + + writer.writePackedInt32(2, signedData); + writer.writePackedInt64(2, signedData); + writer.writePackedUint32(2, unsignedData); + writer.writePackedUint64(2, unsignedData); + writer.writePackedSint32(2, signedData); + writer.writePackedSint64(2, signedData); + writer.writePackedFixed32(2, unsignedData); + writer.writePackedFixed64(2, unsignedData); + writer.writePackedSfixed32(2, signedData); + writer.writePackedSfixed64(2, signedData); + writer.writePackedFloat(2, floatData); + writer.writePackedDouble(2, doubleData); + writer.writePackedBool(2, boolData); + writer.writePackedEnum(2, unsignedData); + + writer.writeInt32(3, sentinel); + + var reader = jspb.BinaryReader.alloc(writer.getResultBuffer()); + + reader.nextField(); + assertEquals(sentinel, reader.readInt32()); + + reader.nextField(); + assertElementsEquals(reader.readPackedInt32(), signedData); + + reader.nextField(); + assertElementsEquals(reader.readPackedInt64(), signedData); + + reader.nextField(); + assertElementsEquals(reader.readPackedUint32(), unsignedData); + + reader.nextField(); + assertElementsEquals(reader.readPackedUint64(), unsignedData); + + reader.nextField(); + assertElementsEquals(reader.readPackedSint32(), signedData); + + reader.nextField(); + assertElementsEquals(reader.readPackedSint64(), signedData); + + reader.nextField(); + assertElementsEquals(reader.readPackedFixed32(), unsignedData); + + reader.nextField(); + assertElementsEquals(reader.readPackedFixed64(), unsignedData); + + reader.nextField(); + assertElementsEquals(reader.readPackedSfixed32(), signedData); + + reader.nextField(); + assertElementsEquals(reader.readPackedSfixed64(), signedData); + + reader.nextField(); + assertElementsEquals(reader.readPackedFloat(), floatData); + + reader.nextField(); + assertElementsEquals(reader.readPackedDouble(), doubleData); + + reader.nextField(); + assertElementsEquals(reader.readPackedBool(), boolData); + + reader.nextField(); + assertElementsEquals(reader.readPackedEnum(), unsignedData); + + reader.nextField(); + assertEquals(sentinel, reader.readInt32()); + }); + + + /** + * Byte blobs inside nested messages should always have their byte offset set + * relative to the start of the outermost blob, not the start of their parent + * blob. + */ + it('testNestedBlobs', function() { + // Create a proto consisting of two nested messages, with the inner one + // containing a blob of bytes. + + var fieldTag = (1 << 3) | jspb.BinaryConstants.WireType.DELIMITED; + var blob = [1, 2, 3, 4, 5]; + var writer = new jspb.BinaryWriter(); + var dummyMessage = /** @type {!jspb.BinaryMessage} */({}); + + writer.writeMessage(1, dummyMessage, function() { + writer.writeMessage(1, dummyMessage, function() { + writer.writeBytes(1, blob); + }); + }); + + // Peel off the outer two message layers. Each layer should have two bytes + // of overhead, one for the field tag and one for the length of the inner + // blob. + + var decoder1 = new jspb.BinaryDecoder(writer.getResultBuffer()); + assertEquals(fieldTag, decoder1.readUnsignedVarint32()); + assertEquals(blob.length + 4, decoder1.readUnsignedVarint32()); + + var decoder2 = new jspb.BinaryDecoder(decoder1.readBytes(blob.length + 4)); + assertEquals(fieldTag, decoder2.readUnsignedVarint32()); + assertEquals(blob.length + 2, decoder2.readUnsignedVarint32()); + + assertEquals(fieldTag, decoder2.readUnsignedVarint32()); + assertEquals(blob.length, decoder2.readUnsignedVarint32()); + var bytes = decoder2.readBytes(blob.length); + + assertElementsEquals(bytes, blob); + }); + + + /** + * Tests read callbacks. + */ + it('testReadCallbacks', function() { + var writer = new jspb.BinaryWriter(); + var dummyMessage = /** @type {!jspb.BinaryMessage} */({}); + + // Add an int, a submessage, and another int. + writer.writeInt32(1, 100); + + writer.writeMessage(2, dummyMessage, function() { + writer.writeInt32(3, 300); + writer.writeInt32(4, 400); + writer.writeInt32(5, 500); + }); + + writer.writeInt32(7, 700); + + // Create the reader and register a custom read callback. + var reader = jspb.BinaryReader.alloc(writer.getResultBuffer()); + + /** + * @param {!jspb.BinaryReader} reader + * @return {*} + */ + function readCallback(reader) { + reader.nextField(); + assertEquals(3, reader.getFieldNumber()); + assertEquals(300, reader.readInt32()); + + reader.nextField(); + assertEquals(4, reader.getFieldNumber()); + assertEquals(400, reader.readInt32()); + + reader.nextField(); + assertEquals(5, reader.getFieldNumber()); + assertEquals(500, reader.readInt32()); + + assertEquals(false, reader.nextField()); + }; + + reader.registerReadCallback('readCallback', readCallback); + + // Read the container message. + reader.nextField(); + assertEquals(1, reader.getFieldNumber()); + assertEquals(100, reader.readInt32()); + + reader.nextField(); + assertEquals(2, reader.getFieldNumber()); + reader.readMessage(dummyMessage, function() { + // Decode the embedded message using the registered callback. + reader.runReadCallback('readCallback'); + }); + + reader.nextField(); + assertEquals(7, reader.getFieldNumber()); + assertEquals(700, reader.readInt32()); + + assertEquals(false, reader.nextField()); + }); +}); diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/utils_test.js b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/utils_test.js new file mode 100644 index 0000000000..d27e5ea2c6 --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/utils_test.js @@ -0,0 +1,668 @@ +// 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. + +/** + * @fileoverview Test cases for jspb's helper functions. + * + * Test suite is written using Jasmine -- see http://jasmine.github.io/ + * + * @author aappleby@google.com (Austin Appleby) + */ + +goog.require('goog.crypt.base64'); +goog.require('goog.testing.asserts'); +goog.require('jspb.BinaryConstants'); +goog.require('jspb.BinaryWriter'); +goog.require('jspb.utils'); + + +/** + * @param {number} x + * @return {number} + */ +function truncate(x) { + var temp = new Float32Array(1); + temp[0] = x; + return temp[0]; +} + + +/** + * Converts an 64-bit integer in split representation to a 64-bit hash string + * (8 bits encoded per character). + * @param {number} bitsLow The low 32 bits of the split 64-bit integer. + * @param {number} bitsHigh The high 32 bits of the split 64-bit integer. + * @return {string} The encoded hash string, 8 bits per character. + */ +function toHashString(bitsLow, bitsHigh) { + return String.fromCharCode((bitsLow >>> 0) & 0xFF, + (bitsLow >>> 8) & 0xFF, + (bitsLow >>> 16) & 0xFF, + (bitsLow >>> 24) & 0xFF, + (bitsHigh >>> 0) & 0xFF, + (bitsHigh >>> 8) & 0xFF, + (bitsHigh >>> 16) & 0xFF, + (bitsHigh >>> 24) & 0xFF); +} + + +describe('binaryUtilsTest', function() { + /** + * Tests lossless binary-to-decimal conversion. + */ + it('testDecimalConversion', function() { + // Check some magic numbers. + var result = + jspb.utils.joinUnsignedDecimalString(0x89e80001, 0x8ac72304); + assertEquals('10000000000000000001', result); + + result = jspb.utils.joinUnsignedDecimalString(0xacd05f15, 0x1b69b4b); + assertEquals('123456789123456789', result); + + result = jspb.utils.joinUnsignedDecimalString(0xeb1f0ad2, 0xab54a98c); + assertEquals('12345678901234567890', result); + + result = jspb.utils.joinUnsignedDecimalString(0xe3b70cb1, 0x891087b8); + assertEquals('9876543210987654321', result); + + // Check limits. + result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x00000000); + assertEquals('0', result); + + result = jspb.utils.joinUnsignedDecimalString(0xFFFFFFFF, 0xFFFFFFFF); + assertEquals('18446744073709551615', result); + + // Check each bit of the low dword. + for (var i = 0; i < 32; i++) { + var low = (1 << i) >>> 0; + result = jspb.utils.joinUnsignedDecimalString(low, 0); + assertEquals('' + Math.pow(2, i), result); + } + + // Check the first 20 bits of the high dword. + for (var i = 0; i < 20; i++) { + var high = (1 << i) >>> 0; + result = jspb.utils.joinUnsignedDecimalString(0, high); + assertEquals('' + Math.pow(2, 32 + i), result); + } + + // V8's internal double-to-string conversion is inaccurate for values above + // 2^52, even if they're representable integers - check the rest of the bits + // manually against the correct string representations of 2^N. + + result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x00100000); + assertEquals('4503599627370496', result); + + result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x00200000); + assertEquals('9007199254740992', result); + + result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x00400000); + assertEquals('18014398509481984', result); + + result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x00800000); + assertEquals('36028797018963968', result); + + result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x01000000); + assertEquals('72057594037927936', result); + + result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x02000000); + assertEquals('144115188075855872', result); + + result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x04000000); + assertEquals('288230376151711744', result); + + result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x08000000); + assertEquals('576460752303423488', result); + + result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x10000000); + assertEquals('1152921504606846976', result); + + result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x20000000); + assertEquals('2305843009213693952', result); + + result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x40000000); + assertEquals('4611686018427387904', result); + + result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x80000000); + assertEquals('9223372036854775808', result); + }); + + + /** + * Going from hash strings to decimal strings should also be lossless. + */ + it('testHashToDecimalConversion', function() { + var result; + var convert = jspb.utils.hash64ToDecimalString; + + result = convert(toHashString(0x00000000, 0x00000000), false); + assertEquals('0', result); + + result = convert(toHashString(0x00000000, 0x00000000), true); + assertEquals('0', result); + + result = convert(toHashString(0xFFFFFFFF, 0xFFFFFFFF), false); + assertEquals('18446744073709551615', result); + + result = convert(toHashString(0xFFFFFFFF, 0xFFFFFFFF), true); + assertEquals('-1', result); + + result = convert(toHashString(0x00000000, 0x80000000), false); + assertEquals('9223372036854775808', result); + + result = convert(toHashString(0x00000000, 0x80000000), true); + assertEquals('-9223372036854775808', result); + + result = convert(toHashString(0xacd05f15, 0x01b69b4b), false); + assertEquals('123456789123456789', result); + + result = convert(toHashString(~0xacd05f15 + 1, ~0x01b69b4b), true); + assertEquals('-123456789123456789', result); + + // And converting arrays of hashes should work the same way. + result = jspb.utils.hash64ArrayToDecimalStrings([ + toHashString(0xFFFFFFFF, 0xFFFFFFFF), + toHashString(0x00000000, 0x80000000), + toHashString(0xacd05f15, 0x01b69b4b)], false); + assertEquals(3, result.length); + assertEquals('18446744073709551615', result[0]); + assertEquals('9223372036854775808', result[1]); + assertEquals('123456789123456789', result[2]); + }); + + /* + * Going from decimal strings to hash strings should be lossless. + */ + it('testDecimalToHashConversion', function() { + var result; + var convert = jspb.utils.decimalStringToHash64; + + result = convert('0'); + assertEquals(String.fromCharCode.apply(null, + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), result); + + result = convert('-1'); + assertEquals(String.fromCharCode.apply(null, + [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]), result); + + result = convert('18446744073709551615'); + assertEquals(String.fromCharCode.apply(null, + [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]), result); + + result = convert('9223372036854775808'); + assertEquals(String.fromCharCode.apply(null, + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80]), result); + + result = convert('-9223372036854775808'); + assertEquals(String.fromCharCode.apply(null, + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80]), result); + + result = convert('123456789123456789'); + assertEquals(String.fromCharCode.apply(null, + [0x15, 0x5F, 0xD0, 0xAC, 0x4B, 0x9B, 0xB6, 0x01]), result); + + result = convert('-123456789123456789'); + assertEquals(String.fromCharCode.apply(null, + [0xEB, 0xA0, 0x2F, 0x53, 0xB4, 0x64, 0x49, 0xFE]), result); + }); + + /** + * Going from hash strings to hex strings should be lossless. + */ + it('testHashToHexConversion', function() { + var result; + var convert = jspb.utils.hash64ToHexString; + + result = convert(toHashString(0x00000000, 0x00000000)); + assertEquals('0x0000000000000000', result); + + result = convert(toHashString(0xFFFFFFFF, 0xFFFFFFFF)); + assertEquals('0xffffffffffffffff', result); + + result = convert(toHashString(0x12345678, 0x9ABCDEF0)); + assertEquals('0x9abcdef012345678', result); + }); + + + /** + * Going from hex strings to hash strings should be lossless. + */ + it('testHexToHashConversion', function() { + var result; + var convert = jspb.utils.hexStringToHash64; + + result = convert('0x0000000000000000'); + assertEquals(String.fromCharCode.apply(null, + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), result); + + result = convert('0xffffffffffffffff'); + assertEquals(String.fromCharCode.apply(null, + [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]), result); + + // Hex string is big-endian, hash string is little-endian. + result = convert('0x123456789ABCDEF0'); + assertEquals(String.fromCharCode.apply(null, + [0xF0, 0xDE, 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12]), result); + + // Capitalization should not matter. + result = convert('0x0000abcdefABCDEF'); + assertEquals(String.fromCharCode.apply(null, + [0xEF, 0xCD, 0xAB, 0xEF, 0xCD, 0xAB, 0x00, 0x00]), result); + }); + + + /** + * Going from numbers to hash strings should be lossless for up to 53 bits of + * precision. + */ + it('testNumberToHashConversion', function() { + var result; + var convert = jspb.utils.numberToHash64; + + result = convert(0x0000000000000); + assertEquals('0x0000000000000000', jspb.utils.hash64ToHexString(result)); + + result = convert(0xFFFFFFFFFFFFF); + assertEquals('0x000fffffffffffff', jspb.utils.hash64ToHexString(result)); + + result = convert(0x123456789ABCD); + assertEquals('0x000123456789abcd', jspb.utils.hash64ToHexString(result)); + + result = convert(0xDCBA987654321); + assertEquals('0x000dcba987654321', jspb.utils.hash64ToHexString(result)); + + // 53 bits of precision should not be truncated. + result = convert(0x10000000000001); + assertEquals('0x0010000000000001', jspb.utils.hash64ToHexString(result)); + + // 54 bits of precision should be truncated. + result = convert(0x20000000000001); + assertNotEquals( + '0x0020000000000001', jspb.utils.hash64ToHexString(result)); + }); + + + /** + * Sanity check the behavior of Javascript's strings when doing funny things + * with unicode characters. + */ + it('sanityCheckUnicodeStrings', function() { + var strings = new Array(65536); + + // All possible unsigned 16-bit values should be storable in a string, they + // shouldn't do weird things with the length of the string, and they should + // come back out of the string unchanged. + for (var i = 0; i < 65536; i++) { + strings[i] = 'a' + String.fromCharCode(i) + 'a'; + if (3 != strings[i].length) throw 'fail!'; + if (i != strings[i].charCodeAt(1)) throw 'fail!'; + } + + // Each unicode character should compare equal to itself and not equal to a + // different unicode character. + for (var i = 0; i < 65536; i++) { + if (strings[i] != strings[i]) throw 'fail!'; + if (strings[i] == strings[(i + 1) % 65536]) throw 'fail!'; + } + }); + + + /** + * Tests conversion from 32-bit floating point numbers to split64 numbers. + */ + it('testFloat32ToSplit64', function() { + var f32_eps = jspb.BinaryConstants.FLOAT32_EPS; + var f32_min = jspb.BinaryConstants.FLOAT32_MIN; + var f32_max = jspb.BinaryConstants.FLOAT32_MAX; + + // NaN. + jspb.utils.splitFloat32(NaN); + if (!isNaN(jspb.utils.joinFloat32(jspb.utils.split64Low, + jspb.utils.split64High))) { + throw 'fail!'; + } + + /** + * @param {number} x + * @param {number=} opt_bits + */ + function test(x, opt_bits) { + jspb.utils.splitFloat32(x); + if (goog.isDef(opt_bits)) { + if (opt_bits != jspb.utils.split64Low) throw 'fail!'; + } + if (truncate(x) != jspb.utils.joinFloat32(jspb.utils.split64Low, + jspb.utils.split64High)) { + throw 'fail!'; + } + } + + // Positive and negative infinity. + test(Infinity, 0x7f800000); + test(-Infinity, 0xff800000); + + // Positive and negative zero. + test(0, 0x00000000); + test(-0, 0x80000000); + + // Positive and negative epsilon. + test(f32_eps, 0x00000001); + test(-f32_eps, 0x80000001); + + // Positive and negative min. + test(f32_min, 0x00800000); + test(-f32_min, 0x80800000); + + // Positive and negative max. + test(f32_max, 0x7F7FFFFF); + test(-f32_max, 0xFF7FFFFF); + + // Various positive values. + var cursor = f32_eps * 10; + while (cursor != Infinity) { + test(cursor); + cursor *= 1.1; + } + + // Various negative values. + cursor = -f32_eps * 10; + while (cursor != -Infinity) { + test(cursor); + cursor *= 1.1; + } + }); + + + /** + * Tests conversion from 64-bit floating point numbers to split64 numbers. + */ + it('testFloat64ToSplit64', function() { + var f64_eps = jspb.BinaryConstants.FLOAT64_EPS; + var f64_min = jspb.BinaryConstants.FLOAT64_MIN; + var f64_max = jspb.BinaryConstants.FLOAT64_MAX; + + // NaN. + jspb.utils.splitFloat64(NaN); + if (!isNaN(jspb.utils.joinFloat64(jspb.utils.split64Low, + jspb.utils.split64High))) { + throw 'fail!'; + } + + /** + * @param {number} x + * @param {number=} opt_highBits + * @param {number=} opt_lowBits + */ + function test(x, opt_highBits, opt_lowBits) { + jspb.utils.splitFloat64(x); + if (goog.isDef(opt_highBits)) { + if (opt_highBits != jspb.utils.split64High) throw 'fail!'; + } + if (goog.isDef(opt_lowBits)) { + if (opt_lowBits != jspb.utils.split64Low) throw 'fail!'; + } + if (x != jspb.utils.joinFloat64(jspb.utils.split64Low, + jspb.utils.split64High)) { + throw 'fail!'; + } + } + + // Positive and negative infinity. + test(Infinity, 0x7ff00000, 0x00000000); + test(-Infinity, 0xfff00000, 0x00000000); + + // Positive and negative zero. + test(0, 0x00000000, 0x00000000); + test(-0, 0x80000000, 0x00000000); + + // Positive and negative epsilon. + test(f64_eps, 0x00000000, 0x00000001); + test(-f64_eps, 0x80000000, 0x00000001); + + // Positive and negative min. + test(f64_min, 0x00100000, 0x00000000); + test(-f64_min, 0x80100000, 0x00000000); + + // Positive and negative max. + test(f64_max, 0x7FEFFFFF, 0xFFFFFFFF); + test(-f64_max, 0xFFEFFFFF, 0xFFFFFFFF); + + // Various positive values. + var cursor = f64_eps * 10; + while (cursor != Infinity) { + test(cursor); + cursor *= 1.1; + } + + // Various negative values. + cursor = -f64_eps * 10; + while (cursor != -Infinity) { + test(cursor); + cursor *= 1.1; + } + }); + + + /** + * Tests counting packed varints. + */ + it('testCountVarints', function() { + var values = []; + for (var i = 1; i < 1000000000; i *= 1.1) { + values.push(Math.floor(i)); + } + + var writer = new jspb.BinaryWriter(); + writer.writePackedUint64(1, values); + + var buffer = new Uint8Array(writer.getResultBuffer()); + + // We should have two more varints than we started with - one for the field + // tag, one for the packed length. + assertEquals(values.length + 2, + jspb.utils.countVarints(buffer, 0, buffer.length)); + }); + + + /** + * Tests counting matching varint fields. + */ + it('testCountVarintFields', function() { + var writer = new jspb.BinaryWriter(); + + var count = 0; + for (var i = 1; i < 1000000000; i *= 1.1) { + writer.writeUint64(1, Math.floor(i)); + count++; + } + writer.writeString(2, 'terminator'); + + var buffer = new Uint8Array(writer.getResultBuffer()); + assertEquals(count, + jspb.utils.countVarintFields(buffer, 0, buffer.length, 1)); + + writer = new jspb.BinaryWriter(); + + count = 0; + for (var i = 1; i < 1000000000; i *= 1.1) { + writer.writeUint64(123456789, Math.floor(i)); + count++; + } + writer.writeString(2, 'terminator'); + + buffer = new Uint8Array(writer.getResultBuffer()); + assertEquals(count, + jspb.utils.countVarintFields(buffer, 0, buffer.length, 123456789)); + }); + + + /** + * Tests counting matching fixed32 fields. + */ + it('testCountFixed32Fields', function() { + var writer = new jspb.BinaryWriter(); + + var count = 0; + for (var i = 1; i < 1000000000; i *= 1.1) { + writer.writeFixed32(1, Math.floor(i)); + count++; + } + writer.writeString(2, 'terminator'); + + var buffer = new Uint8Array(writer.getResultBuffer()); + assertEquals(count, + jspb.utils.countFixed32Fields(buffer, 0, buffer.length, 1)); + + writer = new jspb.BinaryWriter(); + + count = 0; + for (var i = 1; i < 1000000000; i *= 1.1) { + writer.writeFixed32(123456789, Math.floor(i)); + count++; + } + writer.writeString(2, 'terminator'); + + buffer = new Uint8Array(writer.getResultBuffer()); + assertEquals(count, + jspb.utils.countFixed32Fields(buffer, 0, buffer.length, 123456789)); + }); + + + /** + * Tests counting matching fixed64 fields. + */ + it('testCountFixed64Fields', function() { + var writer = new jspb.BinaryWriter(); + + var count = 0; + for (var i = 1; i < 1000000000; i *= 1.1) { + writer.writeDouble(1, i); + count++; + } + writer.writeString(2, 'terminator'); + + var buffer = new Uint8Array(writer.getResultBuffer()); + assertEquals(count, + jspb.utils.countFixed64Fields(buffer, 0, buffer.length, 1)); + + writer = new jspb.BinaryWriter(); + + count = 0; + for (var i = 1; i < 1000000000; i *= 1.1) { + writer.writeDouble(123456789, i); + count++; + } + writer.writeString(2, 'terminator'); + + buffer = new Uint8Array(writer.getResultBuffer()); + assertEquals(count, + jspb.utils.countFixed64Fields(buffer, 0, buffer.length, 123456789)); + }); + + + /** + * Tests counting matching delimited fields. + */ + it('testCountDelimitedFields', function() { + var writer = new jspb.BinaryWriter(); + + var count = 0; + for (var i = 1; i < 1000; i *= 1.1) { + writer.writeBytes(1, [Math.floor(i)]); + count++; + } + writer.writeString(2, 'terminator'); + + var buffer = new Uint8Array(writer.getResultBuffer()); + assertEquals(count, + jspb.utils.countDelimitedFields(buffer, 0, buffer.length, 1)); + + writer = new jspb.BinaryWriter(); + + count = 0; + for (var i = 1; i < 1000; i *= 1.1) { + writer.writeBytes(123456789, [Math.floor(i)]); + count++; + } + writer.writeString(2, 'terminator'); + + buffer = new Uint8Array(writer.getResultBuffer()); + assertEquals(count, + jspb.utils.countDelimitedFields(buffer, 0, buffer.length, 123456789)); + }); + + + /** + * Tests byte format for debug strings. + */ + it('testDebugBytesToTextFormat', function() { + assertEquals('""', jspb.utils.debugBytesToTextFormat(null)); + assertEquals('"\\x00\\x10\\xff"', + jspb.utils.debugBytesToTextFormat([0, 16, 255])); + }); + + + /** + * Tests converting byte blob sources into byte blobs. + */ + it('testByteSourceToUint8Array', function() { + var convert = jspb.utils.byteSourceToUint8Array; + + var sourceData = []; + for (var i = 0; i < 256; i++) { + sourceData.push(i); + } + + var sourceBytes = new Uint8Array(sourceData); + var sourceBuffer = sourceBytes.buffer; + var sourceBase64 = goog.crypt.base64.encodeByteArray(sourceData); + var sourceString = String.fromCharCode.apply(null, sourceData); + + function check(result) { + assertEquals(Uint8Array, result.constructor); + assertEquals(sourceData.length, result.length); + for (var i = 0; i < result.length; i++) { + assertEquals(sourceData[i], result[i]); + } + } + + // Converting Uint8Arrays into Uint8Arrays should be a no-op. + assertEquals(sourceBytes, convert(sourceBytes)); + + // Converting Array. into Uint8Arrays should work. + check(convert(sourceData)); + + // Converting ArrayBuffers into Uint8Arrays should work. + check(convert(sourceBuffer)); + + // Converting base64-encoded strings into Uint8Arrays should work. + check(convert(sourceBase64)); + }); +}); diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/writer_test.js b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/writer_test.js new file mode 100644 index 0000000000..d5dadb4135 --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/binary/writer_test.js @@ -0,0 +1,122 @@ +// 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. + +/** + * @fileoverview Test cases for jspb's binary protocol buffer writer. In + * practice BinaryWriter is used to drive the Decoder and Reader test cases, + * so only writer-specific tests are here. + * + * Test suite is written using Jasmine -- see http://jasmine.github.io/ + * + * @author aappleby@google.com (Austin Appleby) + */ + +goog.require('goog.crypt'); +goog.require('goog.testing.asserts'); +goog.require('jspb.BinaryWriter'); + + +/** + * @param {function()} func This function should throw an error when run. + */ +function assertFails(func) { + var e = assertThrows(func); + //assertNotNull(e.toString().match(/Error/)); +} + + +describe('binaryWriterTest', function() { + /** + * Verifies that misuse of the writer class triggers assertions. + */ + it('testWriteErrors', function() { + // Submessages with invalid field indices should assert. + var writer = new jspb.BinaryWriter(); + var dummyMessage = /** @type {!jspb.BinaryMessage} */({}); + + assertFails(function() { + writer.writeMessage(-1, dummyMessage, goog.nullFunction); + }); + + // Writing invalid field indices should assert. + writer = new jspb.BinaryWriter(); + assertFails(function() {writer.writeUint64(-1, 1);}); + + // Writing out-of-range field values should assert. + writer = new jspb.BinaryWriter(); + + assertFails(function() {writer.writeInt32(1, -Infinity);}); + assertFails(function() {writer.writeInt32(1, Infinity);}); + + assertFails(function() {writer.writeInt64(1, -Infinity);}); + assertFails(function() {writer.writeInt64(1, Infinity);}); + + assertFails(function() {writer.writeUint32(1, -1);}); + assertFails(function() {writer.writeUint32(1, Infinity);}); + + assertFails(function() {writer.writeUint64(1, -1);}); + assertFails(function() {writer.writeUint64(1, Infinity);}); + + assertFails(function() {writer.writeSint32(1, -Infinity);}); + assertFails(function() {writer.writeSint32(1, Infinity);}); + + assertFails(function() {writer.writeSint64(1, -Infinity);}); + assertFails(function() {writer.writeSint64(1, Infinity);}); + + assertFails(function() {writer.writeFixed32(1, -1);}); + assertFails(function() {writer.writeFixed32(1, Infinity);}); + + assertFails(function() {writer.writeFixed64(1, -1);}); + assertFails(function() {writer.writeFixed64(1, Infinity);}); + + assertFails(function() {writer.writeSfixed32(1, -Infinity);}); + assertFails(function() {writer.writeSfixed32(1, Infinity);}); + + assertFails(function() {writer.writeSfixed64(1, -Infinity);}); + assertFails(function() {writer.writeSfixed64(1, Infinity);}); + }); + + + /** + * Basic test of retrieving the result as a Uint8Array buffer + */ + it('testGetResultBuffer', function() { + var expected = '0864120b48656c6c6f20776f726c641a0301020320c801'; + + var writer = new jspb.BinaryWriter(); + writer.writeUint32(1, 100); + writer.writeString(2, 'Hello world'); + writer.writeBytes(3, new Uint8Array([1, 2, 3])); + writer.writeUint32(4, 200); + + var buffer = writer.getResultBuffer(); + assertEquals(expected, goog.crypt.byteArrayToHex(buffer)); + }); +}); diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/export_asserts.js b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/export_asserts.js new file mode 100644 index 0000000000..5219d120c1 --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/export_asserts.js @@ -0,0 +1,37 @@ +/** + * @fileoverview Exports symbols needed only by tests. + * + * This file exports several Closure Library symbols that are only + * used by tests. It is used to generate a file + * closure_asserts_commonjs.js that is only used at testing time. + */ + +goog.require('goog.testing.asserts'); + +var global = Function('return this')(); + +// All of the closure "assert" functions are exported at the global level. +// +// The Google Closure assert functions start with assert, eg. +// assertThrows +// assertNotThrows +// assertTrue +// ... +// +// The one exception is the "fail" function. +function shouldExport(str) { + return str.lastIndexOf('assert') === 0 || str == 'fail'; +} + +for (var key in global) { + if ((typeof key == "string") && global.hasOwnProperty(key) && + shouldExport(key)) { + exports[key] = global[key]; + } +} + +// The COMPILED variable is set by Closure compiler to "true" when it compiles +// JavaScript, so in practice this is equivalent to "exports.COMPILED = true". +// This will disable some debugging functionality in debug.js. We could +// investigate whether this can/should be enabled in CommonJS builds. +exports.COMPILED = COMPILED diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/export_testdeps.js b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/export_testdeps.js new file mode 100644 index 0000000000..59c77ca2cd --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/export_testdeps.js @@ -0,0 +1,18 @@ +/** + * @fileoverview Export symbols needed by tests in CommonJS style. + * + * This file is like export.js, but for symbols that are only used by tests. + * However we exclude assert functions here, because they are exported into + * the global namespace, so those are handled as a special case in + * export_asserts.js. + */ + +goog.require('goog.crypt.base64'); +goog.require('jspb.arith.Int64'); +goog.require('jspb.arith.UInt64'); +goog.require('jspb.BinaryEncoder'); +goog.require('jspb.BinaryDecoder'); +goog.require('jspb.utils'); + +exports.goog = goog; +exports.jspb = jspb; diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/import_test.js b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/import_test.js new file mode 100644 index 0000000000..ffa34fea61 --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/import_test.js @@ -0,0 +1,52 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2016 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. + +// Test suite is written using Jasmine -- see http://jasmine.github.io/ + + + +var googleProtobuf = require('google-protobuf'); +var asserts = require('closure_asserts_commonjs'); +var global = Function('return this')(); + +// Bring asserts into the global namespace. +googleProtobuf.object.extend(global, asserts); +googleProtobuf.exportSymbol('jspb.Message', googleProtobuf.Message, global); + +var test7_pb = require('./test7/test7_pb'); +googleProtobuf.exportSymbol('proto.jspb.test.framing.FramingMessage', test7_pb.FramingMessage, global); + +describe('Import test suite', function() { + it('testImportedMessage', function() { + var framing1 = new proto.jspb.test.framing.FramingMessage([]); + var framing2 = new proto.jspb.test.framing.FramingMessage([]); + assertObjectEquals(framing1.toObject(), framing2.toObject()); + }); +}); diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/jasmine.json b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/jasmine.json new file mode 100644 index 0000000000..666b8edbf8 --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/jasmine.json @@ -0,0 +1,9 @@ +{ + "spec_dir": "", + "spec_files": [ + "*_test.js", + "binary/proto_test.js" + ], + "helpers": [ + ] +} diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/rewrite_tests_for_commonjs.js b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/rewrite_tests_for_commonjs.js new file mode 100644 index 0000000000..b6d90d287d --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/rewrite_tests_for_commonjs.js @@ -0,0 +1,97 @@ +/** + * @fileoverview Utility to translate test files to CommonJS imports. + * + * This is a somewhat hacky tool designed to do one very specific thing. + * All of the test files in *_test.js are written with Closure-style + * imports (goog.require()). This works great for running the tests + * against Closure-style generated code, but we also want to run the + * tests against CommonJS-style generated code without having to fork + * the tests. + * + * Closure-style imports import each individual type by name. This is + * very different than CommonJS imports which are by file. So we put + * special comments in these tests like: + * + * // CommonJS-LoadFromFile: test_pb + * goog.require('proto.jspb.test.CloneExtension'); + * goog.require('proto.jspb.test.Complex'); + * goog.require('proto.jspb.test.DefaultValues'); + * + * This script parses that special comment and uses it to generate proper + * CommonJS require() statements so that the tests can run and pass using + * CommonJS imports. The script will change the above statements into: + * + * var test_pb = require('test_pb'); + * googleProtobuf.exportSymbol('proto.jspb.test.CloneExtension', test_pb.CloneExtension, global); + * googleProtobuf.exportSymbol('proto.jspb.test.Complex', test_pb.Complex, global); + * googleProtobuf.exportSymbol('proto.jspb.test.DefaultValues', test_pb.DefaultValues, global); + * + * (The "exportSymbol" function will define the given names in the global + * namespace, taking care not to overwrite any previous value for + * "proto.jspb.test"). + */ + +var lineReader = require('readline').createInterface({ + input: process.stdin, + output: process.stdout +}); + +function tryStripPrefix(str, prefix) { + if (str.lastIndexOf(prefix) !== 0) { + throw "String: " + str + " didn't start with: " + prefix; + } + return str.substr(prefix.length); +} + +function camelCase(str) { + var ret = ''; + var ucaseNext = false; + for (var i = 0; i < str.length; i++) { + if (str[i] == '-') { + ucaseNext = true; + } else if (ucaseNext) { + ret += str[i].toUpperCase(); + ucaseNext = false; + } else { + ret += str[i]; + } + } + return ret; +} + +var module = null; +var pkg = null; + +// Header: goes in every file at the top. +console.log("var global = Function('return this')();"); +console.log("var googleProtobuf = require('google-protobuf');"); +console.log("var testdeps = require('testdeps_commonjs');"); +console.log("global.goog = testdeps.goog;"); +console.log("global.jspb = testdeps.jspb;"); +console.log("var asserts = require('closure_asserts_commonjs');"); +console.log(""); +console.log("// Bring asserts into the global namespace."); +console.log("googleProtobuf.object.extend(global, asserts);"); + +lineReader.on('line', function(line) { + var isRequire = line.match(/goog\.require\('([^']*)'\)/); + var isLoadFromFile = line.match(/CommonJS-LoadFromFile: (\S*) (.*)/); + var isSetTestOnly = line.match(/goog.setTestOnly()/); + if (isRequire) { + if (module) { // Skip goog.require() lines before the first directive. + var fullSym = isRequire[1]; + var sym = tryStripPrefix(fullSym, pkg); + console.log("googleProtobuf.exportSymbol('" + fullSym + "', " + module + sym + ', global);'); + } + } else if (isLoadFromFile) { + var module_path = isLoadFromFile[1].split('/'); + module = camelCase(module_path[module_path.length - 1]); + pkg = isLoadFromFile[2]; + + if (module != "googleProtobuf") { // We unconditionally require this in the header. + console.log("var " + module + " = require('./" + isLoadFromFile[1] + "');"); + } + } else if (!isSetTestOnly) { // Remove goog.setTestOnly() lines. + console.log(line); + } +}); diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/test6/test6.proto b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/test6/test6.proto new file mode 100644 index 0000000000..a060925f2d --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/test6/test6.proto @@ -0,0 +1,40 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2016 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. + +syntax = "proto3"; + +option java_package = "com.google.apps.jspb.proto"; +option java_multiple_files = true; + +package jspb.test.importing; + +message ImportedMessage { + string string_value = 1; +} diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/test7/test7.proto b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/test7/test7.proto new file mode 100644 index 0000000000..f5574a3dd3 --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/commonjs/test7/test7.proto @@ -0,0 +1,42 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2016 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. + +syntax = "proto3"; + +option java_package = "com.google.apps.jspb.proto"; +option java_multiple_files = true; + +package jspb.test.framing; + +import "test6/test6.proto"; + +message FramingMessage { + jspb.test.importing.ImportedMessage imported_message = 1; +} diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/data.proto b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/data.proto new file mode 100644 index 0000000000..74a8a994c7 --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/data.proto @@ -0,0 +1,51 @@ +// 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: mwr@google.com (Mark Rawling) + +syntax = "proto2"; + +option java_package = "com.google.apps.jspb.proto"; +option java_multiple_files = true; + +package jspb.test; + +// legacy data, must be nested +message data { + message NestedData { + required string str = 1; + } +} + +// new data, does not require nesting +message UnnestedData { + required string str = 1; +} + diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/debug_test.js b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/debug_test.js new file mode 100644 index 0000000000..01cbf891ab --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/debug_test.js @@ -0,0 +1,105 @@ +// 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. + +goog.setTestOnly(); + +goog.require('goog.testing.asserts'); + +// CommonJS-LoadFromFile: google-protobuf +goog.require('jspb.debug'); + +// CommonJS-LoadFromFile: test_pb +goog.require('proto.jspb.test.HasExtensions'); +goog.require('proto.jspb.test.IsExtension'); +goog.require('proto.jspb.test.Simple1'); + + + +describe('debugTest', function() { + it('testSimple1', function() { + if (COMPILED) { + return; + } + var message = new proto.jspb.test.Simple1(); + message.setAString('foo'); + assertObjectEquals({ + $name: 'proto.jspb.test.Simple1', + 'aString': 'foo', + 'aRepeatedStringList': [] + }, jspb.debug.dump(message)); + + message.setABoolean(true); + message.setARepeatedStringList(['1', '2']); + + assertObjectEquals({ + $name: 'proto.jspb.test.Simple1', + 'aString': 'foo', + 'aRepeatedStringList': ['1', '2'], + 'aBoolean': true + }, jspb.debug.dump(message)); + + message.setAString(undefined); + + assertObjectEquals({ + $name: 'proto.jspb.test.Simple1', + 'aRepeatedStringList': ['1', '2'], + 'aBoolean': true + }, jspb.debug.dump(message)); + }); + + + it('testExtensions', function() { + if (COMPILED) { + return; + } + var extension = new proto.jspb.test.IsExtension(); + extension.setExt1('ext1field'); + var extendable = new proto.jspb.test.HasExtensions(); + extendable.setStr1('v1'); + extendable.setStr2('v2'); + extendable.setStr3('v3'); + extendable.setExtension(proto.jspb.test.IsExtension.extField, extension); + + assertObjectEquals({ + '$name': 'proto.jspb.test.HasExtensions', + 'str1': 'v1', + 'str2': 'v2', + 'str3': 'v3', + '$extensions': { + 'extField': { + '$name': 'proto.jspb.test.IsExtension', + 'ext1': 'ext1field' + }, + 'repeatedSimpleList': [] + } + }, jspb.debug.dump(extendable)); + }); + +}); diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/jasmine1.json b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/jasmine1.json new file mode 100644 index 0000000000..6653c01cc7 --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/jasmine1.json @@ -0,0 +1,17 @@ +{ + "spec_dir": "", + "spec_files": [ + "*_test.js", + "binary/*_test.js" + ], + "helpers": [ + "../../../js/node_modules/google-closure-library/closure/goog/bootstrap/nodejs.js", + "../../../js/node_loader.js", + "../../../js/deps.js", + "../../../js/google/protobuf/any.js", + "../../../js/google/protobuf/struct.js", + "../../../js/google/protobuf/timestamp.js", + "testproto_libs1.js", + "testproto_libs2.js" + ] +} diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/jasmine2.json b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/jasmine2.json new file mode 100644 index 0000000000..3208078f7e --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/jasmine2.json @@ -0,0 +1,17 @@ +{ + "spec_dir": "", + "spec_files": [ + "*_test.js", + "binary/*_test.js" + ], + "helpers": [ + "../../../js/node_modules/google-closure-library/closure/goog/bootstrap/nodejs.js", + "../../../js/node_loader.js", + "../../../js/deps.js", + "../../../js/google/protobuf/any.js", + "../../../js/google/protobuf/struct.js", + "../../../js/google/protobuf/timestamp.js", + "testproto_libs1_new.js", + "testproto_libs2.js" + ] +} diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/jasmine3.json b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/jasmine3.json new file mode 100644 index 0000000000..3fb9a1b01d --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/jasmine3.json @@ -0,0 +1,17 @@ +{ + "spec_dir": "", + "spec_files": [ + "*_test.js", + "binary/*_test.js" + ], + "helpers": [ + "../../../js/node_modules/google-closure-library/closure/goog/bootstrap/nodejs.js", + "../../../js/node_loader.js", + "../../../js/deps.js", + "../../../js/google/protobuf/any.js", + "../../../js/google/protobuf/struct.js", + "../../../js/google/protobuf/timestamp.js", + "testproto_libs1.js", + "testproto_libs2_new.js" + ] +} diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/message_test.js b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/message_test.js new file mode 100644 index 0000000000..b779143115 --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/message_test.js @@ -0,0 +1,1080 @@ +// 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. + +// Test suite is written using Jasmine -- see http://jasmine.github.io/ + +goog.setTestOnly(); + +goog.require('goog.json'); +goog.require('goog.testing.asserts'); +goog.require('goog.userAgent'); + +// CommonJS-LoadFromFile: google-protobuf jspb +goog.require('jspb.Message'); + +// CommonJS-LoadFromFile: test5_pb proto.jspb.exttest.beta +goog.require('proto.jspb.exttest.beta.floatingStrField'); + +// CommonJS-LoadFromFile: test3_pb proto.jspb.exttest +goog.require('proto.jspb.exttest.floatingMsgField'); + +// CommonJS-LoadFromFile: test4_pb proto.jspb.exttest +goog.require('proto.jspb.exttest.floatingMsgFieldTwo'); + +// CommonJS-LoadFromFile: test_pb proto.jspb.test +goog.require('proto.jspb.test.CloneExtension'); +goog.require('proto.jspb.test.Complex'); +goog.require('proto.jspb.test.DefaultValues'); +goog.require('proto.jspb.test.Empty'); +goog.require('proto.jspb.test.EnumContainer'); +goog.require('proto.jspb.test.floatingMsgField'); +goog.require('proto.jspb.test.FloatingPointFields'); +goog.require('proto.jspb.test.floatingStrField'); +goog.require('proto.jspb.test.HasExtensions'); +goog.require('proto.jspb.test.IndirectExtension'); +goog.require('proto.jspb.test.IsExtension'); +goog.require('proto.jspb.test.OptionalFields'); +goog.require('proto.jspb.test.OuterEnum'); +goog.require('proto.jspb.test.OuterMessage.Complex'); +goog.require('proto.jspb.test.Simple1'); +goog.require('proto.jspb.test.Simple2'); +goog.require('proto.jspb.test.SpecialCases'); +goog.require('proto.jspb.test.TestClone'); +goog.require('proto.jspb.test.TestEndsWithBytes'); +goog.require('proto.jspb.test.TestGroup'); +goog.require('proto.jspb.test.TestGroup1'); +goog.require('proto.jspb.test.TestMessageWithOneof'); +goog.require('proto.jspb.test.TestReservedNames'); +goog.require('proto.jspb.test.TestReservedNamesExtension'); + +// CommonJS-LoadFromFile: test2_pb proto.jspb.test +goog.require('proto.jspb.test.ExtensionMessage'); +goog.require('proto.jspb.test.TestExtensionsMessage'); + + + + +describe('Message test suite', function() { + it('testEmptyProto', function() { + var empty1 = new proto.jspb.test.Empty([]); + var empty2 = new proto.jspb.test.Empty([]); + assertObjectEquals({}, empty1.toObject()); + assertObjectEquals('Message should not be corrupted:', empty2, empty1); + }); + + it('testTopLevelEnum', function() { + var response = new proto.jspb.test.EnumContainer([]); + response.setOuterEnum(proto.jspb.test.OuterEnum.FOO); + assertEquals(proto.jspb.test.OuterEnum.FOO, response.getOuterEnum()); + }); + + it('testByteStrings', function() { + var data = new proto.jspb.test.DefaultValues([]); + data.setBytesField('some_bytes'); + assertEquals('some_bytes', data.getBytesField()); + }); + + it('testComplexConversion', function() { + var data1 = ['a',,, [, 11], [[, 22], [, 33]],, ['s1', 's2'],, 1]; + var data2 = ['a',,, [, 11], [[, 22], [, 33]],, ['s1', 's2'],, 1]; + var foo = new proto.jspb.test.Complex(data1); + var bar = new proto.jspb.test.Complex(data2); + var result = foo.toObject(); + assertObjectEquals({ + aString: 'a', + anOutOfOrderBool: 1, + aNestedMessage: { + anInt: 11 + }, + aRepeatedMessageList: [{anInt: 22}, {anInt: 33}], + aRepeatedStringList: ['s1', 's2'] + }, result); + + // Now test with the jspb instances included. + result = foo.toObject(true /* opt_includeInstance */); + assertObjectEquals({ + aString: 'a', + anOutOfOrderBool: 1, + aNestedMessage: { + anInt: 11, + $jspbMessageInstance: foo.getANestedMessage() + }, + aRepeatedMessageList: [ + {anInt: 22, $jspbMessageInstance: foo.getARepeatedMessageList()[0]}, + {anInt: 33, $jspbMessageInstance: foo.getARepeatedMessageList()[1]} + ], + aRepeatedStringList: ['s1', 's2'], + $jspbMessageInstance: foo + }, result); + + }); + + it('testMissingFields', function() { + var foo = new proto.jspb.test.Complex([ + undefined, undefined, undefined, [], + undefined, undefined, undefined, undefined]); + var bar = new proto.jspb.test.Complex([ + undefined, undefined, undefined, [], + undefined, undefined, undefined, undefined]); + var result = foo.toObject(); + assertObjectEquals({ + aString: undefined, + anOutOfOrderBool: undefined, + aNestedMessage: { + anInt: undefined + }, + // Note: JsPb converts undefined repeated fields to empty arrays. + aRepeatedMessageList: [], + aRepeatedStringList: [] + }, result); + + }); + + it('testNestedComplexMessage', function() { + // Instantiate the message and set a unique field, just to ensure that we + // are not getting jspb.test.Complex instead. + var msg = new proto.jspb.test.OuterMessage.Complex(); + msg.setInnerComplexField(5); + }); + + it('testSpecialCases', function() { + // Note: Some property names are reserved in JavaScript. + // These names are converted to the Js property named pb_. + var special = + new proto.jspb.test.SpecialCases(['normal', 'default', 'function', + 'var']); + var result = special.toObject(); + assertObjectEquals({ + normal: 'normal', + pb_default: 'default', + pb_function: 'function', + pb_var: 'var' + }, result); + }); + + it('testDefaultValues', function() { + var defaultString = "default<>\'\"abc"; + var response = new proto.jspb.test.DefaultValues(); + + // Test toObject + var expectedObject = { + stringField: defaultString, + boolField: true, + intField: 11, + enumField: 13, + emptyField: '', + bytesField: 'bW9v' + }; + assertObjectEquals(expectedObject, response.toObject()); + + + // Test getters + response = new proto.jspb.test.DefaultValues(); + assertEquals(defaultString, response.getStringField()); + assertEquals(true, response.getBoolField()); + assertEquals(11, response.getIntField()); + assertEquals(13, response.getEnumField()); + assertEquals('', response.getEmptyField()); + assertEquals('bW9v', response.getBytesField()); + + function makeDefault(values) { + return new proto.jspb.test.DefaultValues(values); + } + + // Test with undefined values, + // Use push to workaround IE treating undefined array elements as holes. + response = makeDefault([undefined, undefined, undefined, undefined]); + assertEquals(defaultString, response.getStringField()); + assertEquals(true, response.getBoolField()); + assertEquals(11, response.getIntField()); + assertEquals(13, response.getEnumField()); + assertFalse(response.hasStringField()); + assertFalse(response.hasBoolField()); + assertFalse(response.hasIntField()); + assertFalse(response.hasEnumField()); + + // Test with null values, as would be returned by a JSON serializer. + response = makeDefault([null, null, null, null]); + assertEquals(defaultString, response.getStringField()); + assertEquals(true, response.getBoolField()); + assertEquals(11, response.getIntField()); + assertEquals(13, response.getEnumField()); + assertFalse(response.hasStringField()); + assertFalse(response.hasBoolField()); + assertFalse(response.hasIntField()); + assertFalse(response.hasEnumField()); + + // Test with false-like values. + response = makeDefault(['', false, 0, 0]); + assertEquals('', response.getStringField()); + assertEquals(false, response.getBoolField()); + assertEquals(true, response.getIntField() == 0); + assertEquals(true, response.getEnumField() == 0); + assertTrue(response.hasStringField()); + assertTrue(response.hasBoolField()); + assertTrue(response.hasIntField()); + assertTrue(response.hasEnumField()); + + // Test that clearing the values reverts them to the default state. + response = makeDefault(['blah', false, 111, 77]); + response.clearStringField(); response.clearBoolField(); + response.clearIntField(); response.clearEnumField(); + assertEquals(defaultString, response.getStringField()); + assertEquals(true, response.getBoolField()); + assertEquals(11, response.getIntField()); + assertEquals(13, response.getEnumField()); + assertFalse(response.hasStringField()); + assertFalse(response.hasBoolField()); + assertFalse(response.hasIntField()); + assertFalse(response.hasEnumField()); + + // Test that setFoo(null) clears the values. + response = makeDefault(['blah', false, 111, 77]); + response.setStringField(null); response.setBoolField(null); + response.setIntField(undefined); response.setEnumField(undefined); + assertEquals(defaultString, response.getStringField()); + assertEquals(true, response.getBoolField()); + assertEquals(11, response.getIntField()); + assertEquals(13, response.getEnumField()); + assertFalse(response.hasStringField()); + assertFalse(response.hasBoolField()); + assertFalse(response.hasIntField()); + assertFalse(response.hasEnumField()); + }); + + it('testMessageRegistration', function() { + // goog.require(SomeResponse) will include its library, which will in + // turn add SomeResponse to the message registry. + assertEquals(jspb.Message.registry_['res'], proto.jspb.test.SomeResponse); + }); + + it('testClearFields', function() { + var data = ['str', true, [11], [[22], [33]], ['s1', 's2']]; + var foo = new proto.jspb.test.OptionalFields(data); + foo.clearAString(); + foo.clearABool(); + foo.clearANestedMessage(); + foo.clearARepeatedMessageList(); + foo.clearARepeatedStringList(); + assertEquals('', foo.getAString()); + assertEquals(false, foo.getABool()); + assertUndefined(foo.getANestedMessage()); + assertFalse(foo.hasAString()); + assertFalse(foo.hasABool()); + assertObjectEquals([], foo.getARepeatedMessageList()); + assertObjectEquals([], foo.getARepeatedStringList()); + // NOTE: We want the missing fields in 'expected' to be undefined, + // but we actually get a sparse array instead. We could use something + // like [1,undefined,2] to avoid this, except that this is still + // sparse on IE. No comment... + var expected = [,,, [], []]; + expected[0] = expected[1] = expected[2] = undefined; + assertObjectEquals(expected, foo.toArray()); + + // Test set(null). We could deprecated this in favor of clear(), but + // it's also convenient to have. + data = ['str', true, [11], [[22], [33]], ['s1', 's2']]; + foo = new proto.jspb.test.OptionalFields(data); + foo.setAString(null); + foo.setABool(null); + foo.setANestedMessage(null); + foo.setARepeatedMessageList(null); + foo.setARepeatedStringList(null); + assertEquals('', foo.getAString()); + assertEquals(false, foo.getABool()); + assertNull(foo.getANestedMessage()); + assertFalse(foo.hasAString()); + assertFalse(foo.hasABool()); + assertObjectEquals([], foo.getARepeatedMessageList()); + assertObjectEquals([], foo.getARepeatedStringList()); + assertObjectEquals([null, null, null, [], []], foo.toArray()); + + // Test set(undefined). Again, not something we really need, and not + // supported directly by our typing, but it should 'do the right thing'. + data = ['str', true, [11], [[22], [33]], ['s1', 's2']]; + foo = new proto.jspb.test.OptionalFields(data); + foo.setAString(undefined); + foo.setABool(undefined); + foo.setANestedMessage(undefined); + foo.setARepeatedMessageList(undefined); + foo.setARepeatedStringList(undefined); + assertEquals('', foo.getAString()); + assertEquals(false, foo.getABool()); + assertUndefined(foo.getANestedMessage()); + assertFalse(foo.hasAString()); + assertFalse(foo.hasABool()); + assertObjectEquals([], foo.getARepeatedMessageList()); + assertObjectEquals([], foo.getARepeatedStringList()); + expected = [,,, [], []]; + expected[0] = expected[1] = expected[2] = undefined; + assertObjectEquals(expected, foo.toArray()); + }); + + it('testDifferenceRawObject', function() { + var p1 = new proto.jspb.test.HasExtensions(['hi', 'diff', {}]); + var p2 = new proto.jspb.test.HasExtensions(['hi', 'what', + {1000: 'unique'}]); + var diff = /** @type {proto.jspb.test.HasExtensions} */ + (jspb.Message.difference(p1, p2)); + assertEquals('', diff.getStr1()); + assertEquals('what', diff.getStr2()); + assertEquals('', diff.getStr3()); + assertEquals('unique', diff.extensionObject_[1000]); + }); + + it('testEqualsSimple', function() { + var s1 = new proto.jspb.test.Simple1(['hi']); + assertTrue(jspb.Message.equals(s1, new proto.jspb.test.Simple1(['hi']))); + assertFalse(jspb.Message.equals(s1, new proto.jspb.test.Simple1(['bye']))); + var s1b = new proto.jspb.test.Simple1(['hi', ['hello']]); + assertTrue(jspb.Message.equals(s1b, + new proto.jspb.test.Simple1(['hi', ['hello']]))); + assertTrue(jspb.Message.equals(s1b, + new proto.jspb.test.Simple1(['hi', ['hello', undefined, + undefined, undefined]]))); + assertFalse(jspb.Message.equals(s1b, + new proto.jspb.test.Simple1(['no', ['hello']]))); + // Test with messages of different types + var s2 = new proto.jspb.test.Simple2(['hi']); + assertFalse(jspb.Message.equals(s1, s2)); + }); + + it('testEquals_softComparison', function() { + var s1 = new proto.jspb.test.Simple1(['hi', [], null]); + assertTrue(jspb.Message.equals(s1, + new proto.jspb.test.Simple1(['hi', []]))); + + var s1b = new proto.jspb.test.Simple1(['hi', [], true]); + assertTrue(jspb.Message.equals(s1b, + new proto.jspb.test.Simple1(['hi', [], 1]))); + }); + + it('testEqualsComplex', function() { + var data1 = ['a',,, [, 11], [[, 22], [, 33]],, ['s1', 's2'],, 1]; + var data2 = ['a',,, [, 11], [[, 22], [, 34]],, ['s1', 's2'],, 1]; + var data3 = ['a',,, [, 11], [[, 22]],, ['s1', 's2'],, 1]; + var data4 = ['hi']; + var c1a = new proto.jspb.test.Complex(data1); + var c1b = new proto.jspb.test.Complex(data1); + var c2 = new proto.jspb.test.Complex(data2); + var c3 = new proto.jspb.test.Complex(data3); + var s1 = new proto.jspb.test.Simple1(data4); + + assertTrue(jspb.Message.equals(c1a, c1b)); + assertFalse(jspb.Message.equals(c1a, c2)); + assertFalse(jspb.Message.equals(c2, c3)); + assertFalse(jspb.Message.equals(c1a, s1)); + }); + + it('testEqualsExtensionsConstructed', function() { + assertTrue(jspb.Message.equals( + new proto.jspb.test.HasExtensions([]), + new proto.jspb.test.HasExtensions([{}]) + )); + assertTrue(jspb.Message.equals( + new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]), + new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]) + )); + assertFalse(jspb.Message.equals( + new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]), + new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'b'}]}]) + )); + assertTrue(jspb.Message.equals( + new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]), + new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]) + )); + assertTrue(jspb.Message.equals( + new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]), + new proto.jspb.test.HasExtensions([,,, {100: [{200: 'a'}]}]) + )); + assertTrue(jspb.Message.equals( + new proto.jspb.test.HasExtensions([,,, {100: [{200: 'a'}]}]), + new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]) + )); + assertTrue(jspb.Message.equals( + new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]), + new proto.jspb.test.HasExtensions(['hi',,, {100: [{200: 'a'}]}]) + )); + assertTrue(jspb.Message.equals( + new proto.jspb.test.HasExtensions(['hi',,, {100: [{200: 'a'}]}]), + new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]) + )); + }); + + it('testEqualsExtensionsUnconstructed', function() { + assertTrue(jspb.Message.compareFields([], [{}])); + assertTrue(jspb.Message.compareFields([,,, {}], [])); + assertTrue(jspb.Message.compareFields([,,, {}], [,, {}])); + assertTrue(jspb.Message.compareFields( + ['hi', {100: [{200: 'a'}]}], ['hi', {100: [{200: 'a'}]}])); + assertFalse(jspb.Message.compareFields( + ['hi', {100: [{200: 'a'}]}], ['hi', {100: [{200: 'b'}]}])); + assertTrue(jspb.Message.compareFields( + [{100: [{200: 'a'}]}], [{100: [{200: 'a'}]}])); + assertTrue(jspb.Message.compareFields( + [{100: [{200: 'a'}]}], [,,, {100: [{200: 'a'}]}])); + assertTrue(jspb.Message.compareFields( + [,,, {100: [{200: 'a'}]}], [{100: [{200: 'a'}]}])); + assertTrue(jspb.Message.compareFields( + ['hi', {100: [{200: 'a'}]}], ['hi',,, {100: [{200: 'a'}]}])); + assertTrue(jspb.Message.compareFields( + ['hi',,, {100: [{200: 'a'}]}], ['hi', {100: [{200: 'a'}]}])); + }); + + it('testToMap', function() { + var p1 = new proto.jspb.test.Simple1(['k', ['v']]); + var p2 = new proto.jspb.test.Simple1(['k1', ['v1', 'v2']]); + var soymap = jspb.Message.toMap([p1, p2], + proto.jspb.test.Simple1.prototype.getAString, + proto.jspb.test.Simple1.prototype.toObject); + assertEquals('k', soymap['k'].aString); + assertArrayEquals(['v'], soymap['k'].aRepeatedStringList); + var protomap = jspb.Message.toMap([p1, p2], + proto.jspb.test.Simple1.prototype.getAString); + assertEquals('k', protomap['k'].getAString()); + assertArrayEquals(['v'], protomap['k'].getARepeatedStringList()); + }); + + it('testClone', function() { + var supportsUint8Array = + !goog.userAgent.IE || goog.userAgent.isVersionOrHigher('10'); + var original = new proto.jspb.test.TestClone(); + original.setStr('v1'); + var simple1 = new proto.jspb.test.Simple1(['x1', ['y1', 'z1']]); + var simple2 = new proto.jspb.test.Simple1(['x2', ['y2', 'z2']]); + var simple3 = new proto.jspb.test.Simple1(['x3', ['y3', 'z3']]); + original.setSimple1(simple1); + original.setSimple2List([simple2, simple3]); + var bytes1 = supportsUint8Array ? new Uint8Array([1, 2, 3]) : '123'; + original.setBytesField(bytes1); + var extension = new proto.jspb.test.CloneExtension(); + extension.setExt('e1'); + original.setExtension(proto.jspb.test.IsExtension.extField, extension); + var clone = original.cloneMessage(); + assertArrayEquals(['v1',, ['x1', ['y1', 'z1']],, + [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1,, { 100: [, 'e1'] }], + clone.toArray()); + clone.setStr('v2'); + var simple4 = new proto.jspb.test.Simple1(['a1', ['b1', 'c1']]); + var simple5 = new proto.jspb.test.Simple1(['a2', ['b2', 'c2']]); + var simple6 = new proto.jspb.test.Simple1(['a3', ['b3', 'c3']]); + clone.setSimple1(simple4); + clone.setSimple2List([simple5, simple6]); + if (supportsUint8Array) { + clone.getBytesField()[0] = 4; + assertObjectEquals(bytes1, original.getBytesField()); + } + var bytes2 = supportsUint8Array ? new Uint8Array([4, 5, 6]) : '456'; + clone.setBytesField(bytes2); + var newExtension = new proto.jspb.test.CloneExtension(); + newExtension.setExt('e2'); + clone.setExtension(proto.jspb.test.CloneExtension.extField, newExtension); + assertArrayEquals(['v2',, ['a1', ['b1', 'c1']],, + [['a2', ['b2', 'c2']], ['a3', ['b3', 'c3']]], bytes2,, { 100: [, 'e2'] }], + clone.toArray()); + assertArrayEquals(['v1',, ['x1', ['y1', 'z1']],, + [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1,, { 100: [, 'e1'] }], + original.toArray()); + }); + + it('testCopyInto', function() { + var supportsUint8Array = + !goog.userAgent.IE || goog.userAgent.isVersionOrHigher('10'); + var original = new proto.jspb.test.TestClone(); + original.setStr('v1'); + var dest = new proto.jspb.test.TestClone(); + dest.setStr('override'); + var simple1 = new proto.jspb.test.Simple1(['x1', ['y1', 'z1']]); + var simple2 = new proto.jspb.test.Simple1(['x2', ['y2', 'z2']]); + var simple3 = new proto.jspb.test.Simple1(['x3', ['y3', 'z3']]); + var destSimple1 = new proto.jspb.test.Simple1(['ox1', ['oy1', 'oz1']]); + var destSimple2 = new proto.jspb.test.Simple1(['ox2', ['oy2', 'oz2']]); + var destSimple3 = new proto.jspb.test.Simple1(['ox3', ['oy3', 'oz3']]); + original.setSimple1(simple1); + original.setSimple2List([simple2, simple3]); + dest.setSimple1(destSimple1); + dest.setSimple2List([destSimple2, destSimple3]); + var bytes1 = supportsUint8Array ? new Uint8Array([1, 2, 3]) : '123'; + var bytes2 = supportsUint8Array ? new Uint8Array([4, 5, 6]) : '456'; + original.setBytesField(bytes1); + dest.setBytesField(bytes2); + var extension = new proto.jspb.test.CloneExtension(); + extension.setExt('e1'); + original.setExtension(proto.jspb.test.CloneExtension.extField, extension); + + jspb.Message.copyInto(original, dest); + assertArrayEquals(original.toArray(), dest.toArray()); + assertEquals('x1', dest.getSimple1().getAString()); + assertEquals('e1', + dest.getExtension(proto.jspb.test.CloneExtension.extField).getExt()); + dest.getSimple1().setAString('new value'); + assertNotEquals(dest.getSimple1().getAString(), + original.getSimple1().getAString()); + if (supportsUint8Array) { + dest.getBytesField()[0] = 7; + assertObjectEquals(bytes1, original.getBytesField()); + assertObjectEquals(new Uint8Array([7, 2, 3]), dest.getBytesField()); + } else { + dest.setBytesField('789'); + assertObjectEquals(bytes1, original.getBytesField()); + assertObjectEquals('789', dest.getBytesField()); + } + dest.getExtension(proto.jspb.test.CloneExtension.extField). + setExt('new value'); + assertNotEquals( + dest.getExtension(proto.jspb.test.CloneExtension.extField).getExt(), + original.getExtension( + proto.jspb.test.CloneExtension.extField).getExt()); + }); + + it('testCopyInto_notSameType', function() { + var a = new proto.jspb.test.TestClone(); + var b = new proto.jspb.test.Simple1(['str', ['s1', 's2']]); + + var e = assertThrows(function() { + jspb.Message.copyInto(a, b); + }); + assertContains('should have the same type', e.message); + }); + + it('testExtensions', function() { + var extension1 = new proto.jspb.test.IsExtension(['ext1field']); + var extension2 = new proto.jspb.test.Simple1(['str', ['s1', 's2']]); + var extendable = new proto.jspb.test.HasExtensions(['v1', 'v2', 'v3']); + extendable.setExtension(proto.jspb.test.IsExtension.extField, extension1); + extendable.setExtension(proto.jspb.test.IndirectExtension.simple, + extension2); + extendable.setExtension(proto.jspb.test.IndirectExtension.str, 'xyzzy'); + extendable.setExtension(proto.jspb.test.IndirectExtension.repeatedStrList, + ['a', 'b']); + var s1 = new proto.jspb.test.Simple1(['foo', ['s1', 's2']]); + var s2 = new proto.jspb.test.Simple1(['bar', ['t1', 't2']]); + extendable.setExtension( + proto.jspb.test.IndirectExtension.repeatedSimpleList, + [s1, s2]); + assertObjectEquals(extension1, + extendable.getExtension(proto.jspb.test.IsExtension.extField)); + assertObjectEquals(extension2, + extendable.getExtension(proto.jspb.test.IndirectExtension.simple)); + assertObjectEquals('xyzzy', + extendable.getExtension(proto.jspb.test.IndirectExtension.str)); + assertObjectEquals(['a', 'b'], extendable.getExtension( + proto.jspb.test.IndirectExtension.repeatedStrList)); + assertObjectEquals([s1, s2], extendable.getExtension( + proto.jspb.test.IndirectExtension.repeatedSimpleList)); + // Not supported yet, but it should work... + extendable.setExtension(proto.jspb.test.IndirectExtension.simple, null); + assertNull( + extendable.getExtension(proto.jspb.test.IndirectExtension.simple)); + extendable.setExtension(proto.jspb.test.IndirectExtension.str, null); + assertNull(extendable.getExtension(proto.jspb.test.IndirectExtension.str)); + + + // Extension fields with jspb.ignore = true are ignored. + assertUndefined(proto.jspb.test.IndirectExtension['ignored']); + assertUndefined(proto.jspb.test.HasExtensions['ignoredFloating']); + }); + + it('testFloatingExtensions', function() { + // From an autogenerated container. + var extendable = new proto.jspb.test.HasExtensions(['v1', 'v2', 'v3']); + var extension = new proto.jspb.test.Simple1(['foo', ['s1', 's2']]); + extendable.setExtension(proto.jspb.test.simple1, extension); + assertObjectEquals(extension, + extendable.getExtension(proto.jspb.test.simple1)); + + // From _lib mode. + extension = new proto.jspb.test.ExtensionMessage(['s1']); + extendable = new proto.jspb.test.TestExtensionsMessage([16]); + extendable.setExtension(proto.jspb.test.floatingMsgField, extension); + extendable.setExtension(proto.jspb.test.floatingStrField, 's2'); + assertObjectEquals(extension, + extendable.getExtension(proto.jspb.test.floatingMsgField)); + assertObjectEquals('s2', + extendable.getExtension(proto.jspb.test.floatingStrField)); + assertNotUndefined(proto.jspb.exttest.floatingMsgField); + assertNotUndefined(proto.jspb.exttest.floatingMsgFieldTwo); + assertNotUndefined(proto.jspb.exttest.beta.floatingStrField); + }); + + it('testToObject_extendedObject', function() { + var extension1 = new proto.jspb.test.IsExtension(['ext1field']); + var extension2 = new proto.jspb.test.Simple1(['str', ['s1', 's2'], true]); + var extendable = new proto.jspb.test.HasExtensions(['v1', 'v2', 'v3']); + extendable.setExtension(proto.jspb.test.IsExtension.extField, extension1); + extendable.setExtension(proto.jspb.test.IndirectExtension.simple, + extension2); + extendable.setExtension(proto.jspb.test.IndirectExtension.str, 'xyzzy'); + extendable.setExtension(proto.jspb.test.IndirectExtension.repeatedStrList, + ['a', 'b']); + var s1 = new proto.jspb.test.Simple1(['foo', ['s1', 's2'], true]); + var s2 = new proto.jspb.test.Simple1(['bar', ['t1', 't2'], false]); + extendable.setExtension( + proto.jspb.test.IndirectExtension.repeatedSimpleList, + [s1, s2]); + assertObjectEquals({ + str1: 'v1', str2: 'v2', str3: 'v3', + extField: { ext1: 'ext1field' }, + simple: { + aString: 'str', aRepeatedStringList: ['s1', 's2'], aBoolean: true + }, + str: 'xyzzy', + repeatedStrList: ['a', 'b'], + repeatedSimpleList: [ + { aString: 'foo', aRepeatedStringList: ['s1', 's2'], aBoolean: true}, + { aString: 'bar', aRepeatedStringList: ['t1', 't2'], aBoolean: false} + ] + }, extendable.toObject()); + + // Now, with instances included. + assertObjectEquals({ + str1: 'v1', str2: 'v2', str3: 'v3', + extField: { + ext1: 'ext1field', + $jspbMessageInstance: + extendable.getExtension(proto.jspb.test.IsExtension.extField) + }, + simple: { + aString: 'str', + aRepeatedStringList: ['s1', 's2'], + aBoolean: true, + $jspbMessageInstance: + extendable.getExtension(proto.jspb.test.IndirectExtension.simple) + }, + str: 'xyzzy', + repeatedStrList: ['a', 'b'], + repeatedSimpleList: [{ + aString: 'foo', + aRepeatedStringList: ['s1', 's2'], + aBoolean: true, + $jspbMessageInstance: s1 + }, { + aString: 'bar', + aRepeatedStringList: ['t1', 't2'], + aBoolean: false, + $jspbMessageInstance: s2 + }], + $jspbMessageInstance: extendable + }, extendable.toObject(true /* opt_includeInstance */)); + }); + + it('testInitialization_emptyArray', function() { + var msg = new proto.jspb.test.HasExtensions([]); + if (jspb.Message.MINIMIZE_MEMORY_ALLOCATIONS) { + assertArrayEquals([], msg.toArray()); + } else { + // Extension object is created past all regular fields. + assertArrayEquals([,,, {}], msg.toArray()); + } + }); + + it('testInitialization_justExtensionObject', function() { + var msg = new proto.jspb.test.Empty([{1: 'hi'}]); + // The extensionObject is not moved from its original location. + assertArrayEquals([{1: 'hi'}], msg.toArray()); + }); + + it('testInitialization_incompleteList', function() { + var msg = new proto.jspb.test.Empty([1, {4: 'hi'}]); + // The extensionObject is not moved from its original location. + assertArrayEquals([1, {4: 'hi'}], msg.toArray()); + }); + + it('testInitialization_forwardCompatible', function() { + var msg = new proto.jspb.test.Empty([1, 2, 3, {1: 'hi'}]); + assertArrayEquals([1, 2, 3, {1: 'hi'}], msg.toArray()); + }); + + it('testExtendedMessageEnsureObject', function() { + var data = new proto.jspb.test.HasExtensions(['str1', + {'a_key': 'an_object'}]); + assertEquals('an_object', data.extensionObject_['a_key']); + }); + + it('testToObject_hasExtensionField', function() { + var data = new proto.jspb.test.HasExtensions(['str1', {100: ['ext1']}]); + var obj = data.toObject(); + assertEquals('str1', obj.str1); + assertEquals('ext1', obj.extField.ext1); + }); + + it('testGetExtension', function() { + var data = new proto.jspb.test.HasExtensions(['str1', {100: ['ext1']}]); + assertEquals('str1', data.getStr1()); + var extension = data.getExtension(proto.jspb.test.IsExtension.extField); + assertNotNull(extension); + assertEquals('ext1', extension.getExt1()); + }); + + it('testSetExtension', function() { + var data = new proto.jspb.test.HasExtensions(); + var extensionMessage = new proto.jspb.test.IsExtension(['is_extension']); + data.setExtension(proto.jspb.test.IsExtension.extField, extensionMessage); + var obj = data.toObject(); + assertNotNull( + data.getExtension(proto.jspb.test.IsExtension.extField)); + assertEquals('is_extension', obj.extField.ext1); + }); + + /** + * Note that group is long deprecated, we only support it because JsPb has + * a goal of being able to generate JS classes for all proto descriptors. + */ + it('testGroups', function() { + var group = new proto.jspb.test.TestGroup(); + var someGroup = new proto.jspb.test.TestGroup.RepeatedGroup(); + someGroup.setId('g1'); + someGroup.setSomeBoolList([true, false]); + group.setRepeatedGroupList([someGroup]); + var groups = group.getRepeatedGroupList(); + assertEquals('g1', groups[0].getId()); + assertObjectEquals([true, false], groups[0].getSomeBoolList()); + assertObjectEquals({id: 'g1', someBoolList: [true, false]}, + groups[0].toObject()); + assertObjectEquals({ + repeatedGroupList: [{id: 'g1', someBoolList: [true, false]}], + requiredGroup: {id: undefined}, + optionalGroup: undefined, + requiredSimple: {aRepeatedStringList: [], aString: undefined}, + optionalSimple: undefined, + id: undefined + }, group.toObject()); + var group1 = new proto.jspb.test.TestGroup1(); + group1.setGroup(someGroup); + assertEquals(someGroup, group1.getGroup()); + }); + + it('testNonExtensionFieldsAfterExtensionRange', function() { + var data = [{'1': 'a_string'}]; + var message = new proto.jspb.test.Complex(data); + assertArrayEquals([], message.getARepeatedStringList()); + }); + + it('testReservedGetterNames', function() { + var message = new proto.jspb.test.TestReservedNames(); + message.setExtension$(11); + message.setExtension(proto.jspb.test.TestReservedNamesExtension.foo, 12); + assertEquals(11, message.getExtension$()); + assertEquals(12, message.getExtension( + proto.jspb.test.TestReservedNamesExtension.foo)); + assertObjectEquals({extension: 11, foo: 12}, message.toObject()); + }); + + it('testInitializeMessageWithUnsetOneof', function() { + var message = new proto.jspb.test.TestMessageWithOneof([]); + assertEquals( + proto.jspb.test.TestMessageWithOneof.PartialOneofCase. + PARTIAL_ONEOF_NOT_SET, + message.getPartialOneofCase()); + assertEquals( + proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase. + RECURSIVE_ONEOF_NOT_SET, + message.getRecursiveOneofCase()); + }); + + it('testInitializeMessageWithSingleValueSetInOneof', function() { + var message = new proto.jspb.test.TestMessageWithOneof([,, 'x']); + + assertEquals('x', message.getPone()); + assertEquals('', message.getPthree()); + assertEquals( + proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE, + message.getPartialOneofCase()); + }); + + it('testKeepsLastWireValueSetInUnion_multipleValues', function() { + var message = new proto.jspb.test.TestMessageWithOneof([,, 'x',, 'y']); + + assertEquals('', message.getPone()); + assertEquals('y', message.getPthree()); + assertEquals( + proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PTHREE, + message.getPartialOneofCase()); + }); + + it('testSettingOneofFieldClearsOthers', function() { + var message = new proto.jspb.test.TestMessageWithOneof; + assertEquals('', message.getPone()); + assertEquals('', message.getPthree()); + assertFalse(message.hasPone()); + assertFalse(message.hasPthree()); + + message.setPone('hi'); + assertEquals('hi', message.getPone()); + assertEquals('', message.getPthree()); + assertTrue(message.hasPone()); + assertFalse(message.hasPthree()); + + message.setPthree('bye'); + assertEquals('', message.getPone()); + assertEquals('bye', message.getPthree()); + assertFalse(message.hasPone()); + assertTrue(message.hasPthree()); + }); + + it('testSettingOneofFieldDoesNotClearFieldsFromOtherUnions', function() { + var other = new proto.jspb.test.TestMessageWithOneof; + var message = new proto.jspb.test.TestMessageWithOneof; + assertEquals('', message.getPone()); + assertEquals('', message.getPthree()); + assertUndefined(message.getRone()); + assertFalse(message.hasPone()); + assertFalse(message.hasPthree()); + + message.setPone('hi'); + message.setRone(other); + assertEquals('hi', message.getPone()); + assertEquals('', message.getPthree()); + assertEquals(other, message.getRone()); + assertTrue(message.hasPone()); + assertFalse(message.hasPthree()); + + message.setPthree('bye'); + assertEquals('', message.getPone()); + assertEquals('bye', message.getPthree()); + assertEquals(other, message.getRone()); + assertFalse(message.hasPone()); + assertTrue(message.hasPthree()); + }); + + it('testUnsetsOneofCaseWhenFieldIsCleared', function() { + var message = new proto.jspb.test.TestMessageWithOneof; + assertEquals( + proto.jspb.test.TestMessageWithOneof.PartialOneofCase. + PARTIAL_ONEOF_NOT_SET, + message.getPartialOneofCase()); + + message.setPone('hi'); + assertEquals( + proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE, + message.getPartialOneofCase()); + + message.clearPone(); + assertEquals( + proto.jspb.test.TestMessageWithOneof.PartialOneofCase. + PARTIAL_ONEOF_NOT_SET, + message.getPartialOneofCase()); + }); + + it('testMessageWithDefaultOneofValues', function() { + var message = new proto.jspb.test.TestMessageWithOneof; + assertEquals(1234, message.getAone()); + assertEquals(0, message.getAtwo()); + assertEquals( + proto.jspb.test.TestMessageWithOneof.DefaultOneofACase + .DEFAULT_ONEOF_A_NOT_SET, + message.getDefaultOneofACase()); + + message.setAone(567); + assertEquals(567, message.getAone()); + assertEquals(0, message.getAtwo()); + assertEquals( + proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.AONE, + message.getDefaultOneofACase()); + + message.setAtwo(890); + assertEquals(1234, message.getAone()); + assertEquals(890, message.getAtwo()); + assertEquals( + proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.ATWO, + message.getDefaultOneofACase()); + + message.clearAtwo(); + assertEquals(1234, message.getAone()); + assertEquals(0, message.getAtwo()); + assertEquals( + proto.jspb.test.TestMessageWithOneof.DefaultOneofACase + .DEFAULT_ONEOF_A_NOT_SET, + message.getDefaultOneofACase()); + }); + + it('testMessageWithDefaultOneofValues_defaultNotOnFirstField', function() { + var message = new proto.jspb.test.TestMessageWithOneof; + assertEquals(0, message.getBone()); + assertEquals(1234, message.getBtwo()); + assertFalse(message.hasBone()); + assertFalse(message.hasBtwo()); + assertEquals( + proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase + .DEFAULT_ONEOF_B_NOT_SET, + message.getDefaultOneofBCase()); + + message.setBone(2); + assertEquals(2, message.getBone()); + assertEquals(1234, message.getBtwo()); + assertTrue(message.hasBone()); + assertFalse(message.hasBtwo()); + assertEquals( + proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BONE, + message.getDefaultOneofBCase()); + + message.setBtwo(3); + assertEquals(0, message.getBone()); + assertFalse(message.hasBone()); + assertTrue(message.hasBtwo()); + assertEquals(3, message.getBtwo()); + assertEquals( + proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO, + message.getDefaultOneofBCase()); + + message.clearBtwo(); + assertEquals(0, message.getBone()); + assertFalse(message.hasBone()); + assertFalse(message.hasBtwo()); + assertEquals(1234, message.getBtwo()); + assertEquals( + proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase + .DEFAULT_ONEOF_B_NOT_SET, + message.getDefaultOneofBCase()); + }); + + it('testInitializeMessageWithOneofDefaults', function() { + var message = + new proto.jspb.test.TestMessageWithOneof(new Array(9).concat(567)); + assertEquals(567, message.getAone()); + assertEquals(0, message.getAtwo()); + assertEquals( + proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.AONE, + message.getDefaultOneofACase()); + + message = + new proto.jspb.test.TestMessageWithOneof(new Array(10).concat(890)); + assertEquals(1234, message.getAone()); + assertEquals(890, message.getAtwo()); + assertEquals( + proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.ATWO, + message.getDefaultOneofACase()); + + message = + new proto.jspb.test.TestMessageWithOneof(new Array(9).concat(567, 890)); + assertEquals(1234, message.getAone()); + assertEquals(890, message.getAtwo()); + assertEquals( + proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.ATWO, + message.getDefaultOneofACase()); + }); + + it('testInitializeMessageWithOneofDefaults_defaultNotSetOnFirstField', + function() { + var message; + + message = + new proto.jspb.test.TestMessageWithOneof(new Array(11).concat(567)); + assertEquals(567, message.getBone()); + assertEquals(1234, message.getBtwo()); + assertEquals( + proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BONE, + message.getDefaultOneofBCase()); + + message = + new proto.jspb.test.TestMessageWithOneof(new Array(12).concat(890)); + assertEquals(0, message.getBone()); + assertEquals(890, message.getBtwo()); + assertEquals( + proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO, + message.getDefaultOneofBCase()); + + message = new proto.jspb.test.TestMessageWithOneof( + new Array(11).concat(567, 890)); + assertEquals(0, message.getBone()); + assertEquals(890, message.getBtwo()); + assertEquals( + proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO, + message.getDefaultOneofBCase()); + }); + + it('testOneofContainingAnotherMessage', function() { + var message = new proto.jspb.test.TestMessageWithOneof; + assertEquals( + proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase. + RECURSIVE_ONEOF_NOT_SET, + message.getRecursiveOneofCase()); + + var other = new proto.jspb.test.TestMessageWithOneof; + message.setRone(other); + assertEquals(other, message.getRone()); + assertEquals('', message.getRtwo()); + assertEquals( + proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase.RONE, + message.getRecursiveOneofCase()); + + message.setRtwo('hi'); + assertUndefined(message.getRone()); + assertEquals('hi', message.getRtwo()); + assertEquals( + proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase.RTWO, + message.getRecursiveOneofCase()); + }); + + it('testQueryingOneofCaseEnsuresOnlyOneFieldIsSetInUnderlyingArray', + function() { + var message = new proto.jspb.test.TestMessageWithOneof; + message.setPone('x'); + assertEquals('x', message.getPone()); + assertEquals('', message.getPthree()); + assertEquals( + proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE, + message.getPartialOneofCase()); + + var array = message.toArray(); + assertEquals('x', array[2]); + assertUndefined(array[4]); + array[4] = 'y'; + + assertEquals( + proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PTHREE, + message.getPartialOneofCase()); + assertUndefined(array[2]); + assertEquals('y', array[4]); + }); + + it('testFloatingPointFieldsSupportNan', function() { + var assertNan = function(x) { + assertTrue('Expected ' + x + ' (' + goog.typeOf(x) + ') to be NaN.', + goog.isNumber(x) && isNaN(x)); + }; + + var message = new proto.jspb.test.FloatingPointFields([ + 'NaN', 'NaN', ['NaN', 'NaN'], 'NaN', + 'NaN', 'NaN', ['NaN', 'NaN'], 'NaN' + ]); + assertNan(message.getOptionalFloatField()); + assertNan(message.getRequiredFloatField()); + assertNan(message.getRepeatedFloatFieldList()[0]); + assertNan(message.getRepeatedFloatFieldList()[1]); + assertNan(message.getDefaultFloatField()); + assertNan(message.getOptionalDoubleField()); + assertNan(message.getRequiredDoubleField()); + assertNan(message.getRepeatedDoubleFieldList()[0]); + assertNan(message.getRepeatedDoubleFieldList()[1]); + assertNan(message.getDefaultDoubleField()); + }); + +}); diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/proto3_test.js b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/proto3_test.js new file mode 100644 index 0000000000..fab0fd44ff --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/proto3_test.js @@ -0,0 +1,329 @@ +// 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. + +goog.require('goog.crypt.base64'); +goog.require('goog.testing.asserts'); + +// CommonJS-LoadFromFile: testbinary_pb proto.jspb.test +goog.require('proto.jspb.test.ForeignMessage'); + +// CommonJS-LoadFromFile: proto3_test_pb proto.jspb.test +goog.require('proto.jspb.test.Proto3Enum'); +goog.require('proto.jspb.test.TestProto3'); + + +var BYTES = new Uint8Array([1, 2, 8, 9]); +var BYTES_B64 = goog.crypt.base64.encodeByteArray(BYTES); + + +/** + * Helper: compare a bytes field to an expected value + * @param {Uint8Array|string} arr + * @param {Uint8Array} expected + * @return {boolean} + */ +function bytesCompare(arr, expected) { + if (goog.isString(arr)) { + arr = goog.crypt.base64.decodeStringToUint8Array(arr); + } + if (arr.length != expected.length) { + return false; + } + for (var i = 0; i < arr.length; i++) { + if (arr[i] != expected[i]) { + return false; + } + } + return true; +} + + +describe('proto3Test', function() { + /** + * Test defaults for proto3 message fields. + */ + it('testProto3FieldDefaults', function() { + var msg = new proto.jspb.test.TestProto3(); + + assertEquals(msg.getOptionalInt32(), 0); + assertEquals(msg.getOptionalInt64(), 0); + assertEquals(msg.getOptionalUint32(), 0); + assertEquals(msg.getOptionalUint64(), 0); + assertEquals(msg.getOptionalSint32(), 0); + assertEquals(msg.getOptionalSint64(), 0); + assertEquals(msg.getOptionalFixed32(), 0); + assertEquals(msg.getOptionalFixed64(), 0); + assertEquals(msg.getOptionalSfixed32(), 0); + assertEquals(msg.getOptionalSfixed64(), 0); + assertEquals(msg.getOptionalFloat(), 0); + assertEquals(msg.getOptionalDouble(), 0); + assertEquals(msg.getOptionalString(), ''); + + // TODO(b/26173701): when we change bytes fields default getter to return + // Uint8Array, we'll want to switch this assertion to match the u8 case. + assertEquals(typeof msg.getOptionalBytes(), 'string'); + assertEquals(msg.getOptionalBytes_asU8() instanceof Uint8Array, true); + assertEquals(typeof msg.getOptionalBytes_asB64(), 'string'); + assertEquals(msg.getOptionalBytes().length, 0); + assertEquals(msg.getOptionalBytes_asU8().length, 0); + assertEquals(msg.getOptionalBytes_asB64(), ''); + + assertEquals(msg.getOptionalForeignEnum(), + proto.jspb.test.Proto3Enum.PROTO3_FOO); + assertEquals(msg.getOptionalForeignMessage(), undefined); + assertEquals(msg.getOptionalForeignMessage(), undefined); + + assertEquals(msg.getRepeatedInt32List().length, 0); + assertEquals(msg.getRepeatedInt64List().length, 0); + assertEquals(msg.getRepeatedUint32List().length, 0); + assertEquals(msg.getRepeatedUint64List().length, 0); + assertEquals(msg.getRepeatedSint32List().length, 0); + assertEquals(msg.getRepeatedSint64List().length, 0); + assertEquals(msg.getRepeatedFixed32List().length, 0); + assertEquals(msg.getRepeatedFixed64List().length, 0); + assertEquals(msg.getRepeatedSfixed32List().length, 0); + assertEquals(msg.getRepeatedSfixed64List().length, 0); + assertEquals(msg.getRepeatedFloatList().length, 0); + assertEquals(msg.getRepeatedDoubleList().length, 0); + assertEquals(msg.getRepeatedStringList().length, 0); + assertEquals(msg.getRepeatedBytesList().length, 0); + assertEquals(msg.getRepeatedForeignEnumList().length, 0); + assertEquals(msg.getRepeatedForeignMessageList().length, 0); + + }); + + + /** + * Test that all fields can be set and read via a serialization roundtrip. + */ + it('testProto3FieldSetGet', function() { + var msg = new proto.jspb.test.TestProto3(); + + msg.setOptionalInt32(-42); + msg.setOptionalInt64(-0x7fffffff00000000); + msg.setOptionalUint32(0x80000000); + msg.setOptionalUint64(0xf000000000000000); + msg.setOptionalSint32(-100); + msg.setOptionalSint64(-0x8000000000000000); + msg.setOptionalFixed32(1234); + msg.setOptionalFixed64(0x1234567800000000); + msg.setOptionalSfixed32(-1234); + msg.setOptionalSfixed64(-0x1234567800000000); + msg.setOptionalFloat(1.5); + msg.setOptionalDouble(-1.5); + msg.setOptionalBool(true); + msg.setOptionalString('hello world'); + msg.setOptionalBytes(BYTES); + var submsg = new proto.jspb.test.ForeignMessage(); + submsg.setC(16); + msg.setOptionalForeignMessage(submsg); + msg.setOptionalForeignEnum(proto.jspb.test.Proto3Enum.PROTO3_BAR); + + msg.setRepeatedInt32List([-42]); + msg.setRepeatedInt64List([-0x7fffffff00000000]); + msg.setRepeatedUint32List([0x80000000]); + msg.setRepeatedUint64List([0xf000000000000000]); + msg.setRepeatedSint32List([-100]); + msg.setRepeatedSint64List([-0x8000000000000000]); + msg.setRepeatedFixed32List([1234]); + msg.setRepeatedFixed64List([0x1234567800000000]); + msg.setRepeatedSfixed32List([-1234]); + msg.setRepeatedSfixed64List([-0x1234567800000000]); + msg.setRepeatedFloatList([1.5]); + msg.setRepeatedDoubleList([-1.5]); + msg.setRepeatedBoolList([true]); + msg.setRepeatedStringList(['hello world']); + msg.setRepeatedBytesList([BYTES]); + submsg = new proto.jspb.test.ForeignMessage(); + submsg.setC(1000); + msg.setRepeatedForeignMessageList([submsg]); + msg.setRepeatedForeignEnumList([proto.jspb.test.Proto3Enum.PROTO3_BAR]); + + msg.setOneofString('asdf'); + + var serialized = msg.serializeBinary(); + msg = proto.jspb.test.TestProto3.deserializeBinary(serialized); + + assertEquals(msg.getOptionalInt32(), -42); + assertEquals(msg.getOptionalInt64(), -0x7fffffff00000000); + assertEquals(msg.getOptionalUint32(), 0x80000000); + assertEquals(msg.getOptionalUint64(), 0xf000000000000000); + assertEquals(msg.getOptionalSint32(), -100); + assertEquals(msg.getOptionalSint64(), -0x8000000000000000); + assertEquals(msg.getOptionalFixed32(), 1234); + assertEquals(msg.getOptionalFixed64(), 0x1234567800000000); + assertEquals(msg.getOptionalSfixed32(), -1234); + assertEquals(msg.getOptionalSfixed64(), -0x1234567800000000); + assertEquals(msg.getOptionalFloat(), 1.5); + assertEquals(msg.getOptionalDouble(), -1.5); + assertEquals(msg.getOptionalBool(), true); + assertEquals(msg.getOptionalString(), 'hello world'); + assertEquals(true, bytesCompare(msg.getOptionalBytes(), BYTES)); + assertEquals(msg.getOptionalForeignMessage().getC(), 16); + assertEquals(msg.getOptionalForeignEnum(), + proto.jspb.test.Proto3Enum.PROTO3_BAR); + + assertElementsEquals(msg.getRepeatedInt32List(), [-42]); + assertElementsEquals(msg.getRepeatedInt64List(), [-0x7fffffff00000000]); + assertElementsEquals(msg.getRepeatedUint32List(), [0x80000000]); + assertElementsEquals(msg.getRepeatedUint64List(), [0xf000000000000000]); + assertElementsEquals(msg.getRepeatedSint32List(), [-100]); + assertElementsEquals(msg.getRepeatedSint64List(), [-0x8000000000000000]); + assertElementsEquals(msg.getRepeatedFixed32List(), [1234]); + assertElementsEquals(msg.getRepeatedFixed64List(), [0x1234567800000000]); + assertElementsEquals(msg.getRepeatedSfixed32List(), [-1234]); + assertElementsEquals(msg.getRepeatedSfixed64List(), [-0x1234567800000000]); + assertElementsEquals(msg.getRepeatedFloatList(), [1.5]); + assertElementsEquals(msg.getRepeatedDoubleList(), [-1.5]); + assertElementsEquals(msg.getRepeatedBoolList(), [true]); + assertElementsEquals(msg.getRepeatedStringList(), ['hello world']); + assertEquals(msg.getRepeatedBytesList().length, 1); + assertEquals(true, bytesCompare(msg.getRepeatedBytesList()[0], BYTES)); + assertEquals(msg.getRepeatedForeignMessageList().length, 1); + assertEquals(msg.getRepeatedForeignMessageList()[0].getC(), 1000); + assertElementsEquals(msg.getRepeatedForeignEnumList(), + [proto.jspb.test.Proto3Enum.PROTO3_BAR]); + + assertEquals(msg.getOneofString(), 'asdf'); + }); + + + /** + * Test that oneofs continue to have a notion of field presence. + */ + it('testOneofs', function() { + var msg = new proto.jspb.test.TestProto3(); + + assertEquals(msg.getOneofUint32(), 0); + assertEquals(msg.getOneofForeignMessage(), undefined); + assertEquals(msg.getOneofString(), ''); + assertEquals(msg.getOneofBytes(), ''); + assertFalse(msg.hasOneofUint32()); + assertFalse(msg.hasOneofString()); + assertFalse(msg.hasOneofBytes()); + + msg.setOneofUint32(42); + assertEquals(msg.getOneofUint32(), 42); + assertEquals(msg.getOneofForeignMessage(), undefined); + assertEquals(msg.getOneofString(), ''); + assertEquals(msg.getOneofBytes(), ''); + assertTrue(msg.hasOneofUint32()); + assertFalse(msg.hasOneofString()); + assertFalse(msg.hasOneofBytes()); + + + var submsg = new proto.jspb.test.ForeignMessage(); + msg.setOneofForeignMessage(submsg); + assertEquals(msg.getOneofUint32(), 0); + assertEquals(msg.getOneofForeignMessage(), submsg); + assertEquals(msg.getOneofString(), ''); + assertEquals(msg.getOneofBytes(), ''); + assertFalse(msg.hasOneofUint32()); + assertFalse(msg.hasOneofString()); + assertFalse(msg.hasOneofBytes()); + + msg.setOneofString('hello'); + assertEquals(msg.getOneofUint32(), 0); + assertEquals(msg.getOneofForeignMessage(), undefined); + assertEquals(msg.getOneofString(), 'hello'); + assertEquals(msg.getOneofBytes(), ''); + assertFalse(msg.hasOneofUint32()); + assertTrue(msg.hasOneofString()); + assertFalse(msg.hasOneofBytes()); + + msg.setOneofBytes(goog.crypt.base64.encodeString('\u00FF\u00FF')); + assertEquals(msg.getOneofUint32(), 0); + assertEquals(msg.getOneofForeignMessage(), undefined); + assertEquals(msg.getOneofString(), ''); + assertEquals(msg.getOneofBytes_asB64(), + goog.crypt.base64.encodeString('\u00FF\u00FF')); + assertFalse(msg.hasOneofUint32()); + assertFalse(msg.hasOneofString()); + assertTrue(msg.hasOneofBytes()); + }); + + + /** + * Test that "default"-valued primitive fields are not emitted on the wire. + */ + it('testNoSerializeDefaults', function() { + var msg = new proto.jspb.test.TestProto3(); + + // Set each primitive to a non-default value, then back to its default, to + // ensure that the serialization is actually checking the value and not just + // whether it has ever been set. + msg.setOptionalInt32(42); + msg.setOptionalInt32(0); + msg.setOptionalDouble(3.14); + msg.setOptionalDouble(0.0); + msg.setOptionalBool(true); + msg.setOptionalBool(false); + msg.setOptionalString('hello world'); + msg.setOptionalString(''); + msg.setOptionalBytes(goog.crypt.base64.encodeString('\u00FF\u00FF')); + msg.setOptionalBytes(''); + msg.setOptionalForeignMessage(new proto.jspb.test.ForeignMessage()); + msg.setOptionalForeignMessage(null); + msg.setOptionalForeignEnum(proto.jspb.test.Proto3Enum.PROTO3_BAR); + msg.setOptionalForeignEnum(proto.jspb.test.Proto3Enum.PROTO3_FOO); + msg.setOneofUint32(32); + msg.setOneofUint32(null); + + + var serialized = msg.serializeBinary(); + assertEquals(0, serialized.length); + }); + + /** + * Test that base64 string and Uint8Array are interchangeable in bytes fields. + */ + it('testBytesFieldsInterop', function() { + var msg = new proto.jspb.test.TestProto3(); + // Set as a base64 string and check all the getters work. + msg.setOptionalBytes(BYTES_B64); + assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES)); + assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES)); + assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); + + // Test binary serialize round trip doesn't break it. + msg = proto.jspb.test.TestProto3.deserializeBinary(msg.serializeBinary()); + assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES)); + assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES)); + assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); + + msg = new proto.jspb.test.TestProto3(); + // Set as a Uint8Array and check all the getters work. + msg.setOptionalBytes(BYTES); + assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES)); + assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES)); + assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); + + }); +}); diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/proto3_test.proto b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/proto3_test.proto new file mode 100644 index 0000000000..acb6716492 --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/proto3_test.proto @@ -0,0 +1,89 @@ +// 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. + +syntax = "proto3"; + +import "testbinary.proto"; + +package jspb.test; + +message TestProto3 { + int32 optional_int32 = 1; + int64 optional_int64 = 2; + uint32 optional_uint32 = 3; + uint64 optional_uint64 = 4; + sint32 optional_sint32 = 5; + sint64 optional_sint64 = 6; + fixed32 optional_fixed32 = 7; + fixed64 optional_fixed64 = 8; + sfixed32 optional_sfixed32 = 9; + sfixed64 optional_sfixed64 = 10; + float optional_float = 11; + double optional_double = 12; + bool optional_bool = 13; + string optional_string = 14; + bytes optional_bytes = 15; + + ForeignMessage optional_foreign_message = 19; + Proto3Enum optional_foreign_enum = 22; + + repeated int32 repeated_int32 = 31; + repeated int64 repeated_int64 = 32; + repeated uint32 repeated_uint32 = 33; + repeated uint64 repeated_uint64 = 34; + repeated sint32 repeated_sint32 = 35; + repeated sint64 repeated_sint64 = 36; + repeated fixed32 repeated_fixed32 = 37; + repeated fixed64 repeated_fixed64 = 38; + repeated sfixed32 repeated_sfixed32 = 39; + repeated sfixed64 repeated_sfixed64 = 40; + repeated float repeated_float = 41; + repeated double repeated_double = 42; + repeated bool repeated_bool = 43; + repeated string repeated_string = 44; + repeated bytes repeated_bytes = 45; + + repeated ForeignMessage repeated_foreign_message = 49; + repeated Proto3Enum repeated_foreign_enum = 52; + + + oneof oneof_field { + uint32 oneof_uint32 = 111; + ForeignMessage oneof_foreign_message = 112; + string oneof_string = 113; + bytes oneof_bytes = 114; + } +} + +enum Proto3Enum { + PROTO3_FOO = 0; + PROTO3_BAR = 1; + PROTO3_BAZ = 2; +} diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test.proto b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test.proto new file mode 100644 index 0000000000..937ffb89ce --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test.proto @@ -0,0 +1,236 @@ +// 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: mwr@google.com (Mark Rawling) + +syntax = "proto2"; + +option java_package = "com.google.apps.jspb.proto"; +option java_multiple_files = true; + +import "google/protobuf/descriptor.proto"; + +package jspb.test; + +message Empty { +} + +enum OuterEnum { + FOO = 1; + BAR = 2; +} + +message EnumContainer { + optional OuterEnum outer_enum = 1; +} + +message Simple1 { + required string a_string = 1; + repeated string a_repeated_string = 2; + optional bool a_boolean = 3; +} + +// A message that differs from Simple1 only by name +message Simple2 { + required string a_string = 1; + repeated string a_repeated_string = 2; +} + +message SpecialCases { + required string normal = 1; + // Examples of Js reserved names that are converted to pb_. + required string default = 2; + required string function = 3; + required string var = 4; +} + +message OptionalFields { + message Nested { + optional int32 an_int = 1; + } + optional string a_string = 1; + required bool a_bool = 2; + optional Nested a_nested_message = 3; + repeated Nested a_repeated_message = 4; + repeated string a_repeated_string = 5; +} + +message HasExtensions { + optional string str1 = 1; + optional string str2 = 2; + optional string str3 = 3; + extensions 10 to max; +} + +message Complex { + message Nested { + required int32 an_int = 2; + } + required string a_string = 1; + required bool an_out_of_order_bool = 9; + optional Nested a_nested_message = 4; + repeated Nested a_repeated_message = 5; + repeated string a_repeated_string = 7; +} + +message OuterMessage { + // Make sure this doesn't conflict with the other Complex message. + message Complex { + optional int32 inner_complex_field = 1; + } +} + +message IsExtension { + extend HasExtensions { + optional IsExtension ext_field = 100; + } + optional string ext1 = 1; + + // Extensions of proto2 Descriptor messages will be ignored. + extend google.protobuf.EnumOptions { + optional string simple_option = 42113038; + } +} + +message IndirectExtension { + extend HasExtensions { + optional Simple1 simple = 101; + optional string str = 102; + repeated string repeated_str = 103; + repeated Simple1 repeated_simple = 104; + } +} + +extend HasExtensions { + optional Simple1 simple1 = 105; +} + +message DefaultValues { + enum Enum { + E1 = 13; + E2 = 77; + } + optional string string_field = 1 [default="default<>\'\"abc"]; + optional bool bool_field = 2 [default=true]; + optional int64 int_field = 3 [default=11]; + optional Enum enum_field = 4 [default=E1]; + optional string empty_field = 6 [default=""]; + optional bytes bytes_field = 8 [default="moo"]; // Base64 encoding is "bW9v" +} + +message FloatingPointFields { + optional float optional_float_field = 1; + required float required_float_field = 2; + repeated float repeated_float_field = 3; + optional float default_float_field = 4 [default = 2.0]; + optional double optional_double_field = 5; + required double required_double_field = 6; + repeated double repeated_double_field = 7; + optional double default_double_field = 8 [default = 2.0]; +} + +message TestClone { + optional string str = 1; + optional Simple1 simple1 = 3; + repeated Simple1 simple2 = 5; + optional bytes bytes_field = 6; + optional string unused = 7; + extensions 10 to max; +} + +message CloneExtension { + extend TestClone { + optional CloneExtension ext_field = 100; + } + optional string ext = 2; +} + +message TestGroup { + repeated group RepeatedGroup = 1 { + required string id = 1; + repeated bool some_bool = 2; + } + required group RequiredGroup = 2 { + required string id = 1; + } + optional group OptionalGroup = 3 { + required string id = 1; + } + optional string id = 4; + required Simple2 required_simple = 5; + optional Simple2 optional_simple = 6; +} + +message TestGroup1 { + optional TestGroup.RepeatedGroup group = 1; +} + +message TestReservedNames { + optional int32 extension = 1; + extensions 10 to max; +} + +message TestReservedNamesExtension { + extend TestReservedNames { + optional int32 foo = 10; + } +} + +message TestMessageWithOneof { + + oneof partial_oneof { + string pone = 3; + string pthree = 5; + } + + oneof recursive_oneof { + TestMessageWithOneof rone = 6; + string rtwo = 7; + } + + optional bool normal_field = 8; + repeated string repeated_field = 9; + + oneof default_oneof_a { + int32 aone = 10 [default = 1234]; + int32 atwo = 11; + } + + oneof default_oneof_b { + int32 bone = 12; + int32 btwo = 13 [default = 1234]; + } +} + +message TestEndsWithBytes { + optional int32 value = 1; + optional bytes data = 2; +} + diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test.sh b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test.sh new file mode 100755 index 0000000000..9d58f30ac3 --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +set -e + +# Download protoc 3.0.0 from Maven if it is not already present. +OLD_PROTOC_URL=https://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0/protoc-3.0.0-linux-x86_64.exe +if [ ! -f protoc ]; then + wget $OLD_PROTOC_URL -O protoc + chmod +x protoc +fi + +pushd ../.. +npm install && npm test +popd + +old_protoc=./protoc +new_protoc=../../../src/protoc + +# The protos in group 2 have some dependencies on protos in group 1. The tests +# will verify that the generated code for one group can be regenerated +# independently of the other group in a compatible way. +# +# Note: these lists of protos duplicate the lists in gulpfile.js. Ideally we +# should find a good way of having a single source of truth for this. +group1_protos="data.proto test3.proto test5.proto commonjs/test6/test6.proto testbinary.proto testempty.proto test.proto" +group2_protos="proto3_test.proto test2.proto test4.proto commonjs/test7/test7.proto" + +# We test the following cases: +# +# Case 1: build groups 1 and 2 with the old protoc +# Case 2: build group 1 with new protoc but group 2 with old protoc +# Case 3: build group 1 with old protoc but group 2 with new protoc +# +# In each case, we use the current runtime. + +# +# CommonJS tests +# +mkdir -p commonjs_out{1,2,3} +# Case 1 +$old_protoc --js_out=import_style=commonjs,binary:commonjs_out1 -I ../../../src -I commonjs -I . $group1_protos +$old_protoc --js_out=import_style=commonjs,binary:commonjs_out1 -I ../../../src -I commonjs -I . $group2_protos +# Case 2 +$new_protoc --js_out=import_style=commonjs,binary:commonjs_out2 -I ../../../src -I commonjs -I . $group1_protos +$old_protoc --js_out=import_style=commonjs,binary:commonjs_out2 -I ../../../src -I commonjs -I . $group2_protos +# Case 3 +$old_protoc --js_out=import_style=commonjs,binary:commonjs_out3 -I ../../../src -I commonjs -I . $group1_protos +$new_protoc --js_out=import_style=commonjs,binary:commonjs_out3 -I ../../../src -I commonjs -I . $group2_protos + +mkdir -p commonjs_out/binary +for file in *_test.js binary/*_test.js; do + node commonjs/rewrite_tests_for_commonjs.js < "$file" > "commonjs_out/$file" +done +cp commonjs/{jasmine.json,import_test.js} commonjs_out/ +mkdir -p commonjs_out/test_node_modules +../../node_modules/google-closure-library/closure/bin/calcdeps.py -i commonjs/export_asserts.js -p . -p ../../node_modules/google-closure-library/closure -o compiled --compiler_jar ../../node_modules/google-closure-compiler/compiler.jar > commonjs_out/test_node_modules/closure_asserts_commonjs.js +../../node_modules/google-closure-library/closure/bin/calcdeps.py -i commonjs/export_testdeps.js -p ../.. -p ../../node_modules/google-closure-library/closure -o compiled --compiler_jar ../../node_modules/google-closure-compiler/compiler.jar > commonjs_out/test_node_modules/testdeps_commonjs.js +cp ../../google-protobuf.js commonjs_out/test_node_modules +cp -r ../../commonjs_out/node_modules commonjs_out + +echo +echo "Running tests with CommonJS imports" +echo "-----------------------------------" +for i in 1 2 3; do + cp -r commonjs_out/* "commonjs_out$i" + pushd "commonjs_out$i" + JASMINE_CONFIG_PATH=jasmine.json NODE_PATH=test_node_modules ../../../node_modules/.bin/jasmine + popd +done + +# +# Closure tests +# +$old_protoc --js_out=library=testproto_libs1,binary:. -I ../../../src -I commonjs -I . $group1_protos +$old_protoc --js_out=library=testproto_libs2,binary:. -I ../../../src -I commonjs -I . $group2_protos +$new_protoc --js_out=library=testproto_libs1_new,binary:. -I ../../../src -I commonjs -I . $group1_protos +$new_protoc --js_out=library=testproto_libs2_new,binary:. -I ../../../src -I commonjs -I . $group2_protos + +echo +echo "Running tests with Closure-style imports" +echo "----------------------------------------" + +# Case 1 +JASMINE_CONFIG_PATH=jasmine1.json ../../node_modules/.bin/jasmine +# Case 2 +JASMINE_CONFIG_PATH=jasmine2.json ../../node_modules/.bin/jasmine +# Case 3 +JASMINE_CONFIG_PATH=jasmine3.json ../../node_modules/.bin/jasmine + +# Remove these files so that calcdeps.py does not get confused by them the next +# time this script runs. +rm testproto_libs[12]* diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test2.proto b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test2.proto new file mode 100644 index 0000000000..44e55effcb --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test2.proto @@ -0,0 +1,54 @@ +// 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. + +syntax = "proto2"; + +option java_package = "com.google.apps.jspb.proto"; +option java_multiple_files = true; + +package jspb.test; + +message TestExtensionsMessage { + optional int32 intfield = 1; + extensions 100 to max; +} + +message ExtensionMessage { + extend TestExtensionsMessage { + optional ExtensionMessage ext_field = 100; + } + optional string ext1 = 1; +} + +// Floating extensions are only supported when generating a _lib.js library. +extend TestExtensionsMessage { + optional ExtensionMessage floating_msg_field = 101; + optional string floating_str_field = 102; +} diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test3.proto b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test3.proto new file mode 100644 index 0000000000..940a552ed5 --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test3.proto @@ -0,0 +1,53 @@ +// 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. + +syntax = "proto2"; + +option java_package = "com.google.apps.jspb.proto"; +option java_multiple_files = true; + +package jspb.exttest; + +message TestExtensionsMessage { + optional int32 intfield = 1; + extensions 100 to max; +} + +message ExtensionMessage { + extend TestExtensionsMessage { + optional ExtensionMessage ext_field = 100; + } + optional string ext1 = 1; +} + +extend TestExtensionsMessage { + optional ExtensionMessage floating_msg_field = 101; + optional string floating_str_field = 102; +} diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test4.proto b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test4.proto new file mode 100644 index 0000000000..cf2451e9cb --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test4.proto @@ -0,0 +1,42 @@ +// 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. + +syntax = "proto2"; + +option java_package = "com.google.apps.jspb.proto"; +option java_multiple_files = true; + +package jspb.exttest; + +import "test3.proto"; + +extend TestExtensionsMessage { + optional ExtensionMessage floating_msg_field_two = 103; +} diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test5.proto b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test5.proto new file mode 100644 index 0000000000..34979517e5 --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/test5.proto @@ -0,0 +1,44 @@ +// 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. + +syntax = "proto2"; + +option java_package = "com.google.apps.jspb.proto"; +option java_multiple_files = true; + +package jspb.exttest.beta; + +message TestBetaExtensionsMessage { + extensions 100 to max; +} + +extend TestBetaExtensionsMessage { + optional string floating_str_field = 101; +} diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/testbinary.proto b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/testbinary.proto new file mode 100644 index 0000000000..116f17fb50 --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/testbinary.proto @@ -0,0 +1,212 @@ +// 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. + +// LINT: ALLOW_GROUPS + +syntax = "proto2"; + + +package jspb.test; + +// These types are borrowed from `unittest.proto` in the protobuf tree. We want +// to ensure that the binary-format support will handle all field types +// properly. +message TestAllTypes { + optional int32 optional_int32 = 1; + optional int64 optional_int64 = 2; + optional uint32 optional_uint32 = 3; + optional uint64 optional_uint64 = 4; + optional sint32 optional_sint32 = 5; + optional sint64 optional_sint64 = 6; + optional fixed32 optional_fixed32 = 7; + optional fixed64 optional_fixed64 = 8; + optional sfixed32 optional_sfixed32 = 9; + optional sfixed64 optional_sfixed64 = 10; + optional float optional_float = 11; + optional double optional_double = 12; + optional bool optional_bool = 13; + optional string optional_string = 14; + optional bytes optional_bytes = 15; + optional group OptionalGroup = 16 { + optional int32 a = 17; + } + + optional ForeignMessage optional_foreign_message = 19; + optional ForeignEnum optional_foreign_enum = 22; + + // Repeated + repeated int32 repeated_int32 = 31; + repeated int64 repeated_int64 = 32; + repeated uint32 repeated_uint32 = 33; + repeated uint64 repeated_uint64 = 34; + repeated sint32 repeated_sint32 = 35; + repeated sint64 repeated_sint64 = 36; + repeated fixed32 repeated_fixed32 = 37; + repeated fixed64 repeated_fixed64 = 38; + repeated sfixed32 repeated_sfixed32 = 39; + repeated sfixed64 repeated_sfixed64 = 40; + repeated float repeated_float = 41; + repeated double repeated_double = 42; + repeated bool repeated_bool = 43; + repeated string repeated_string = 44; + repeated bytes repeated_bytes = 45; + + repeated group RepeatedGroup = 46 { + optional int32 a = 47; + } + + repeated ForeignMessage repeated_foreign_message = 49; + repeated ForeignEnum repeated_foreign_enum = 52; + + // Packed repeated + repeated int32 packed_repeated_int32 = 61 [packed=true]; + repeated int64 packed_repeated_int64 = 62 [packed=true]; + repeated uint32 packed_repeated_uint32 = 63 [packed=true]; + repeated uint64 packed_repeated_uint64 = 64 [packed=true]; + repeated sint32 packed_repeated_sint32 = 65 [packed=true]; + repeated sint64 packed_repeated_sint64 = 66 [packed=true]; + repeated fixed32 packed_repeated_fixed32 = 67 [packed=true]; + repeated fixed64 packed_repeated_fixed64 = 68 [packed=true]; + repeated sfixed32 packed_repeated_sfixed32 = 69 [packed=true]; + repeated sfixed64 packed_repeated_sfixed64 = 70 [packed=true]; + repeated float packed_repeated_float = 71 [packed=true]; + repeated double packed_repeated_double = 72 [packed=true]; + repeated bool packed_repeated_bool = 73 [packed=true]; + + oneof oneof_field { + uint32 oneof_uint32 = 111; + ForeignMessage oneof_foreign_message = 112; + string oneof_string = 113; + bytes oneof_bytes = 114; + } + +} + +message ForeignMessage { + optional int32 c = 1; +} + +enum ForeignEnum { + FOREIGN_FOO = 4; + FOREIGN_BAR = 5; + FOREIGN_BAZ = 6; +} + +message TestExtendable { + extensions 1 to max; +} + +message ExtendsWithMessage { + extend TestExtendable { + optional ExtendsWithMessage optional_extension = 19; + repeated ExtendsWithMessage repeated_extension = 49; + } + optional int32 foo = 1; +} + +extend TestExtendable { + optional int32 extend_optional_int32 = 1; + optional int64 extend_optional_int64 = 2; + optional uint32 extend_optional_uint32 = 3; + optional uint64 extend_optional_uint64 = 4; + optional sint32 extend_optional_sint32 = 5; + optional sint64 extend_optional_sint64 = 6; + optional fixed32 extend_optional_fixed32 = 7; + optional fixed64 extend_optional_fixed64 = 8; + optional sfixed32 extend_optional_sfixed32 = 9; + optional sfixed64 extend_optional_sfixed64 = 10; + optional float extend_optional_float = 11; + optional double extend_optional_double = 12; + optional bool extend_optional_bool = 13; + optional string extend_optional_string = 14; + optional bytes extend_optional_bytes = 15; + optional ForeignEnum extend_optional_foreign_enum = 22; + + repeated int32 extend_repeated_int32 = 31; + repeated int64 extend_repeated_int64 = 32; + repeated uint32 extend_repeated_uint32 = 33; + repeated uint64 extend_repeated_uint64 = 34; + repeated sint32 extend_repeated_sint32 = 35; + repeated sint64 extend_repeated_sint64 = 36; + repeated fixed32 extend_repeated_fixed32 = 37; + repeated fixed64 extend_repeated_fixed64 = 38; + repeated sfixed32 extend_repeated_sfixed32 = 39; + repeated sfixed64 extend_repeated_sfixed64 = 40; + repeated float extend_repeated_float = 41; + repeated double extend_repeated_double = 42; + repeated bool extend_repeated_bool = 43; + repeated string extend_repeated_string = 44; + repeated bytes extend_repeated_bytes = 45; + repeated ForeignEnum extend_repeated_foreign_enum = 52; + + repeated int32 extend_packed_repeated_int32 = 61 [packed=true]; + repeated int64 extend_packed_repeated_int64 = 62 [packed=true]; + repeated uint32 extend_packed_repeated_uint32 = 63 [packed=true]; + repeated uint64 extend_packed_repeated_uint64 = 64 [packed=true]; + repeated sint32 extend_packed_repeated_sint32 = 65 [packed=true]; + repeated sint64 extend_packed_repeated_sint64 = 66 [packed=true]; + repeated fixed32 extend_packed_repeated_fixed32 = 67 [packed=true]; + repeated fixed64 extend_packed_repeated_fixed64 = 68 [packed=true]; + repeated sfixed32 extend_packed_repeated_sfixed32 = 69 [packed=true]; + repeated sfixed64 extend_packed_repeated_sfixed64 = 70 [packed=true]; + repeated float extend_packed_repeated_float = 71 [packed=true]; + repeated double extend_packed_repeated_double = 72 [packed=true]; + repeated bool extend_packed_repeated_bool = 73 [packed=true]; + repeated ForeignEnum extend_packed_repeated_foreign_enum = 82 + [packed=true]; + +} + +message TestMapFields { + map map_string_string = 1; + map map_string_int32 = 2; + map map_string_int64 = 3; + map map_string_bool = 4; + map map_string_double = 5; + map map_string_enum = 6; + map map_string_msg = 7; + + map map_int32_string = 8; + map map_int64_string = 9; + map map_bool_string = 10; + + optional TestMapFields test_map_fields = 11; + map map_string_testmapfields = 12; +} + +enum MapValueEnum { + MAP_VALUE_FOO = 0; + MAP_VALUE_BAR = 1; + MAP_VALUE_BAZ = 2; +} + +message MapValueMessage { + optional int32 foo = 1; +} diff --git a/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/testempty.proto b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/testempty.proto new file mode 100644 index 0000000000..960bce4e5c --- /dev/null +++ b/third_party/protobuf/3.2.0/js/compatibility_tests/v3.0.0/testempty.proto @@ -0,0 +1,34 @@ +// 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. + +syntax = "proto2"; + +package javatests.com.google.apps.jspb; + diff --git a/third_party/protobuf/3.2.0/js/gulpfile.js b/third_party/protobuf/3.2.0/js/gulpfile.js index 16c302ed67..fc9559f934 100644 --- a/third_party/protobuf/3.2.0/js/gulpfile.js +++ b/third_party/protobuf/3.2.0/js/gulpfile.js @@ -23,8 +23,62 @@ var wellKnownTypes = [ '../src/google/protobuf/wrappers.proto', ]; -gulp.task('genproto_closure', function (cb) { - exec(protoc + ' --js_out=library=testproto_libs,binary:. -I ../src -I . *.proto && ' + protoc + ' --js_out=one_output_file_per_input_file,binary:. -I ../src -I . ' + wellKnownTypes.join(' '), +var group1Protos = [ + 'data.proto', + 'test3.proto', + 'test5.proto', + 'commonjs/test6/test6.proto', + 'test8.proto', + 'testbinary.proto', + 'testempty.proto', + 'test.proto', +]; + +var group2Protos = [ + 'proto3_test.proto', + 'test2.proto', + 'test4.proto', + 'commonjs/test7/test7.proto', +]; + +gulp.task('genproto_well_known_types_closure', function (cb) { + exec(protoc + ' --js_out=one_output_file_per_input_file,binary:. -I ../src -I . ' + wellKnownTypes.join(' '), + function (err, stdout, stderr) { + console.log(stdout); + console.log(stderr); + cb(err); + }); +}); + +gulp.task('genproto_group1_closure', function (cb) { + exec(protoc + ' --js_out=library=testproto_libs1,binary:. -I ../src -I . ' + group1Protos.join(' '), + function (err, stdout, stderr) { + console.log(stdout); + console.log(stderr); + cb(err); + }); +}); + +gulp.task('genproto_group2_closure', function (cb) { + exec(protoc + ' --js_out=library=testproto_libs2,binary:. -I ../src -I . -I commonjs ' + group2Protos.join(' '), + function (err, stdout, stderr) { + console.log(stdout); + console.log(stderr); + cb(err); + }); +}); + +gulp.task('genproto_well_known_types_commonjs', function (cb) { + exec('mkdir -p commonjs_out && ' + protoc + ' --js_out=import_style=commonjs,binary:commonjs_out -I ../src ' + wellKnownTypes.join(' '), + function (err, stdout, stderr) { + console.log(stdout); + console.log(stderr); + cb(err); + }); +}); + +gulp.task('genproto_group1_commonjs', function (cb) { + exec('mkdir -p commonjs_out && ' + protoc + ' --js_out=import_style=commonjs,binary:commonjs_out -I ../src -I commonjs -I . ' + group1Protos.join(' '), function (err, stdout, stderr) { console.log(stdout); console.log(stderr); @@ -32,8 +86,8 @@ gulp.task('genproto_closure', function (cb) { }); }); -gulp.task('genproto_commonjs', function (cb) { - exec('mkdir -p commonjs_out && ' + protoc + ' --js_out=import_style=commonjs,binary:commonjs_out -I ../src -I commonjs -I . *.proto commonjs/test*/*.proto ' + wellKnownTypes.join(' '), +gulp.task('genproto_group2_commonjs', function (cb) { + exec('mkdir -p commonjs_out && ' + protoc + ' --js_out=import_style=commonjs,binary:commonjs_out -I ../src -I commonjs -I . ' + group2Protos.join(' '), function (err, stdout, stderr) { console.log(stdout); console.log(stderr); @@ -105,7 +159,7 @@ gulp.task('commonjs_testdeps', function (cb) { }); }); -gulp.task('make_commonjs_out', ['dist', 'genproto_commonjs', 'genproto_commonjs_wellknowntypes', 'commonjs_asserts', 'commonjs_testdeps'], function (cb) { +gulp.task('make_commonjs_out', ['dist', 'genproto_well_known_types_commonjs', 'genproto_group1_commonjs', 'genproto_group2_commonjs', 'genproto_commonjs_wellknowntypes', 'commonjs_asserts', 'commonjs_testdeps'], function (cb) { // TODO(haberman): minify this more aggressively. // Will require proper externs/exports. var cmd = "mkdir -p commonjs_out/binary && mkdir -p commonjs_out/test_node_modules && "; @@ -128,8 +182,8 @@ gulp.task('make_commonjs_out', ['dist', 'genproto_commonjs', 'genproto_commonjs_ }); }); -gulp.task('deps', ['genproto_closure'], function (cb) { - exec('./node_modules/google-closure-library/closure/bin/build/depswriter.py *.js binary/*.js > deps.js', +gulp.task('deps', ['genproto_well_known_types_closure', 'genproto_group1_closure', 'genproto_group2_closure'], function (cb) { + exec('./node_modules/google-closure-library/closure/bin/build/depswriter.py binary/arith.js binary/constants.js binary/decoder.js binary/encoder.js binary/reader.js binary/utils.js binary/writer.js debug.js map.js message.js node_loader.js test_bootstrap.js > deps.js', function (err, stdout, stderr) { console.log(stdout); console.log(stderr); @@ -137,7 +191,7 @@ gulp.task('deps', ['genproto_closure'], function (cb) { }); }); -gulp.task('test_closure', ['genproto_closure', 'deps'], function (cb) { +gulp.task('test_closure', ['genproto_well_known_types_closure', 'genproto_group1_closure', 'genproto_group2_closure', 'deps'], function (cb) { exec('JASMINE_CONFIG_PATH=jasmine.json ./node_modules/.bin/jasmine', function (err, stdout, stderr) { console.log(stdout); diff --git a/third_party/protobuf/3.2.0/js/jasmine.json b/third_party/protobuf/3.2.0/js/jasmine.json index 093f15794f..aeea72f857 100644 --- a/third_party/protobuf/3.2.0/js/jasmine.json +++ b/third_party/protobuf/3.2.0/js/jasmine.json @@ -10,6 +10,8 @@ "deps.js", "google/protobuf/any.js", "google/protobuf/struct.js", - "google/protobuf/timestamp.js" + "google/protobuf/timestamp.js", + "testproto_libs1.js", + "testproto_libs2.js" ] } diff --git a/third_party/protobuf/3.2.0/js/map.js b/third_party/protobuf/3.2.0/js/map.js index 4f562dbc1e..d423499f05 100644 --- a/third_party/protobuf/3.2.0/js/map.js +++ b/third_party/protobuf/3.2.0/js/map.js @@ -136,7 +136,7 @@ jspb.Map.prototype.toArray = function() { * * @param {boolean=} includeInstance Whether to include the JSPB instance for * transitional soy proto support: http://goto/soy-param-migration - * @param {!function((boolean|undefined),!V):!Object=} valueToObject + * @param {!function((boolean|undefined),V):!Object=} valueToObject * The static toObject() method, if V is a message type. * @return {!Array>} */ @@ -146,7 +146,7 @@ jspb.Map.prototype.toObject = function(includeInstance, valueToObject) { for (var i = 0; i < rawArray.length; i++) { var entry = this.map_[rawArray[i][0].toString()]; this.wrapEntry_(entry); - var valueWrapper = /** @type {!V|undefined} */ (entry.valueWrapper); + var valueWrapper = /** @type {V|undefined} */ (entry.valueWrapper); if (valueWrapper) { goog.asserts.assert(valueToObject); entries.push([entry.key, valueToObject(includeInstance, valueWrapper)]); @@ -412,8 +412,8 @@ jspb.Map.prototype.has = function(key) { * @param {!jspb.BinaryWriter} writer * @param {!function(this:jspb.BinaryWriter,number,K)} keyWriterFn * The method on BinaryWriter that writes type K to the stream. - * @param {!function(this:jspb.BinaryWriter,number,V)| - * function(this:jspb.BinaryReader,V,?)} valueWriterFn + * @param {!function(this:jspb.BinaryWriter,number,V,?=)| + * function(this:jspb.BinaryWriter,number,V,?)} valueWriterFn * The method on BinaryWriter that writes type V to the stream. May be * writeMessage, in which case the second callback arg form is used. * @param {function(V,!jspb.BinaryWriter)=} opt_valueWriterCallback @@ -509,7 +509,7 @@ jspb.Map.prototype.stringKeys_ = function() { /** - * @param {!K} key The entry's key. + * @param {K} key The entry's key. * @param {V=} opt_value The entry's value wrapper. * @constructor * @struct diff --git a/third_party/protobuf/3.2.0/js/message.js b/third_party/protobuf/3.2.0/js/message.js index 220a5bdb7e..1f6bf16b6e 100644 --- a/third_party/protobuf/3.2.0/js/message.js +++ b/third_party/protobuf/3.2.0/js/message.js @@ -106,8 +106,9 @@ jspb.ExtensionFieldInfo = function(fieldNumber, fieldName, ctor, toObjectFn, /** * Stores binary-related information for a single extension field. * @param {!jspb.ExtensionFieldInfo} fieldInfo - * @param {!function(number,?)} binaryReaderFn - * @param {!function(number,?)|function(number,?,?,?,?,?)} binaryWriterFn + * @param {function(this:jspb.BinaryReader,number,?)} binaryReaderFn + * @param {function(this:jspb.BinaryWriter,number,?) + * |function(this:jspb.BinaryWriter,number,?,?,?,?,?)} binaryWriterFn * @param {function(?,?)=} opt_binaryMessageSerializeFn * @param {function(?,?)=} opt_binaryMessageDeserializeFn * @param {boolean=} opt_isPacked @@ -141,6 +142,21 @@ jspb.ExtensionFieldInfo.prototype.isMessageType = function() { /** * Base class for all JsPb messages. + * + * Several common methods (toObject, serializeBinary, in particular) are not + * defined on the prototype to encourage code patterns that minimize code bloat + * due to otherwise unused code on all protos contained in the project. + * + * If you want to call these methods on a generic message, either + * pass in your instance of method as a parameter: + * someFunction(instanceOfKnownProto, + * KnownProtoClass.prototype.serializeBinary); + * or use a lambda that knows the type: + * someFunction(()=>instanceOfKnownProto.serializeBinary()); + * or, if you don't care about code size, just suppress the + * WARNING - Property serializeBinary never defined on jspb.Message + * and call it the intuitive way. + * * @constructor * @struct */ @@ -524,7 +540,7 @@ jspb.Message.toObjectExtension = function(proto, obj, extensions, * @param {!jspb.Message} proto The proto whose extensions to convert. * @param {*} writer The binary-format writer to write to. * @param {!Object} extensions The proto class' registered extensions. - * @param {function(jspb.ExtensionFieldInfo) : *} getExtensionFn The proto + * @param {function(this:jspb.Message,!jspb.ExtensionFieldInfo) : *} getExtensionFn The proto * class' getExtension function. Passed for effective dead code removal. */ jspb.Message.serializeBinaryExtensions = function(proto, writer, extensions, @@ -570,10 +586,13 @@ jspb.Message.serializeBinaryExtensions = function(proto, writer, extensions, * Reads an extension field from the given reader and, if a valid extension, * sets the extension value. * @param {!jspb.Message} msg A jspb proto. - * @param {{skipField:function(),getFieldNumber:function():number}} reader + * @param {{ + * skipField:function(this:jspb.BinaryReader), + * getFieldNumber:function(this:jspb.BinaryReader):number + * }} reader * @param {!Object} extensions The extensions object. - * @param {function(jspb.ExtensionFieldInfo)} getExtensionFn - * @param {function(jspb.ExtensionFieldInfo, ?)} setExtensionFn + * @param {function(this:jspb.Message,!jspb.ExtensionFieldInfo)} getExtensionFn + * @param {function(this:jspb.Message,!jspb.ExtensionFieldInfo, ?)} setExtensionFn */ jspb.Message.readBinaryExtension = function(msg, reader, extensions, getExtensionFn, setExtensionFn) { diff --git a/third_party/protobuf/3.2.0/js/message_test.js b/third_party/protobuf/3.2.0/js/message_test.js index 2298742d77..dc0ae211ba 100644 --- a/third_party/protobuf/3.2.0/js/message_test.js +++ b/third_party/protobuf/3.2.0/js/message_test.js @@ -40,6 +40,7 @@ goog.require('goog.userAgent'); goog.require('jspb.Message'); // CommonJS-LoadFromFile: test8_pb proto.jspb.exttest.nested +goog.require('proto.jspb.exttest.nested.TestNestedExtensionsMessage'); goog.require('proto.jspb.exttest.nested.TestOuterMessage'); // CommonJS-LoadFromFile: test5_pb proto.jspb.exttest.beta diff --git a/third_party/protobuf/3.2.0/js/package.json b/third_party/protobuf/3.2.0/js/package.json index dd6373de0d..14f54b8bfd 100644 --- a/third_party/protobuf/3.2.0/js/package.json +++ b/third_party/protobuf/3.2.0/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.2.0", + "version": "3.3.0", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/third_party/protobuf/3.2.0/libprotobuf_java.jar b/third_party/protobuf/3.2.0/libprotobuf_java.jar new file mode 100755 index 0000000000..3004c2982e Binary files /dev/null and b/third_party/protobuf/3.2.0/libprotobuf_java.jar differ diff --git a/third_party/protobuf/3.2.0/libprotobuf_java_util.jar b/third_party/protobuf/3.2.0/libprotobuf_java_util.jar new file mode 100755 index 0000000000..befce6b881 Binary files /dev/null and b/third_party/protobuf/3.2.0/libprotobuf_java_util.jar differ diff --git a/third_party/protobuf/3.2.0/objectivec/DevTools/full_mac_build.sh b/third_party/protobuf/3.2.0/objectivec/DevTools/full_mac_build.sh index ea9fd2736b..c3cc8e6826 100755 --- a/third_party/protobuf/3.2.0/objectivec/DevTools/full_mac_build.sh +++ b/third_party/protobuf/3.2.0/objectivec/DevTools/full_mac_build.sh @@ -273,6 +273,14 @@ if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then -destination "platform=iOS Simulator,name=iPad Pro (9.7 inch),OS=10.2" # 64bit ) ;; + 8.3* ) + XCODEBUILD_TEST_BASE_IOS+=( + -destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit + -destination "platform=iOS Simulator,name=iPhone 7,OS=10.3" # 64bit + -destination "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit + -destination "platform=iOS Simulator,name=iPad Pro (9.7 inch),OS=10.3" # 64bit + ) + ;; * ) echo "Time to update the simulator targets for Xcode ${XCODE_VERSION}" exit 2 diff --git a/third_party/protobuf/3.2.0/objectivec/GPBMessage.m b/third_party/protobuf/3.2.0/objectivec/GPBMessage.m index 58a10fdb9b..627a396e54 100644 --- a/third_party/protobuf/3.2.0/objectivec/GPBMessage.m +++ b/third_party/protobuf/3.2.0/objectivec/GPBMessage.m @@ -130,7 +130,7 @@ static NSError *ErrorFromException(NSException *exception) { static void CheckExtension(GPBMessage *self, GPBExtensionDescriptor *extension) { - if ([self class] != extension.containingMessageClass) { + if (![self isKindOfClass:extension.containingMessageClass]) { [NSException raise:NSInvalidArgumentException format:@"Extension %@ used on wrong class (%@ instead of %@)", @@ -738,6 +738,25 @@ void GPBClearMessageAutocreator(GPBMessage *self) { self->autocreatorExtension_ = nil; } +// Call this before using the readOnlySemaphore_. This ensures it is created only once. +void GPBPrepareReadOnlySemaphore(GPBMessage *self) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdirect-ivar-access" +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + + // Create the semaphore on demand (rather than init) as developers might not cause them + // to be needed, and the heap usage can add up. The atomic swap is used to avoid needing + // another lock around creating it. + if (self->readOnlySemaphore_ == nil) { + dispatch_semaphore_t worker = dispatch_semaphore_create(1); + if (!OSAtomicCompareAndSwapPtrBarrier(NULL, worker, (void * volatile *)&(self->readOnlySemaphore_))) { + dispatch_release(worker); + } + } + +#pragma clang diagnostic pop +} + static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { if (!self->unknownFields_) { self->unknownFields_ = [[GPBUnknownFieldSet alloc] init]; @@ -3170,7 +3189,7 @@ static void ResolveIvarSet(GPBFieldDescriptor *field, + (BOOL)resolveClassMethod:(SEL)sel { // Extensions scoped to a Message and looked up via class methods. - if (GPBResolveExtensionClassMethod(self, sel)) { + if (GPBResolveExtensionClassMethod([self descriptor].messageClass, sel)) { return YES; } return [super resolveClassMethod:sel]; diff --git a/third_party/protobuf/3.2.0/objectivec/GPBMessage_PackagePrivate.h b/third_party/protobuf/3.2.0/objectivec/GPBMessage_PackagePrivate.h index 9324cf8d5e..90834d4073 100644 --- a/third_party/protobuf/3.2.0/objectivec/GPBMessage_PackagePrivate.h +++ b/third_party/protobuf/3.2.0/objectivec/GPBMessage_PackagePrivate.h @@ -70,7 +70,6 @@ typedef struct GPBMessage_Storage *GPBMessage_StoragePtr; // Use of readOnlySemaphore_ must be prefaced by a call to // GPBPrepareReadOnlySemaphore to ensure it has been created. This allows // readOnlySemaphore_ to be only created when actually needed. - dispatch_once_t readOnlySemaphoreCreationOnce_; dispatch_semaphore_t readOnlySemaphore_; } @@ -105,22 +104,7 @@ CF_EXTERN_C_BEGIN // Call this before using the readOnlySemaphore_. This ensures it is created only once. -NS_INLINE void GPBPrepareReadOnlySemaphore(GPBMessage *self) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdirect-ivar-access" - -// Starting on Xcode 8.3, the static analyzer complains that the dispatch_once_t -// variable passed to dispatch_once should not be allocated on the heap or -// stack. Given that the semaphore is also an instance variable of the message, -// both variables are cleared at the same time, so this is safe. -#if !defined(__clang_analyzer__) - dispatch_once(&self->readOnlySemaphoreCreationOnce_, ^{ - self->readOnlySemaphore_ = dispatch_semaphore_create(1); - }); -#endif // !defined(__clang_analyzer__) - -#pragma clang diagnostic pop -} +void GPBPrepareReadOnlySemaphore(GPBMessage *self); // Returns a new instance that was automatically created by |autocreator| for // its field |field|. diff --git a/third_party/protobuf/3.2.0/objectivec/google/protobuf/Duration.pbobjc.h b/third_party/protobuf/3.2.0/objectivec/google/protobuf/Duration.pbobjc.h index e70138a01e..d9a388ac1b 100644 --- a/third_party/protobuf/3.2.0/objectivec/google/protobuf/Duration.pbobjc.h +++ b/third_party/protobuf/3.2.0/objectivec/google/protobuf/Duration.pbobjc.h @@ -59,6 +59,8 @@ typedef GPB_ENUM(GPBDuration_FieldNumber) { * two Timestamp values is a Duration and it can be added or subtracted * from a Timestamp. Range is approximately +-10,000 years. * + * # Examples + * * Example 1: Compute Duration from two Timestamps in pseudo code. * * Timestamp start = ...; @@ -98,12 +100,23 @@ typedef GPB_ENUM(GPBDuration_FieldNumber) { * td = datetime.timedelta(days=3, minutes=10) * duration = Duration() * duration.FromTimedelta(td) + * + * # JSON Mapping + * + * In JSON format, the Duration type is encoded as a string rather than an + * object, where the string ends in the suffix "s" (indicating seconds) and + * is preceded by the number of seconds, with nanoseconds expressed as + * fractional seconds. For example, 3 seconds with 0 nanoseconds should be + * encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should + * be expressed in JSON format as "3.000000001s", and 3 seconds and 1 + * microsecond should be expressed in JSON format as "3.000001s". **/ @interface GPBDuration : GPBMessage /** * Signed seconds of the span of time. Must be from -315,576,000,000 - * to +315,576,000,000 inclusive. + * to +315,576,000,000 inclusive. Note: these bounds are computed from: + * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years **/ @property(nonatomic, readwrite) int64_t seconds; diff --git a/third_party/protobuf/3.2.0/objectivec/google/protobuf/Timestamp.pbobjc.h b/third_party/protobuf/3.2.0/objectivec/google/protobuf/Timestamp.pbobjc.h index 9c83d0945e..5d74bd3274 100644 --- a/third_party/protobuf/3.2.0/objectivec/google/protobuf/Timestamp.pbobjc.h +++ b/third_party/protobuf/3.2.0/objectivec/google/protobuf/Timestamp.pbobjc.h @@ -64,6 +64,8 @@ typedef GPB_ENUM(GPBTimestamp_FieldNumber) { * and from RFC 3339 date strings. * See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt). * + * # Examples + * * Example 1: Compute Timestamp from POSIX `time()`. * * Timestamp timestamp; @@ -103,6 +105,29 @@ typedef GPB_ENUM(GPBTimestamp_FieldNumber) { * * timestamp = Timestamp() * timestamp.GetCurrentTime() + * + * # JSON Mapping + * + * In JSON format, the Timestamp type is encoded as a string in the + * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the + * format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" + * where {year} is always expressed using four digits while {month}, {day}, + * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional + * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), + * are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone + * is required, though only UTC (as indicated by "Z") is presently supported. + * + * For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past + * 01:30 UTC on January 15, 2017. + * + * In JavaScript, one can convert a Date object to this format using the + * standard [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString] + * method. In Python, a standard `datetime.datetime` object can be converted + * to this format using [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) + * with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one + * can use the Joda Time's [`ISODateTimeFormat.dateTime()`]( + * http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime()) + * to obtain a formatter capable of generating timestamps in this format. **/ @interface GPBTimestamp : GPBMessage diff --git a/third_party/protobuf/3.2.0/php/ext/google/protobuf/array.c b/third_party/protobuf/3.2.0/php/ext/google/protobuf/array.c index 2186ab1f5d..e9f5f156ff 100644 --- a/third_party/protobuf/3.2.0/php/ext/google/protobuf/array.c +++ b/third_party/protobuf/3.2.0/php/ext/google/protobuf/array.c @@ -69,19 +69,20 @@ static zend_function_entry repeated_field_iter_methods[] = { // Forward declare static functions. -static zend_object_value repeated_field_create(zend_class_entry *ce TSRMLS_DC); -static void repeated_field_free(void *object TSRMLS_DC); static int repeated_field_array_init(zval *array, upb_fieldtype_t type, uint size ZEND_FILE_LINE_DC); -static void repeated_field_free_element(void *object); static void repeated_field_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC); static int repeated_field_has_dimension(zval *object, zval *offset TSRMLS_DC); -static HashTable *repeated_field_get_gc(zval *object, zval ***table, +static HashTable *repeated_field_get_gc(zval *object, CACHED_VALUE **table, int *n TSRMLS_DC); - +#if PHP_MAJOR_VERSION < 7 +static zend_object_value repeated_field_create(zend_class_entry *ce TSRMLS_DC); static zend_object_value repeated_field_iter_create(zend_class_entry *ce TSRMLS_DC); -static void repeated_field_iter_free(void *object TSRMLS_DC); +#else +static zend_object *repeated_field_create(zend_class_entry *ce TSRMLS_DC); +static zend_object *repeated_field_iter_create(zend_class_entry *ce TSRMLS_DC); +#endif // ----------------------------------------------------------------------------- // RepeatedField creation/desctruction @@ -90,76 +91,91 @@ static void repeated_field_iter_free(void *object TSRMLS_DC); zend_class_entry* repeated_field_type; zend_class_entry* repeated_field_iter_type; zend_object_handlers* repeated_field_handlers; - -void repeated_field_init(TSRMLS_D) { - zend_class_entry class_type; - const char* class_name = "Google\\Protobuf\\Internal\\RepeatedField"; - INIT_CLASS_ENTRY_EX(class_type, class_name, strlen(class_name), - repeated_field_methods); - - repeated_field_type = zend_register_internal_class(&class_type TSRMLS_CC); - repeated_field_type->create_object = repeated_field_create; - - zend_class_implements(repeated_field_type TSRMLS_CC, 3, spl_ce_ArrayAccess, - zend_ce_aggregate, spl_ce_Countable); - - repeated_field_handlers = PEMALLOC(zend_object_handlers); - memcpy(repeated_field_handlers, zend_get_std_object_handlers(), - sizeof(zend_object_handlers)); - repeated_field_handlers->write_dimension = repeated_field_write_dimension; - repeated_field_handlers->get_gc = repeated_field_get_gc; +zend_object_handlers* repeated_field_iter_handlers; + +// Define object free method. +PHP_PROTO_OBJECT_FREE_START(RepeatedField, repeated_field) +#if PHP_MAJOR_VERSION < 7 +php_proto_zval_ptr_dtor(intern->array); +#else +php_proto_zval_ptr_dtor(&intern->array); +#endif +PHP_PROTO_OBJECT_FREE_END + +PHP_PROTO_OBJECT_DTOR_START(RepeatedField, repeated_field) +PHP_PROTO_OBJECT_DTOR_END + +// Define object create method. +PHP_PROTO_OBJECT_CREATE_START(RepeatedField, repeated_field) +#if PHP_MAJOR_VERSION < 7 +intern->array = NULL; +#endif +intern->type = 0; +intern->msg_ce = NULL; +PHP_PROTO_OBJECT_CREATE_END(RepeatedField, repeated_field) + +// Init class entry. +PHP_PROTO_INIT_CLASS_START("Google\\Protobuf\\Internal\\RepeatedField", + RepeatedField, repeated_field) +zend_class_implements(repeated_field_type TSRMLS_CC, 3, spl_ce_ArrayAccess, + zend_ce_aggregate, spl_ce_Countable); +repeated_field_handlers->write_dimension = repeated_field_write_dimension; +repeated_field_handlers->get_gc = repeated_field_get_gc; +PHP_PROTO_INIT_CLASS_END + +// Define array element free function. +#if PHP_MAJOR_VERSION < 7 +static inline void php_proto_array_string_release(void *value) { + zval_ptr_dtor(value); } -static zend_object_value repeated_field_create(zend_class_entry *ce TSRMLS_DC) { - zend_object_value retval = {0}; - RepeatedField *intern; - - intern = emalloc(sizeof(RepeatedField)); - memset(intern, 0, sizeof(RepeatedField)); - - zend_object_std_init(&intern->std, ce TSRMLS_CC); - object_properties_init(&intern->std, ce); - - intern->array = NULL; - intern->type = 0; - intern->msg_ce = NULL; - - retval.handle = zend_objects_store_put( - intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)repeated_field_free, NULL TSRMLS_CC); - retval.handlers = repeated_field_handlers; - - return retval; +static inline void php_proto_array_object_release(void *value) { + zval_ptr_dtor(value); } - -static void repeated_field_free(void *object TSRMLS_DC) { - RepeatedField *intern = object; - zend_object_std_dtor(&intern->std TSRMLS_CC); - zval_ptr_dtor(&intern->array); - efree(object); +static inline void php_proto_array_default_release(void *value) { +} +#else +static inline void php_proto_array_string_release(zval *value) { + void* ptr = Z_PTR_P(value); + zend_string* object = *(zend_string**)ptr; + zend_string_release(object); + efree(ptr); +} +static inline void php_proto_array_object_release(zval *value) { + void* ptr = Z_PTR_P(value); + zend_object* object = *(zend_object**)ptr; + if(--GC_REFCOUNT(object) == 0) { + zend_objects_store_del(object); + } + efree(ptr); } +static void php_proto_array_default_release(zval* value) { + void* ptr = Z_PTR_P(value); + efree(ptr); +} +#endif static int repeated_field_array_init(zval *array, upb_fieldtype_t type, uint size ZEND_FILE_LINE_DC) { - ALLOC_HASHTABLE(Z_ARRVAL_P(array)); + PHP_PROTO_ALLOC_ARRAY(array); switch (type) { case UPB_TYPE_STRING: case UPB_TYPE_BYTES: + zend_hash_init(Z_ARRVAL_P(array), size, NULL, + php_proto_array_string_release, 0); + break; case UPB_TYPE_MESSAGE: - zend_hash_init(Z_ARRVAL_P(array), size, NULL, ZVAL_PTR_DTOR, 0); + zend_hash_init(Z_ARRVAL_P(array), size, NULL, + php_proto_array_object_release, 0); break; default: - zend_hash_init(Z_ARRVAL_P(array), size, NULL, repeated_field_free_element, - 0); + zend_hash_init(Z_ARRVAL_P(array), size, NULL, + php_proto_array_default_release, 0); } - Z_TYPE_P(array) = IS_ARRAY; return SUCCESS; } -static void repeated_field_free_element(void *object) { -} - // ----------------------------------------------------------------------------- // RepeatedField Handlers // ----------------------------------------------------------------------------- @@ -168,23 +184,25 @@ static void repeated_field_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC) { uint64_t index; - RepeatedField *intern = zend_object_store_get_object(object TSRMLS_CC); - HashTable *ht = HASH_OF(intern->array); + RepeatedField *intern = UNBOX(RepeatedField, object); + HashTable *ht = PHP_PROTO_HASH_OF(intern->array); int size = native_slot_size(intern->type); unsigned char memory[NATIVE_SLOT_MAX_SIZE]; memset(memory, 0, NATIVE_SLOT_MAX_SIZE); - if (!native_slot_set(intern->type, intern->msg_ce, memory, value TSRMLS_CC)) { + if (!native_slot_set_by_array(intern->type, intern->msg_ce, memory, + value TSRMLS_CC)) { return; } if (!offset || Z_TYPE_P(offset) == IS_NULL) { - index = zend_hash_num_elements(HASH_OF(intern->array)); + index = zend_hash_num_elements(PHP_PROTO_HASH_OF(intern->array)); } else { if (protobuf_convert_to_uint64(offset, &index)) { if (!zend_hash_index_exists(ht, index)) { - zend_error(E_USER_ERROR, "Element at %llu doesn't exist.\n", index); + zend_error(E_USER_ERROR, "Element at %llu doesn't exist.\n", + (long long unsigned int)index); return; } } else { @@ -192,15 +210,19 @@ static void repeated_field_write_dimension(zval *object, zval *offset, } } - zend_hash_index_update(ht, index, memory, size, NULL); + php_proto_zend_hash_index_update(ht, index, memory, size, NULL); } +#if PHP_MAJOR_VERSION < 7 static HashTable *repeated_field_get_gc(zval *object, zval ***table, int *n TSRMLS_DC) { +#else +static HashTable *repeated_field_get_gc(zval *object, zval **table, int *n) { +#endif *table = NULL; *n = 0; - RepeatedField *intern = zend_object_store_get_object(object TSRMLS_CC); - return HASH_OF(intern->array); + RepeatedField *intern = UNBOX(RepeatedField, object); + return PHP_PROTO_HASH_OF(intern->array); } // ----------------------------------------------------------------------------- @@ -208,10 +230,10 @@ static HashTable *repeated_field_get_gc(zval *object, zval ***table, // ----------------------------------------------------------------------------- void *repeated_field_index_native(RepeatedField *intern, int index TSRMLS_DC) { - HashTable *ht = HASH_OF(intern->array); + HashTable *ht = PHP_PROTO_HASH_OF(intern->array); void *value; - if (zend_hash_index_find(ht, index, (void **)&value) == FAILURE) { + if (php_proto_zend_hash_index_find(ht, index, (void **)&value) == FAILURE) { zend_error(E_USER_ERROR, "Element at %d doesn't exist.\n", index); return NULL; } @@ -219,35 +241,37 @@ void *repeated_field_index_native(RepeatedField *intern, int index TSRMLS_DC) { return value; } -void repeated_field_push_native(RepeatedField *intern, void *value TSRMLS_DC) { - HashTable *ht = HASH_OF(intern->array); +void repeated_field_push_native(RepeatedField *intern, void *value) { + HashTable *ht = PHP_PROTO_HASH_OF(intern->array); int size = native_slot_size(intern->type); - zend_hash_next_index_insert(ht, (void **)value, size, NULL); + php_proto_zend_hash_next_index_insert(ht, (void **)value, size, NULL); } -void repeated_field_create_with_field(zend_class_entry *ce, - const upb_fielddef *field, - zval **repeated_field TSRMLS_DC) { +void repeated_field_create_with_field( + zend_class_entry *ce, const upb_fielddef *field, + CACHED_VALUE *repeated_field PHP_PROTO_TSRMLS_DC) { upb_fieldtype_t type = upb_fielddef_type(field); - const zend_class_entry *msg_ce = field_type_class(field TSRMLS_CC); - repeated_field_create_with_type(ce, type, msg_ce, repeated_field TSRMLS_CC); + const zend_class_entry *msg_ce = field_type_class(field PHP_PROTO_TSRMLS_CC); + repeated_field_create_with_type(ce, type, msg_ce, + repeated_field PHP_PROTO_TSRMLS_CC); } -void repeated_field_create_with_type(zend_class_entry *ce, - upb_fieldtype_t type, - const zend_class_entry* msg_ce, - zval **repeated_field TSRMLS_DC) { - MAKE_STD_ZVAL(*repeated_field); - Z_TYPE_PP(repeated_field) = IS_OBJECT; - Z_OBJVAL_PP(repeated_field) = - repeated_field_type->create_object(repeated_field_type TSRMLS_CC); +void repeated_field_create_with_type( + zend_class_entry *ce, upb_fieldtype_t type, const zend_class_entry *msg_ce, + CACHED_VALUE *repeated_field PHP_PROTO_TSRMLS_DC) { + CREATE_OBJ_ON_ALLOCATED_ZVAL_PTR(CACHED_PTR_TO_ZVAL_PTR(repeated_field), + repeated_field_type); RepeatedField *intern = - zend_object_store_get_object(*repeated_field TSRMLS_CC); + UNBOX(RepeatedField, CACHED_TO_ZVAL_PTR(*repeated_field)); intern->type = type; intern->msg_ce = msg_ce; +#if PHP_MAJOR_VERSION < 7 MAKE_STD_ZVAL(intern->array); repeated_field_array_init(intern->array, intern->type, 0 ZEND_FILE_LINE_CC); +#else + repeated_field_array_init(&intern->array, intern->type, 0 ZEND_FILE_LINE_CC); +#endif // TODO(teboring): Link class entry for message and enum } @@ -271,12 +295,16 @@ PHP_METHOD(RepeatedField, __construct) { return; } - RepeatedField *intern = zend_object_store_get_object(getThis() TSRMLS_CC); + RepeatedField *intern = UNBOX(RepeatedField, getThis()); intern->type = to_fieldtype(type); intern->msg_ce = klass; +#if PHP_MAJOR_VERSION < 7 MAKE_STD_ZVAL(intern->array); repeated_field_array_init(intern->array, intern->type, 0 ZEND_FILE_LINE_CC); +#else + repeated_field_array_init(&intern->array, intern->type, 0 ZEND_FILE_LINE_CC); +#endif if (intern->type == UPB_TYPE_MESSAGE && klass == NULL) { zend_error(E_USER_ERROR, "Message type must have concrete class."); @@ -313,10 +341,10 @@ PHP_METHOD(RepeatedField, offsetExists) { return; } - RepeatedField *intern = zend_object_store_get_object(getThis() TSRMLS_CC); + RepeatedField *intern = UNBOX(RepeatedField, getThis()); RETURN_BOOL(index >= 0 && - index < zend_hash_num_elements(HASH_OF(intern->array))); + index < zend_hash_num_elements(PHP_PROTO_HASH_OF(intern->array))); } /** @@ -336,15 +364,16 @@ PHP_METHOD(RepeatedField, offsetGet) { return; } - RepeatedField *intern = zend_object_store_get_object(getThis() TSRMLS_CC); - HashTable *table = HASH_OF(intern->array); + RepeatedField *intern = UNBOX(RepeatedField, getThis()); + HashTable *table = PHP_PROTO_HASH_OF(intern->array); - if (zend_hash_index_find(table, index, (void **)&memory) == FAILURE) { + if (php_proto_zend_hash_index_find(table, index, (void **)&memory) == FAILURE) { zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index); return; } - native_slot_get(intern->type, memory, return_value_ptr TSRMLS_CC); + native_slot_get_by_array(intern->type, memory, + ZVAL_PTR_TO_CACHED_PTR(return_value) TSRMLS_CC); } /** @@ -379,16 +408,16 @@ PHP_METHOD(RepeatedField, offsetUnset) { return; } - RepeatedField *intern = zend_object_store_get_object(getThis() TSRMLS_CC); + RepeatedField *intern = UNBOX(RepeatedField, getThis()); // Only the element at the end of the array can be removed. if (index == -1 || - index != (zend_hash_num_elements(HASH_OF(intern->array)) - 1)) { + index != (zend_hash_num_elements(PHP_PROTO_HASH_OF(intern->array)) - 1)) { zend_error(E_USER_ERROR, "Cannot remove element at %ld.\n", index); return; } - zend_hash_index_del(HASH_OF(intern->array), index); + zend_hash_index_del(PHP_PROTO_HASH_OF(intern->array), index); } /** @@ -397,13 +426,13 @@ PHP_METHOD(RepeatedField, offsetUnset) { * @return long The number of stored elements. */ PHP_METHOD(RepeatedField, count) { - RepeatedField *intern = zend_object_store_get_object(getThis() TSRMLS_CC); + RepeatedField *intern = UNBOX(RepeatedField, getThis()); if (zend_parse_parameters_none() == FAILURE) { return; } - RETURN_LONG(zend_hash_num_elements(HASH_OF(intern->array))); + RETURN_LONG(zend_hash_num_elements(PHP_PROTO_HASH_OF(intern->array))); } /** @@ -412,105 +441,77 @@ PHP_METHOD(RepeatedField, count) { * @return object Beginning iterator. */ PHP_METHOD(RepeatedField, getIterator) { - zval *iter_php = NULL; - MAKE_STD_ZVAL(iter_php); - Z_TYPE_P(iter_php) = IS_OBJECT; - Z_OBJVAL_P(iter_php) = repeated_field_iter_type->create_object( - repeated_field_iter_type TSRMLS_CC); - - RepeatedField *intern = zend_object_store_get_object(getThis() TSRMLS_CC); - RepeatedFieldIter *iter = zend_object_store_get_object(iter_php TSRMLS_CC); + CREATE_OBJ_ON_ALLOCATED_ZVAL_PTR(return_value, + repeated_field_iter_type); + + RepeatedField *intern = UNBOX(RepeatedField, getThis()); + RepeatedFieldIter *iter = UNBOX(RepeatedFieldIter, return_value); iter->repeated_field = intern; iter->position = 0; - - RETURN_ZVAL(iter_php, 1, 1); } // ----------------------------------------------------------------------------- // RepeatedFieldIter creation/desctruction // ----------------------------------------------------------------------------- -void repeated_field_iter_init(TSRMLS_D) { - zend_class_entry class_type; - const char* class_name = "Google\\Protobuf\\Internal\\RepeatedFieldIter"; - INIT_CLASS_ENTRY_EX(class_type, class_name, strlen(class_name), - repeated_field_iter_methods); - - repeated_field_iter_type = - zend_register_internal_class(&class_type TSRMLS_CC); - repeated_field_iter_type->create_object = repeated_field_iter_create; - - zend_class_implements(repeated_field_iter_type TSRMLS_CC, 1, - zend_ce_iterator); -} - -static zend_object_value repeated_field_iter_create( - zend_class_entry *ce TSRMLS_DC) { - zend_object_value retval = {0}; - RepeatedFieldIter *intern; - - intern = emalloc(sizeof(RepeatedFieldIter)); - memset(intern, 0, sizeof(RepeatedFieldIter)); - - zend_object_std_init(&intern->std, ce TSRMLS_CC); - object_properties_init(&intern->std, ce); +// Define object free method. +PHP_PROTO_OBJECT_FREE_START(RepeatedFieldIter, repeated_field_iter) +PHP_PROTO_OBJECT_FREE_END - intern->repeated_field = NULL; - intern->position = 0; - - retval.handle = zend_objects_store_put( - intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)repeated_field_iter_free, - NULL TSRMLS_CC); - retval.handlers = zend_get_std_object_handlers(); +PHP_PROTO_OBJECT_DTOR_START(RepeatedFieldIter, repeated_field_iter) +PHP_PROTO_OBJECT_DTOR_END - return retval; -} +// Define object create method. +PHP_PROTO_OBJECT_CREATE_START(RepeatedFieldIter, repeated_field_iter) +intern->repeated_field = NULL; +intern->position = 0; +PHP_PROTO_OBJECT_CREATE_END(RepeatedFieldIter, repeated_field_iter) -static void repeated_field_iter_free(void *object TSRMLS_DC) { - RepeatedFieldIter *intern = object; - zend_object_std_dtor(&intern->std TSRMLS_CC); - efree(object); -} +// Init class entry. +PHP_PROTO_INIT_CLASS_START("Google\\Protobuf\\Internal\\RepeatedFieldIter", + RepeatedFieldIter, repeated_field_iter) +zend_class_implements(repeated_field_iter_type TSRMLS_CC, 1, zend_ce_iterator); +PHP_PROTO_INIT_CLASS_END // ----------------------------------------------------------------------------- // PHP RepeatedFieldIter Methods // ----------------------------------------------------------------------------- PHP_METHOD(RepeatedFieldIter, rewind) { - RepeatedFieldIter *intern = zend_object_store_get_object(getThis() TSRMLS_CC); + RepeatedFieldIter *intern = UNBOX(RepeatedFieldIter, getThis()); intern->position = 0; } PHP_METHOD(RepeatedFieldIter, current) { - RepeatedFieldIter *intern = zend_object_store_get_object(getThis() TSRMLS_CC); + RepeatedFieldIter *intern = UNBOX(RepeatedFieldIter, getThis()); RepeatedField *repeated_field = intern->repeated_field; long index; void *memory; - HashTable *table = HASH_OF(repeated_field->array); + HashTable *table = PHP_PROTO_HASH_OF(repeated_field->array); - if (zend_hash_index_find(table, intern->position, (void **)&memory) == + if (php_proto_zend_hash_index_find(table, intern->position, (void **)&memory) == FAILURE) { zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index); return; } - native_slot_get(repeated_field->type, memory, return_value_ptr TSRMLS_CC); + native_slot_get_by_array(repeated_field->type, memory, + ZVAL_PTR_TO_CACHED_PTR(return_value) TSRMLS_CC); } PHP_METHOD(RepeatedFieldIter, key) { - RepeatedFieldIter *intern = zend_object_store_get_object(getThis() TSRMLS_CC); + RepeatedFieldIter *intern = UNBOX(RepeatedFieldIter, getThis()); RETURN_LONG(intern->position); } PHP_METHOD(RepeatedFieldIter, next) { - RepeatedFieldIter *intern = zend_object_store_get_object(getThis() TSRMLS_CC); + RepeatedFieldIter *intern = UNBOX(RepeatedFieldIter, getThis()); ++intern->position; } PHP_METHOD(RepeatedFieldIter, valid) { - RepeatedFieldIter *intern = zend_object_store_get_object(getThis() TSRMLS_CC); - RETURN_BOOL(zend_hash_num_elements(HASH_OF(intern->repeated_field->array)) > - intern->position); + RepeatedFieldIter *intern = UNBOX(RepeatedFieldIter, getThis()); + RETURN_BOOL(zend_hash_num_elements(PHP_PROTO_HASH_OF( + intern->repeated_field->array)) > intern->position); } diff --git a/third_party/protobuf/3.2.0/php/ext/google/protobuf/def.c b/third_party/protobuf/3.2.0/php/ext/google/protobuf/def.c index 52b9e88568..8e563a618a 100644 --- a/third_party/protobuf/3.2.0/php/ext/google/protobuf/def.c +++ b/third_party/protobuf/3.2.0/php/ext/google/protobuf/def.c @@ -30,20 +30,17 @@ #include "protobuf.h" +const char* const kReservedNames[] = {"Empty"}; +const int kReservedNamesSize = 1; + // Forward declare. -static zend_object_value descriptor_create(zend_class_entry *ce TSRMLS_DC); static void descriptor_init_c_instance(Descriptor* intern TSRMLS_DC); static void descriptor_free_c(Descriptor* object TSRMLS_DC); -static void descriptor_free(void* object TSRMLS_DC); -static zend_object_value enum_descriptor_create(zend_class_entry *ce TSRMLS_DC); static void enum_descriptor_init_c_instance(EnumDescriptor* intern TSRMLS_DC); static void enum_descriptor_free_c(EnumDescriptor* object TSRMLS_DC); -static void enum_descriptor_free(void* object TSRMLS_DC); -static zend_object_value descriptor_pool_create(zend_class_entry *ce TSRMLS_DC); static void descriptor_pool_free_c(DescriptorPool* object TSRMLS_DC); -static void descriptor_pool_free(void* object TSRMLS_DC); static void descriptor_pool_init_c_instance(DescriptorPool* pool TSRMLS_DC); // ----------------------------------------------------------------------------- @@ -104,40 +101,31 @@ static void append_map_entry_name(char *result, const char *field_name, } while (0) // Define PHP class -#define DEFINE_PROTOBUF_INIT_CLASS(name_lower, string_name) \ - void name_lower##_init(TSRMLS_D) { \ - zend_class_entry class_type; \ - INIT_CLASS_ENTRY(class_type, string_name, name_lower##_methods); \ - name_lower##_type = zend_register_internal_class(&class_type TSRMLS_CC); \ - name_lower##_type->create_object = name_lower##_create; \ - } - -#define DEFINE_PROTOBUF_CREATE(name, name_lower) \ - static zend_object_value name_lower##_create( \ - zend_class_entry* ce TSRMLS_DC) { \ - zend_object_value return_value; \ - name* intern = (name*)emalloc(sizeof(name)); \ - memset(intern, 0, sizeof(name)); \ - name_lower##_init_c_instance(intern TSRMLS_CC); \ - return_value.handle = zend_objects_store_put( \ - intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, \ - name_lower##_free, NULL TSRMLS_CC); \ - return_value.handlers = zend_get_std_object_handlers(); \ - return return_value; \ - } - -#define DEFINE_PROTOBUF_FREE(name, name_lower) \ - static void name_lower##_free(void* object TSRMLS_DC) { \ - name* intern = (name*)object; \ - name_lower##_free_c(intern TSRMLS_CC); \ - efree(object); \ - } - -#define DEFINE_CLASS(name, name_lower, string_name) \ - zend_class_entry* name_lower##_type; \ - DEFINE_PROTOBUF_FREE(name, name_lower) \ - DEFINE_PROTOBUF_CREATE(name, name_lower) \ - DEFINE_PROTOBUF_INIT_CLASS(name_lower, string_name) +#define DEFINE_PROTOBUF_INIT_CLASS(CLASSNAME, CAMELNAME, LOWERNAME) \ + PHP_PROTO_INIT_CLASS_START(CLASSNAME, CAMELNAME, LOWERNAME) \ + PHP_PROTO_INIT_CLASS_END + +#define DEFINE_PROTOBUF_CREATE(NAME, LOWERNAME) \ + PHP_PROTO_OBJECT_CREATE_START(NAME, LOWERNAME) \ + LOWERNAME##_init_c_instance(intern TSRMLS_CC); \ + PHP_PROTO_OBJECT_CREATE_END(NAME, LOWERNAME) + +#define DEFINE_PROTOBUF_FREE(CAMELNAME, LOWERNAME) \ + PHP_PROTO_OBJECT_FREE_START(CAMELNAME, LOWERNAME) \ + LOWERNAME##_free_c(intern TSRMLS_CC); \ + PHP_PROTO_OBJECT_FREE_END + +#define DEFINE_PROTOBUF_DTOR(CAMELNAME, LOWERNAME) \ + PHP_PROTO_OBJECT_DTOR_START(CAMELNAME, LOWERNAME) \ + PHP_PROTO_OBJECT_DTOR_END + +#define DEFINE_CLASS(NAME, LOWERNAME, string_name) \ + zend_class_entry *LOWERNAME##_type; \ + zend_object_handlers *LOWERNAME##_handlers; \ + DEFINE_PROTOBUF_FREE(NAME, LOWERNAME) \ + DEFINE_PROTOBUF_DTOR(NAME, LOWERNAME) \ + DEFINE_PROTOBUF_CREATE(NAME, LOWERNAME) \ + DEFINE_PROTOBUF_INIT_CLASS(string_name, NAME, LOWERNAME) // ----------------------------------------------------------------------------- // GPBType @@ -176,6 +164,114 @@ void gpb_type_init(TSRMLS_D) { zend_declare_class_constant_long(gpb_type_type, STR("SINT64"), 18 TSRMLS_CC); } +// ----------------------------------------------------------------------------- +// Descriptor +// ----------------------------------------------------------------------------- + +static zend_function_entry descriptor_methods[] = { + ZEND_FE_END +}; + +DEFINE_CLASS(Descriptor, descriptor, "Google\\Protobuf\\Internal\\Descriptor"); + +static void descriptor_free_c(Descriptor *self TSRMLS_DC) { + if (self->layout) { + free_layout(self->layout); + } + if (self->fill_handlers) { + upb_handlers_unref(self->fill_handlers, &self->fill_handlers); + } + if (self->fill_method) { + upb_pbdecodermethod_unref(self->fill_method, &self->fill_method); + } + if (self->json_fill_method) { + upb_json_parsermethod_unref(self->json_fill_method, + &self->json_fill_method); + } + if (self->pb_serialize_handlers) { + upb_handlers_unref(self->pb_serialize_handlers, + &self->pb_serialize_handlers); + } + if (self->json_serialize_handlers) { + upb_handlers_unref(self->json_serialize_handlers, + &self->json_serialize_handlers); + } + if (self->json_serialize_handlers_preserve) { + upb_handlers_unref(self->json_serialize_handlers_preserve, + &self->json_serialize_handlers_preserve); + } +} + +static void descriptor_init_c_instance(Descriptor *desc TSRMLS_DC) { + // zend_object_std_init(&desc->std, descriptor_type TSRMLS_CC); + desc->msgdef = NULL; + desc->layout = NULL; + desc->klass = NULL; + desc->fill_handlers = NULL; + desc->fill_method = NULL; + desc->json_fill_method = NULL; + desc->pb_serialize_handlers = NULL; + desc->json_serialize_handlers = NULL; + desc->json_serialize_handlers_preserve = NULL; +} + +// ----------------------------------------------------------------------------- +// EnumDescriptor +// ----------------------------------------------------------------------------- + +static zend_function_entry enum_descriptor_methods[] = { + ZEND_FE_END +}; + +DEFINE_CLASS(EnumDescriptor, enum_descriptor, + "Google\\Protobuf\\Internal\\EnumDescriptor"); + +static void enum_descriptor_free_c(EnumDescriptor *self TSRMLS_DC) { +} + +static void enum_descriptor_init_c_instance(EnumDescriptor *self TSRMLS_DC) { + // zend_object_std_init(&self->std, enum_descriptor_type TSRMLS_CC); + self->enumdef = NULL; + self->klass = NULL; +} + +// ----------------------------------------------------------------------------- +// FieldDescriptor +// ----------------------------------------------------------------------------- + +upb_fieldtype_t to_fieldtype(upb_descriptortype_t type) { + switch (type) { +#define CASE(descriptor_type, type) \ + case UPB_DESCRIPTOR_TYPE_##descriptor_type: \ + return UPB_TYPE_##type; + + CASE(FLOAT, FLOAT); + CASE(DOUBLE, DOUBLE); + CASE(BOOL, BOOL); + CASE(STRING, STRING); + CASE(BYTES, BYTES); + CASE(MESSAGE, MESSAGE); + CASE(GROUP, MESSAGE); + CASE(ENUM, ENUM); + CASE(INT32, INT32); + CASE(INT64, INT64); + CASE(UINT32, UINT32); + CASE(UINT64, UINT64); + CASE(SINT32, INT32); + CASE(SINT64, INT64); + CASE(FIXED32, UINT32); + CASE(FIXED64, UINT64); + CASE(SFIXED32, INT32); + CASE(SFIXED64, INT64); + +#undef CONVERT + + } + + zend_error(E_ERROR, "Unknown field type."); + return 0; +} + // ----------------------------------------------------------------------------- // DescriptorPool // ----------------------------------------------------------------------------- @@ -190,25 +286,32 @@ static zend_function_entry descriptor_pool_methods[] = { DEFINE_CLASS(DescriptorPool, descriptor_pool, "Google\\Protobuf\\Internal\\DescriptorPool"); -zval* generated_pool_php; // wrapper of generated pool +// wrapper of generated pool +#if PHP_MAJOR_VERSION < 7 +zval* generated_pool_php; +#else +zend_object *generated_pool_php; +#endif DescriptorPool *generated_pool; // The actual generated pool static void init_generated_pool_once(TSRMLS_D) { if (generated_pool_php == NULL) { +#if PHP_MAJOR_VERSION < 7 MAKE_STD_ZVAL(generated_pool_php); - Z_TYPE_P(generated_pool_php) = IS_OBJECT; - generated_pool = ALLOC(DescriptorPool); - descriptor_pool_init_c_instance(generated_pool TSRMLS_CC); - Z_OBJ_HANDLE_P(generated_pool_php) = zend_objects_store_put( - generated_pool, NULL, - (zend_objects_free_object_storage_t)descriptor_pool_free, - NULL TSRMLS_CC); - Z_OBJ_HT_P(generated_pool_php) = zend_get_std_object_handlers(); + ZVAL_OBJ(generated_pool_php, descriptor_pool_type->create_object( + descriptor_pool_type TSRMLS_CC)); + generated_pool = UNBOX(DescriptorPool, generated_pool_php); +#else + generated_pool_php = + descriptor_pool_type->create_object(descriptor_pool_type TSRMLS_CC); + generated_pool = (DescriptorPool *)((char *)generated_pool_php - + XtOffsetOf(DescriptorPool, std)); +#endif } } static void descriptor_pool_init_c_instance(DescriptorPool *pool TSRMLS_DC) { - zend_object_std_init(&pool->std, descriptor_pool_type TSRMLS_CC); + // zend_object_std_init(&pool->std, descriptor_pool_type TSRMLS_CC); pool->symtab = upb_symtab_new(); ALLOC_HASHTABLE(pool->pending_list); @@ -247,66 +350,103 @@ static void validate_msgdef(const upb_msgdef* msgdef) { PHP_METHOD(DescriptorPool, getGeneratedPool) { init_generated_pool_once(TSRMLS_C); +#if PHP_MAJOR_VERSION < 7 RETURN_ZVAL(generated_pool_php, 1, 0); +#else + ++GC_REFCOUNT(generated_pool_php); + RETURN_OBJ(generated_pool_php); +#endif } -static void convert_to_class_name_inplace(char *class_name, - const char* fullname, - const char* prefix, - const char* package_name) { +static void classname_no_prefix(const char *fullname, const char *package_name, + char *class_name) { size_t i = 0, j; - bool first_char = true; + bool first_char = true, is_reserved = false; size_t pkg_name_len = package_name == NULL ? 0 : strlen(package_name); - size_t prefix_len = prefix == NULL ? 0 : strlen(prefix); size_t message_name_start = package_name == NULL ? 0 : pkg_name_len + 1; size_t message_len = (strlen(fullname) - message_name_start); - // In php, class name cannot be Empty. - if (strcmp("google.protobuf.Empty", fullname) == 0) { - strcpy(class_name, "\\Google\\Protobuf\\GPBEmpty"); - return; + // Submessage is concatenated with its containing messages by '_'. + for (j = message_name_start; j < message_name_start + message_len; j++) { + if (fullname[j] == '.') { + class_name[i++] = '_'; + } else { + class_name[i++] = fullname[j]; + } + } +} + +static const char *classname_prefix(const char *classname, + const char *prefix_given, + const char *package_name) { + size_t i; + bool is_reserved = false; + + if (prefix_given != NULL && strcmp(prefix_given, "") != 0) { + return prefix_given; } - if (pkg_name_len != 0) { - class_name[i++] = '\\'; - for (j = 0; j < pkg_name_len; j++) { + for (i = 0; i < kReservedNamesSize; i++) { + if (strcmp(kReservedNames[i], classname) == 0) { + is_reserved = true; + break; + } + } + + if (is_reserved) { + if (package_name != NULL && strcmp("google.protobuf", package_name) == 0) { + return "GPB"; + } else { + return "PB"; + } + } + + return ""; +} + +static void convert_to_class_name_inplace(const char *package, + const char *prefix, char *classname) { + size_t package_len = package == NULL ? 0 : strlen(package); + size_t prefix_len = prefix == NULL ? 0 : strlen(prefix); + size_t classname_len = strlen(classname); + int i = 0, j; + bool first_char = true; + + int offset = package_len != 0 ? 2 : 0; + + for (j = 0; j < classname_len; j++) { + classname[package_len + prefix_len + classname_len + offset - 1 - j] = + classname[classname_len - j - 1]; + } + + if (package_len != 0) { + classname[i++] = '\\'; + for (j = 0; j < package_len; j++) { // php packages are divided by '\'. - if (package_name[j] == '.') { - class_name[i++] = '\\'; + if (package[j] == '.') { + classname[i++] = '\\'; first_char = true; } else if (first_char) { // PHP package uses camel case. - if (package_name[j] < 'A' || package_name[j] > 'Z') { - class_name[i++] = package_name[j] + 'A' - 'a'; + if (package[j] < 'A' || package[j] > 'Z') { + classname[i++] = package[j] + 'A' - 'a'; } else { - class_name[i++] = package_name[j]; + classname[i++] = package[j]; } first_char = false; } else { - class_name[i++] = package_name[j]; + classname[i++] = package[j]; } } - class_name[i++] = '\\'; + classname[i++] = '\\'; } - if (prefix_len > 0) { - strcpy(class_name + i, prefix); - i += prefix_len; - } - - // Submessage is concatenated with its containing messages by '_'. - for (j = message_name_start; j < message_name_start + message_len; j++) { - if (fullname[j] == '.') { - class_name[i++] = '_'; - } else { - class_name[i++] = fullname[j]; - } - } + memcpy(classname + i, prefix, prefix_len); } PHP_METHOD(DescriptorPool, internalAddGeneratedFile) { char *data = NULL; - int data_len; + PHP_PROTO_SIZE data_len; upb_filedef **files; size_t i; @@ -335,11 +475,7 @@ PHP_METHOD(DescriptorPool, internalAddGeneratedFile) { switch (upb_def_type(def)) { #define CASE_TYPE(def_type, def_type_lower, desc_type, desc_type_lower) \ case UPB_DEF_##def_type: { \ - desc_type *desc; \ - zval *desc_php; \ - CREATE(desc_type, desc, desc_type_lower##_init_c_instance); \ - BOX(desc_type, desc_php, desc, desc_type_lower##_free); \ - Z_DELREF_P(desc_php); \ + CREATE_HASHTABLE_VALUE(desc, desc_php, desc_type, desc_type_lower##_type); \ const upb_##def_type_lower *def_type_lower = \ upb_downcast_##def_type_lower(def); \ desc->def_type_lower = def_type_lower; \ @@ -354,25 +490,27 @@ PHP_METHOD(DescriptorPool, internalAddGeneratedFile) { * bytes allocated, one for '.', one for trailing 0, and 3 for 'GPB' if \ * given message is google.protobuf.Empty.*/ \ const char *fullname = upb_##def_type_lower##_fullname(def_type_lower); \ - const char *prefix = upb_filedef_phpprefix(files[0]); \ - size_t klass_name_len = strlen(fullname) + 5; \ - if (prefix != NULL) { \ - klass_name_len += strlen(prefix); \ + const char *prefix_given = upb_filedef_phpprefix(files[0]); \ + size_t classname_len = strlen(fullname) + 5; \ + if (prefix_given != NULL) { \ + classname_len += strlen(prefix_given); \ } \ - char *klass_name = ecalloc(sizeof(char), klass_name_len); \ - convert_to_class_name_inplace(klass_name, fullname, prefix, \ - upb_filedef_package(files[0])); \ - zend_class_entry **pce; \ - if (zend_lookup_class(klass_name, strlen(klass_name), &pce TSRMLS_CC) == \ + char *classname = ecalloc(sizeof(char), classname_len); \ + const char *package = upb_filedef_package(files[0]); \ + classname_no_prefix(fullname, package, classname); \ + const char *prefix = classname_prefix(classname, prefix_given, package); \ + convert_to_class_name_inplace(package, prefix, classname); \ + PHP_PROTO_CE_DECLARE pce; \ + if (php_proto_zend_lookup_class(classname, strlen(classname), &pce) == \ FAILURE) { \ zend_error(E_ERROR, "Generated message class %s hasn't been defined", \ - klass_name); \ + classname); \ return; \ } else { \ - desc->klass = *pce; \ + desc->klass = PHP_PROTO_CE_UNREF(pce); \ } \ add_ce_obj(desc->klass, desc_php); \ - efree(klass_name); \ + efree(classname); \ break; \ } @@ -389,7 +527,7 @@ PHP_METHOD(DescriptorPool, internalAddGeneratedFile) { const upb_def *def = upb_filedef_def(files[0], i); if (upb_def_type(def) == UPB_DEF_MSG) { const upb_msgdef *msgdef = upb_downcast_msgdef(def); - zval *desc_php = get_def_obj(msgdef); + PHP_PROTO_HASHTABLE_VALUE desc_php = get_def_obj(msgdef); build_class_from_descriptor(desc_php TSRMLS_CC); } } @@ -397,111 +535,3 @@ PHP_METHOD(DescriptorPool, internalAddGeneratedFile) { upb_filedef_unref(files[0], &pool); upb_gfree(files); } - -// ----------------------------------------------------------------------------- -// Descriptor -// ----------------------------------------------------------------------------- - -static zend_function_entry descriptor_methods[] = { - ZEND_FE_END -}; - -DEFINE_CLASS(Descriptor, descriptor, "Google\\Protobuf\\Internal\\Descriptor"); - -static void descriptor_free_c(Descriptor *self TSRMLS_DC) { - if (self->layout) { - free_layout(self->layout); - } - if (self->fill_handlers) { - upb_handlers_unref(self->fill_handlers, &self->fill_handlers); - } - if (self->fill_method) { - upb_pbdecodermethod_unref(self->fill_method, &self->fill_method); - } - if (self->json_fill_method) { - upb_json_parsermethod_unref(self->json_fill_method, - &self->json_fill_method); - } - if (self->pb_serialize_handlers) { - upb_handlers_unref(self->pb_serialize_handlers, - &self->pb_serialize_handlers); - } - if (self->json_serialize_handlers) { - upb_handlers_unref(self->json_serialize_handlers, - &self->json_serialize_handlers); - } - if (self->json_serialize_handlers_preserve) { - upb_handlers_unref(self->json_serialize_handlers_preserve, - &self->json_serialize_handlers_preserve); - } -} - -static void descriptor_init_c_instance(Descriptor *desc TSRMLS_DC) { - zend_object_std_init(&desc->std, descriptor_type TSRMLS_CC); - desc->msgdef = NULL; - desc->layout = NULL; - desc->klass = NULL; - desc->fill_handlers = NULL; - desc->fill_method = NULL; - desc->json_fill_method = NULL; - desc->pb_serialize_handlers = NULL; - desc->json_serialize_handlers = NULL; - desc->json_serialize_handlers_preserve = NULL; -} - -// ----------------------------------------------------------------------------- -// EnumDescriptor -// ----------------------------------------------------------------------------- - -static zend_function_entry enum_descriptor_methods[] = { - ZEND_FE_END -}; - -DEFINE_CLASS(EnumDescriptor, enum_descriptor, - "Google\\Protobuf\\Internal\\EnumDescriptor"); - -static void enum_descriptor_free_c(EnumDescriptor *self TSRMLS_DC) { -} - -static void enum_descriptor_init_c_instance(EnumDescriptor *self TSRMLS_DC) { - zend_object_std_init(&self->std, enum_descriptor_type TSRMLS_CC); - self->enumdef = NULL; - self->klass = NULL; -} - -// ----------------------------------------------------------------------------- -// FieldDescriptor -// ----------------------------------------------------------------------------- - -upb_fieldtype_t to_fieldtype(upb_descriptortype_t type) { - switch (type) { -#define CASE(descriptor_type, type) \ - case UPB_DESCRIPTOR_TYPE_##descriptor_type: \ - return UPB_TYPE_##type; - - CASE(FLOAT, FLOAT); - CASE(DOUBLE, DOUBLE); - CASE(BOOL, BOOL); - CASE(STRING, STRING); - CASE(BYTES, BYTES); - CASE(MESSAGE, MESSAGE); - CASE(GROUP, MESSAGE); - CASE(ENUM, ENUM); - CASE(INT32, INT32); - CASE(INT64, INT64); - CASE(UINT32, UINT32); - CASE(UINT64, UINT64); - CASE(SINT32, INT32); - CASE(SINT64, INT64); - CASE(FIXED32, UINT32); - CASE(FIXED64, UINT64); - CASE(SFIXED32, INT32); - CASE(SFIXED64, INT64); - -#undef CONVERT - - } - - zend_error(E_ERROR, "Unknown field type."); - return 0; -} diff --git a/third_party/protobuf/3.2.0/php/ext/google/protobuf/encode_decode.c b/third_party/protobuf/3.2.0/php/ext/google/protobuf/encode_decode.c index e5a5f307cc..28bf18f4d5 100644 --- a/third_party/protobuf/3.2.0/php/ext/google/protobuf/encode_decode.c +++ b/third_party/protobuf/3.2.0/php/ext/google/protobuf/encode_decode.c @@ -197,19 +197,18 @@ static const void *newoneofhandlerdata(upb_handlers *h, static void *startseq_handler(void* closure, const void* hd) { MessageHeader* msg = closure; const size_t *ofs = hd; - return (void*)(*DEREF(msg, *ofs, zval**)); + return CACHED_PTR_TO_ZVAL_PTR(DEREF(message_data(msg), *ofs, CACHED_VALUE*)); } // Handlers that append primitive values to a repeated field. -#define DEFINE_APPEND_HANDLER(type, ctype) \ - static bool append##type##_handler(void* closure, const void* hd, \ - ctype val) { \ - zval* array = (zval*)closure; \ - TSRMLS_FETCH(); \ - RepeatedField* intern = \ - (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); \ - repeated_field_push_native(intern, &val TSRMLS_CC); \ - return true; \ +#define DEFINE_APPEND_HANDLER(type, ctype) \ + static bool append##type##_handler(void* closure, const void* hd, \ + ctype val) { \ + zval* array = (zval*)closure; \ + TSRMLS_FETCH(); \ + RepeatedField* intern = UNBOX(RepeatedField, array); \ + repeated_field_push_native(intern, &val); \ + return true; \ } DEFINE_APPEND_HANDLER(bool, bool) @@ -226,15 +225,19 @@ static void* appendstr_handler(void *closure, size_t size_hint) { zval* array = (zval*)closure; TSRMLS_FETCH(); - RepeatedField* intern = - (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); + RepeatedField* intern = UNBOX(RepeatedField, array); +#if PHP_MAJOR_VERSION < 7 zval* str; MAKE_STD_ZVAL(str); - ZVAL_STRING(str, "", 1); - - repeated_field_push_native(intern, &str TSRMLS_CC); + PHP_PROTO_ZVAL_STRING(str, "", 1); + repeated_field_push_native(intern, &str); return (void*)str; +#else + zend_string* str = zend_string_init("", 0, 1); + repeated_field_push_native(intern, &str); + return intern; +#endif } // Appends a 'bytes' string to a repeated field. @@ -243,24 +246,51 @@ static void* appendbytes_handler(void *closure, size_t size_hint) { zval* array = (zval*)closure; TSRMLS_FETCH(); - RepeatedField* intern = - (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); + RepeatedField* intern = UNBOX(RepeatedField, array); +#if PHP_MAJOR_VERSION < 7 zval* str; MAKE_STD_ZVAL(str); - ZVAL_STRING(str, "", 1); - - repeated_field_push_native(intern, &str TSRMLS_CC); + PHP_PROTO_ZVAL_STRING(str, "", 1); + repeated_field_push_native(intern, &str); return (void*)str; +#else + zend_string* str = zend_string_init("", 0, 1); + repeated_field_push_native(intern, &str); + return intern; +#endif } +// Handlers that append primitive values to a repeated field. +#define DEFINE_SINGULAR_HANDLER(type, ctype) \ + static bool type##_handler(void* closure, const void* hd, \ + ctype val) { \ + MessageHeader* msg = (MessageHeader*)closure; \ + const size_t *ofs = hd; \ + DEREF(message_data(msg), *ofs, ctype) = val; \ + return true; \ + } + +DEFINE_SINGULAR_HANDLER(bool, bool) +DEFINE_SINGULAR_HANDLER(int32, int32_t) +DEFINE_SINGULAR_HANDLER(uint32, uint32_t) +DEFINE_SINGULAR_HANDLER(float, float) +DEFINE_SINGULAR_HANDLER(int64, int64_t) +DEFINE_SINGULAR_HANDLER(uint64, uint64_t) +DEFINE_SINGULAR_HANDLER(double, double) + +#undef DEFINE_SINGULAR_HANDLER + +#if PHP_MAJOR_VERSION < 7 static void *empty_php_string(zval** value_ptr) { SEPARATE_ZVAL_IF_NOT_REF(value_ptr); - zval* str = *value_ptr; - zval_dtor(str); - ZVAL_STRINGL(str, "", 0, 1); - return (void*)str; + return (void*)(*value_ptr); +} +#else +static void *empty_php_string(zval* value_ptr) { + return value_ptr; } +#endif // Sets a non-repeated string field in a message. static void* str_handler(void *closure, @@ -268,7 +298,7 @@ static void* str_handler(void *closure, size_t size_hint) { MessageHeader* msg = closure; const size_t *ofs = hd; - return empty_php_string(DEREF(msg, *ofs, zval**)); + return empty_php_string(DEREF(message_data(msg), *ofs, CACHED_VALUE*)); } // Sets a non-repeated 'bytes' field in a message. @@ -277,52 +307,73 @@ static void* bytes_handler(void *closure, size_t size_hint) { MessageHeader* msg = closure; const size_t *ofs = hd; - return empty_php_string(DEREF(msg, *ofs, zval**)); + return empty_php_string(DEREF(message_data(msg), *ofs, CACHED_VALUE*)); } static size_t stringdata_handler(void* closure, const void* hd, const char* str, size_t len, const upb_bufhandle* handle) { zval* php_str = (zval*)closure; +#if PHP_MAJOR_VERSION < 7 + // Oneof string/bytes fields may have NULL initial value, which doesn't need + // to be freed. + if (Z_TYPE_P(php_str) == IS_STRING && !IS_INTERNED(Z_STRVAL_P(php_str))) { + FREE(Z_STRVAL_P(php_str)); + } + ZVAL_STRINGL(php_str, str, len, 1); +#else + if (Z_TYPE_P(php_str) == IS_STRING) { + zend_string_release(Z_STR_P(php_str)); + } + ZVAL_NEW_STR(php_str, zend_string_init(str, len, 0)); +#endif + return len; +} - char* old_str = Z_STRVAL_P(php_str); - size_t old_len = Z_STRLEN_P(php_str); - assert(old_str != NULL); - - char* new_str = emalloc(old_len + len + 1); +#if PHP_MAJOR_VERSION >= 7 +static size_t zendstringdata_handler(void* closure, const void* hd, + const char* str, size_t len, + const upb_bufhandle* handle) { + RepeatedField* intern = (RepeatedField*)closure; - memcpy(new_str, old_str, old_len); - memcpy(new_str + old_len, str, len); - new_str[old_len + len] = 0; - FREE(old_str); + unsigned char memory[NATIVE_SLOT_MAX_SIZE]; + memset(memory, 0, NATIVE_SLOT_MAX_SIZE); + *(zend_string**)memory = zend_string_init(str, len, 0); - Z_STRVAL_P(php_str) = new_str; - Z_STRLEN_P(php_str) = old_len + len; + HashTable *ht = PHP_PROTO_HASH_OF(intern->array); + int index = zend_hash_num_elements(ht) - 1; + php_proto_zend_hash_index_update( + ht, index, memory, sizeof(zend_string*), NULL); return len; } +#endif // Appends a submessage to a repeated field. static void *appendsubmsg_handler(void *closure, const void *hd) { zval* array = (zval*)closure; TSRMLS_FETCH(); - RepeatedField* intern = - (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); + RepeatedField* intern = UNBOX(RepeatedField, array); const submsg_handlerdata_t *submsgdata = hd; - zval* subdesc_php = get_def_obj((void*)submsgdata->md); - Descriptor* subdesc = zend_object_store_get_object(subdesc_php TSRMLS_CC); + Descriptor* subdesc = + UNBOX_HASHTABLE_VALUE(Descriptor, get_def_obj((void*)submsgdata->md)); zend_class_entry* subklass = subdesc->klass; MessageHeader* submsg; +#if PHP_MAJOR_VERSION < 7 zval* val = NULL; MAKE_STD_ZVAL(val); - Z_TYPE_P(val) = IS_OBJECT; - Z_OBJVAL_P(val) = subklass->create_object(subklass TSRMLS_CC); - - repeated_field_push_native(intern, &val TSRMLS_CC); + ZVAL_OBJ(val, subklass->create_object(subklass TSRMLS_CC)); + repeated_field_push_native(intern, &val); + submsg = UNBOX(MessageHeader, val); +#else + zend_object* obj = subklass->create_object(subklass TSRMLS_CC); + repeated_field_push_native(intern, &obj); + submsg = (MessageHeader*)((char*)obj - XtOffsetOf(MessageHeader, std)); +#endif + custom_data_init(subklass, submsg PHP_PROTO_TSRMLS_CC); - submsg = zend_object_store_get_object(val TSRMLS_CC); return submsg; } @@ -330,26 +381,35 @@ static void *appendsubmsg_handler(void *closure, const void *hd) { static void *submsg_handler(void *closure, const void *hd) { MessageHeader* msg = closure; const submsg_handlerdata_t* submsgdata = hd; - zval* subdesc_php = get_def_obj((void*)submsgdata->md); TSRMLS_FETCH(); - Descriptor* subdesc = zend_object_store_get_object(subdesc_php TSRMLS_CC); + Descriptor* subdesc = + UNBOX_HASHTABLE_VALUE(Descriptor, get_def_obj((void*)submsgdata->md)); zend_class_entry* subklass = subdesc->klass; zval* submsg_php; MessageHeader* submsg; - if (Z_TYPE_P(*DEREF(msg, submsgdata->ofs, zval**)) == IS_NULL) { + if (Z_TYPE_P(CACHED_PTR_TO_ZVAL_PTR(DEREF(message_data(msg), submsgdata->ofs, + CACHED_VALUE*))) == IS_NULL) { +#if PHP_MAJOR_VERSION < 7 zval* val = NULL; MAKE_STD_ZVAL(val); - Z_TYPE_P(val) = IS_OBJECT; - Z_OBJVAL_P(val) = subklass->create_object(subklass TSRMLS_CC); - - zval_ptr_dtor(DEREF(msg, submsgdata->ofs, zval**)); - *DEREF(msg, submsgdata->ofs, zval**) = val; + ZVAL_OBJ(val, subklass->create_object(subklass TSRMLS_CC)); + MessageHeader* intern = UNBOX(MessageHeader, val); + custom_data_init(subklass, intern PHP_PROTO_TSRMLS_CC); + php_proto_zval_ptr_dtor(*DEREF(message_data(msg), submsgdata->ofs, zval**)); + *DEREF(message_data(msg), submsgdata->ofs, zval**) = val; +#else + zend_object* obj = subklass->create_object(subklass TSRMLS_CC); + ZVAL_OBJ(DEREF(message_data(msg), submsgdata->ofs, zval*), obj); + MessageHeader* intern = UNBOX_HASHTABLE_VALUE(MessageHeader, obj); + custom_data_init(subklass, intern PHP_PROTO_TSRMLS_CC); +#endif } - submsg_php = *DEREF(msg, submsgdata->ofs, zval**); + submsg_php = CACHED_PTR_TO_ZVAL_PTR( + DEREF(message_data(msg), submsgdata->ofs, CACHED_VALUE*)); - submsg = zend_object_store_get_object(submsg_php TSRMLS_CC); + submsg = UNBOX(MessageHeader, submsg_php); return submsg; } @@ -372,32 +432,52 @@ typedef struct { // submessage. When the submessage ends, another handler is called to insert the // value into the map. typedef struct { - zval* map; char key_storage[NATIVE_SLOT_MAX_SIZE]; char value_storage[NATIVE_SLOT_MAX_SIZE]; -} map_parse_frame_t; +} map_parse_frame_data_t; -static void map_slot_init(void* memory, upb_fieldtype_t type) { +PHP_PROTO_WRAP_OBJECT_START(map_parse_frame_t) + map_parse_frame_data_t* data; // Place needs to be consistent with + // MessageHeader. + zval* map; + // In php7, we cannot allocate zval dynamically. So we need to add zval here + // to help decoding. + zval key_zval; + zval value_zval; +PHP_PROTO_WRAP_OBJECT_END +typedef struct map_parse_frame_t map_parse_frame_t; + +static void map_slot_init(void* memory, upb_fieldtype_t type, zval* cache) { switch (type) { case UPB_TYPE_STRING: case UPB_TYPE_BYTES: { +#if PHP_MAJOR_VERSION < 7 // Store zval** in memory in order to be consistent with the layout of // singular fields. zval** holder = ALLOC(zval*); zval* tmp; MAKE_STD_ZVAL(tmp); - ZVAL_STRINGL(tmp, "", 0, 1); + PHP_PROTO_ZVAL_STRINGL(tmp, "", 0, 1); *holder = tmp; *(zval***)memory = holder; +#else + *(zval**)memory = cache; + PHP_PROTO_ZVAL_STRINGL(*(zval**)memory, "", 0, 1); +#endif break; } case UPB_TYPE_MESSAGE: { +#if PHP_MAJOR_VERSION < 7 zval** holder = ALLOC(zval*); zval* tmp; MAKE_STD_ZVAL(tmp); ZVAL_NULL(tmp); *holder = tmp; *(zval***)memory = holder; +#else + *(zval**)memory = cache; + ZVAL_NULL(*(zval**)memory); +#endif break; } default: @@ -410,9 +490,13 @@ static void map_slot_uninit(void* memory, upb_fieldtype_t type) { case UPB_TYPE_MESSAGE: case UPB_TYPE_STRING: case UPB_TYPE_BYTES: { +#if PHP_MAJOR_VERSION < 7 zval** holder = *(zval***)memory; - zval_ptr_dtor(holder); + php_proto_zval_ptr_dtor(*holder); FREE(holder); +#else + php_proto_zval_ptr_dtor(*(zval**)memory); +#endif break; } default: @@ -424,7 +508,11 @@ static void map_slot_key(upb_fieldtype_t type, const void* from, const char** keyval, size_t* length) { if (type == UPB_TYPE_STRING) { +#if PHP_MAJOR_VERSION < 7 zval* key_php = **(zval***)from; +#else + zval* key_php = *(zval**)from; +#endif *keyval = Z_STRVAL_P(key_php); *length = Z_STRLEN_P(key_php); } else { @@ -444,6 +532,7 @@ static void map_slot_value(upb_fieldtype_t type, const void* from, memset(to, 0, native_slot_size(type)); switch (type) { +#if PHP_MAJOR_VERSION < 7 case UPB_TYPE_STRING: case UPB_TYPE_BYTES: case UPB_TYPE_MESSAGE: { @@ -451,6 +540,17 @@ static void map_slot_value(upb_fieldtype_t type, const void* from, Z_ADDREF_PP((zval**)to); break; } +#else + case UPB_TYPE_STRING: + case UPB_TYPE_BYTES: + *(zend_string**)to = Z_STR_P(*(zval**)from); + zend_string_addref(*(zend_string**)to); + break; + case UPB_TYPE_MESSAGE: + *(zend_object**)to = Z_OBJ_P(*(zval**)from); + ++GC_REFCOUNT(*(zend_object**)to); + break; +#endif default: len = native_slot_size(type); memcpy(to, from, len); @@ -462,13 +562,17 @@ static void map_slot_value(upb_fieldtype_t type, const void* from, static void *startmapentry_handler(void *closure, const void *hd) { MessageHeader* msg = closure; const map_handlerdata_t* mapdata = hd; - zval* map = *DEREF(msg, mapdata->ofs, zval**); + zval* map = CACHED_PTR_TO_ZVAL_PTR( + DEREF(message_data(msg), mapdata->ofs, CACHED_VALUE*)); map_parse_frame_t* frame = ALLOC(map_parse_frame_t); + frame->data = ALLOC(map_parse_frame_data_t); frame->map = map; - map_slot_init(&frame->key_storage, mapdata->key_field_type); - map_slot_init(&frame->value_storage, mapdata->value_field_type); + map_slot_init(&frame->data->key_storage, mapdata->key_field_type, + &frame->key_zval); + map_slot_init(&frame->data->value_storage, mapdata->value_field_type, + &frame->value_zval); return frame; } @@ -480,19 +584,20 @@ static bool endmap_handler(void* closure, const void* hd, upb_status* s) { const map_handlerdata_t* mapdata = hd; TSRMLS_FETCH(); - Map *map = (Map *)zend_object_store_get_object(frame->map TSRMLS_CC); + Map *map = UNBOX(Map, frame->map); const char* keyval = NULL; upb_value v; size_t length; - map_slot_key(map->key_type, &frame->key_storage, &keyval, &length); - map_slot_value(map->value_type, &frame->value_storage, &v); + map_slot_key(map->key_type, &frame->data->key_storage, &keyval, &length); + map_slot_value(map->value_type, &frame->data->value_storage, &v); map_index_set(map, keyval, length, v); - map_slot_uninit(&frame->key_storage, mapdata->key_field_type); - map_slot_uninit(&frame->value_storage, mapdata->value_field_type); + map_slot_uninit(&frame->data->key_storage, mapdata->key_field_type); + map_slot_uninit(&frame->data->value_storage, mapdata->value_field_type); + FREE(frame->data); FREE(frame); return true; @@ -528,14 +633,15 @@ static map_handlerdata_t* new_map_handlerdata( } // Handlers that set primitive values in oneofs. -#define DEFINE_ONEOF_HANDLER(type, ctype) \ - static bool oneof##type##_handler(void *closure, const void *hd, \ - ctype val) { \ - const oneof_handlerdata_t *oneofdata = hd; \ - DEREF(closure, oneofdata->case_ofs, uint32_t) = \ - oneofdata->oneof_case_num; \ - DEREF(closure, oneofdata->ofs, ctype) = val; \ - return true; \ +#define DEFINE_ONEOF_HANDLER(type, ctype) \ + static bool oneof##type##_handler(void* closure, const void* hd, \ + ctype val) { \ + const oneof_handlerdata_t* oneofdata = hd; \ + MessageHeader* msg = (MessageHeader*)closure; \ + DEREF(message_data(closure), oneofdata->case_ofs, uint32_t) = \ + oneofdata->oneof_case_num; \ + DEREF(message_data(closure), oneofdata->ofs, ctype) = val; \ + return true; \ } DEFINE_ONEOF_HANDLER(bool, bool) @@ -548,74 +654,71 @@ DEFINE_ONEOF_HANDLER(double, double) #undef DEFINE_ONEOF_HANDLER -// Handlers for strings in a oneof. -static void *oneofstr_handler(void *closure, - const void *hd, - size_t size_hint) { - MessageHeader* msg = closure; - const oneof_handlerdata_t *oneofdata = hd; - - DEREF(msg, oneofdata->case_ofs, uint32_t) = - oneofdata->oneof_case_num; - DEREF(msg, oneofdata->ofs, zval**) = - &(msg->std.properties_table)[oneofdata->property_ofs]; - - return empty_php_string(DEREF(msg, oneofdata->ofs, zval**)); -} - +// Handlers for string/bytes in a oneof. static void *oneofbytes_handler(void *closure, const void *hd, size_t size_hint) { MessageHeader* msg = closure; const oneof_handlerdata_t *oneofdata = hd; - DEREF(msg, oneofdata->case_ofs, uint32_t) = + DEREF(message_data(msg), oneofdata->case_ofs, uint32_t) = oneofdata->oneof_case_num; - DEREF(msg, oneofdata->ofs, zval**) = + DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*) = &(msg->std.properties_table)[oneofdata->property_ofs]; + return empty_php_string(DEREF( + message_data(msg), oneofdata->ofs, CACHED_VALUE*)); +} + +static void *oneofstr_handler(void *closure, + const void *hd, + size_t size_hint) { // TODO(teboring): Add it back. // rb_enc_associate(str, kRubyString8bitEncoding); - - SEPARATE_ZVAL_IF_NOT_REF(DEREF(msg, oneofdata->ofs, zval**)); - zval* str = *DEREF(msg, oneofdata->ofs, zval**); - zval_dtor(str); - ZVAL_STRINGL(str, "", 0, 1); - return (void*)str; + return oneofbytes_handler(closure, hd, size_hint); } // Handler for a submessage field in a oneof. static void* oneofsubmsg_handler(void* closure, const void* hd) { MessageHeader* msg = closure; const oneof_handlerdata_t *oneofdata = hd; - uint32_t oldcase = DEREF(msg, oneofdata->case_ofs, uint32_t); - zval* subdesc_php = get_def_obj((void*)oneofdata->md); + uint32_t oldcase = DEREF(message_data(msg), oneofdata->case_ofs, uint32_t); TSRMLS_FETCH(); - Descriptor* subdesc = zend_object_store_get_object(subdesc_php TSRMLS_CC); + Descriptor* subdesc = + UNBOX_HASHTABLE_VALUE(Descriptor, get_def_obj((void*)oneofdata->md)); zend_class_entry* subklass = subdesc->klass; zval* submsg_php; MessageHeader* submsg; if (oldcase != oneofdata->oneof_case_num) { - DEREF(msg, oneofdata->ofs, zval**) = + // Ideally, we should clean up the old data. However, we don't even know the + // type of the old data. So, we will defer the desctruction of the old data + // to the time that containing message's destroyed or the same oneof field + // is accessed again and find that the old data hasn't been cleaned. + DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*) = &(msg->std.properties_table)[oneofdata->property_ofs]; - } - if (Z_TYPE_P(*DEREF(msg, oneofdata->ofs, zval**)) == IS_NULL) { - zval* val = NULL; - MAKE_STD_ZVAL(val); - Z_TYPE_P(val) = IS_OBJECT; - Z_OBJVAL_P(val) = subklass->create_object(subklass TSRMLS_CC); + // Old data was't cleaned when the oneof was accessed from another field. + if (Z_TYPE_P(CACHED_PTR_TO_ZVAL_PTR(DEREF( + message_data(msg), oneofdata->ofs, CACHED_VALUE*))) != IS_NULL) { + php_proto_zval_ptr_dtor( + CACHED_PTR_TO_ZVAL_PTR( + DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*))); + } - zval_ptr_dtor(DEREF(msg, oneofdata->ofs, zval**)); - *DEREF(msg, oneofdata->ofs, zval**) = val; + // Create new message. + ZVAL_OBJ(CACHED_PTR_TO_ZVAL_PTR( + DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*)), + subklass->create_object(subklass TSRMLS_CC)); } - DEREF(msg, oneofdata->case_ofs, uint32_t) = + DEREF(message_data(msg), oneofdata->case_ofs, uint32_t) = oneofdata->oneof_case_num; - submsg_php = *DEREF(msg, oneofdata->ofs, zval**); - submsg = zend_object_store_get_object(submsg_php TSRMLS_CC); + submsg_php = CACHED_PTR_TO_ZVAL_PTR( + DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*)); + submsg = UNBOX(MessageHeader, submsg_php); + custom_data_init(subklass, submsg PHP_PROTO_TSRMLS_CC); return submsg; } @@ -652,7 +755,11 @@ static void add_handlers_for_repeated_field(upb_handlers *h, upb_handlers_setstartstr(h, f, is_bytes ? appendbytes_handler : appendstr_handler, NULL); +#if PHP_MAJOR_VERSION < 7 upb_handlers_setstring(h, f, stringdata_handler, NULL); +#else + upb_handlers_setstring(h, f, zendstringdata_handler, NULL); +#endif break; } case UPB_TYPE_MESSAGE: { @@ -670,16 +777,26 @@ static void add_handlers_for_singular_field(upb_handlers *h, const upb_fielddef *f, size_t offset) { switch (upb_fielddef_type(f)) { - case UPB_TYPE_BOOL: - case UPB_TYPE_INT32: - case UPB_TYPE_UINT32: - case UPB_TYPE_ENUM: - case UPB_TYPE_FLOAT: - case UPB_TYPE_INT64: - case UPB_TYPE_UINT64: - case UPB_TYPE_DOUBLE: - upb_msg_setscalarhandler(h, f, offset, -1); - break; + +#define SET_HANDLER(utype, ltype) \ + case utype: { \ + upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER; \ + upb_handlerattr_sethandlerdata(&attr, newhandlerdata(h, offset)); \ + upb_handlers_set##ltype(h, f, ltype##_handler, &attr); \ + break; \ + } + + SET_HANDLER(UPB_TYPE_BOOL, bool); + SET_HANDLER(UPB_TYPE_INT32, int32); + SET_HANDLER(UPB_TYPE_UINT32, uint32); + SET_HANDLER(UPB_TYPE_ENUM, int32); + SET_HANDLER(UPB_TYPE_FLOAT, float); + SET_HANDLER(UPB_TYPE_INT64, int64); + SET_HANDLER(UPB_TYPE_UINT64, uint64); + SET_HANDLER(UPB_TYPE_DOUBLE, double); + +#undef SET_HANDLER + case UPB_TYPE_STRING: case UPB_TYPE_BYTES: { bool is_bytes = upb_fielddef_type(f) == UPB_TYPE_BYTES; @@ -730,9 +847,11 @@ static void add_handlers_for_mapentry(const upb_msgdef* msgdef, upb_handlers* h, upb_handlers_setendmsg(h, endmap_handler, &attr); add_handlers_for_singular_field(h, key_field, - offsetof(map_parse_frame_t, key_storage)); + offsetof(map_parse_frame_data_t, + key_storage)); add_handlers_for_singular_field(h, value_field, - offsetof(map_parse_frame_t, value_storage)); + offsetof(map_parse_frame_data_t, + value_storage)); } // Set up handlers for a oneof field. @@ -787,8 +906,8 @@ static void add_handlers_for_message(const void* closure, upb_handlers* h) { const upb_msgdef* msgdef = upb_handlers_msgdef(h); TSRMLS_FETCH(); - Descriptor* desc = (Descriptor*)zend_object_store_get_object( - get_def_obj((void*)msgdef) TSRMLS_CC); + Descriptor* desc = + UNBOX_HASHTABLE_VALUE(Descriptor, get_def_obj((void*)msgdef)); upb_msg_field_iter i; // If this is a mapentry message type, set up a special set of handlers and @@ -810,13 +929,11 @@ static void add_handlers_for_message(const void* closure, !upb_msg_field_done(&i); upb_msg_field_next(&i)) { const upb_fielddef *f = upb_msg_iter_field(&i); - size_t offset = desc->layout->fields[upb_fielddef_index(f)].offset + - sizeof(MessageHeader); + size_t offset = desc->layout->fields[upb_fielddef_index(f)].offset; if (upb_fielddef_containingoneof(f)) { size_t oneof_case_offset = - desc->layout->fields[upb_fielddef_index(f)].case_offset + - sizeof(MessageHeader); + desc->layout->fields[upb_fielddef_index(f)].case_offset; int property_cache_index = desc->layout->fields[upb_fielddef_index(f)].cache_index; add_handlers_for_oneof_field(h, f, offset, oneof_case_offset, @@ -883,6 +1000,8 @@ static const upb_json_parsermethod *msgdef_jsonparsermethod(Descriptor* desc) { static void putmsg(zval* msg, const Descriptor* desc, upb_sink* sink, int depth TSRMLS_DC); +static void putrawmsg(MessageHeader* msg, const Descriptor* desc, + upb_sink* sink, int depth TSRMLS_DC); static void putstr(zval* str, const upb_fielddef* f, upb_sink* sink); @@ -891,6 +1010,8 @@ static void putrawstr(const char* str, int len, const upb_fielddef* f, static void putsubmsg(zval* submsg, const upb_fielddef* f, upb_sink* sink, int depth TSRMLS_DC); +static void putrawsubmsg(MessageHeader* submsg, const upb_fielddef* f, + upb_sink* sink, int depth TSRMLS_DC); static void putarray(zval* array, const upb_fielddef* f, upb_sink* sink, int depth TSRMLS_DC); @@ -933,8 +1054,14 @@ static void put_optional_value(const void* memory, int len, const upb_fielddef* putrawstr(memory, len, f, sink); break; case UPB_TYPE_MESSAGE: { - zval* submsg = *(zval**)memory; - putsubmsg(submsg, f, sink, depth TSRMLS_CC); +#if PHP_MAJOR_VERSION < 7 + MessageHeader *submsg = UNBOX(MessageHeader, *(zval**)memory); +#else + MessageHeader *submsg = + (MessageHeader*)((char*)(*(zend_object**)memory) - + XtOffsetOf(MessageHeader, std)); +#endif + putrawsubmsg(submsg, f, sink, depth TSRMLS_CC); break; } default: @@ -947,7 +1074,11 @@ static const char* raw_value(void* memory, const upb_fielddef* f) { switch (upb_fielddef_type(f)) { case UPB_TYPE_STRING: case UPB_TYPE_BYTES: +#if PHP_MAJOR_VERSION < 7 return Z_STRVAL_PP((zval**)memory); +#else + return ZSTR_VAL(*(zend_string**)memory); +#endif break; default: return memory; @@ -958,8 +1089,11 @@ static int raw_value_len(void* memory, int len, const upb_fielddef* f) { switch (upb_fielddef_type(f)) { case UPB_TYPE_STRING: case UPB_TYPE_BYTES: +#if PHP_MAJOR_VERSION < 7 return Z_STRLEN_PP((zval**)memory); - break; +#else + return ZSTR_LEN(*(zend_string**)memory); +#endif default: return len; } @@ -967,7 +1101,6 @@ static int raw_value_len(void* memory, int len, const upb_fielddef* f) { static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink, int depth TSRMLS_DC) { - Map* self; upb_sink subsink; const upb_fielddef* key_field; const upb_fielddef* value_field; @@ -975,8 +1108,7 @@ static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink, int len, size; assert(map != NULL); - Map* intern = - (Map*)zend_object_store_get_object(map TSRMLS_CC); + Map* intern = UNBOX(Map, map); size = upb_strtable_count(&intern->table); if (size == 0) return; @@ -1013,6 +1145,12 @@ static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink, static void putmsg(zval* msg_php, const Descriptor* desc, upb_sink* sink, int depth TSRMLS_DC) { + MessageHeader* msg = UNBOX(MessageHeader, msg_php); + putrawmsg(msg, desc, sink, depth TSRMLS_CC); +} + +static void putrawmsg(MessageHeader* msg, const Descriptor* desc, + upb_sink* sink, int depth TSRMLS_DC) { upb_msg_field_iter i; upb_status status; @@ -1025,21 +1163,18 @@ static void putmsg(zval* msg_php, const Descriptor* desc, upb_sink* sink, "Maximum recursion depth exceeded during encoding."); } - MessageHeader* msg = zend_object_store_get_object(msg_php TSRMLS_CC); - for (upb_msg_field_begin(&i, desc->msgdef); !upb_msg_field_done(&i); upb_msg_field_next(&i)) { upb_fielddef* f = upb_msg_iter_field(&i); - uint32_t offset = desc->layout->fields[upb_fielddef_index(f)].offset + - sizeof(MessageHeader); + uint32_t offset = desc->layout->fields[upb_fielddef_index(f)].offset; if (upb_fielddef_containingoneof(f)) { uint32_t oneof_case_offset = - desc->layout->fields[upb_fielddef_index(f)].case_offset + - sizeof(MessageHeader); + desc->layout->fields[upb_fielddef_index(f)].case_offset; // For a oneof, check that this field is actually present -- skip all the // below if not. - if (DEREF(msg, oneof_case_offset, uint32_t) != upb_fielddef_number(f)) { + if (DEREF(message_data(msg), oneof_case_offset, uint32_t) != + upb_fielddef_number(f)) { continue; } // Otherwise, fall through to the appropriate singular-field handler @@ -1047,31 +1182,36 @@ static void putmsg(zval* msg_php, const Descriptor* desc, upb_sink* sink, } if (is_map_field(f)) { - zval* map = *DEREF(msg, offset, zval**); + zval* map = CACHED_PTR_TO_ZVAL_PTR( + DEREF(message_data(msg), offset, CACHED_VALUE*)); if (map != NULL) { putmap(map, f, sink, depth TSRMLS_CC); } } else if (upb_fielddef_isseq(f)) { - zval* array = *DEREF(msg, offset, zval**); + zval* array = CACHED_PTR_TO_ZVAL_PTR( + DEREF(message_data(msg), offset, CACHED_VALUE*)); if (array != NULL) { putarray(array, f, sink, depth TSRMLS_CC); } } else if (upb_fielddef_isstring(f)) { - zval* str = *DEREF(msg, offset, zval**); + zval* str = CACHED_PTR_TO_ZVAL_PTR( + DEREF(message_data(msg), offset, CACHED_VALUE*)); if (Z_STRLEN_P(str) > 0) { putstr(str, f, sink); } } else if (upb_fielddef_issubmsg(f)) { - putsubmsg(*DEREF(msg, offset, zval**), f, sink, depth TSRMLS_CC); + putsubmsg(CACHED_PTR_TO_ZVAL_PTR( + DEREF(message_data(msg), offset, CACHED_VALUE*)), + f, sink, depth TSRMLS_CC); } else { upb_selector_t sel = getsel(f, upb_handlers_getprimitivehandlertype(f)); -#define T(upbtypeconst, upbtype, ctype, default_value) \ - case upbtypeconst: { \ - ctype value = DEREF(msg, offset, ctype); \ - if (value != default_value) { \ - upb_sink_put##upbtype(sink, sel, value); \ - } \ +#define T(upbtypeconst, upbtype, ctype, default_value) \ + case upbtypeconst: { \ + ctype value = DEREF(message_data(msg), offset, ctype); \ + if (value != default_value) { \ + upb_sink_put##upbtype(sink, sel, value); \ + } \ } break; switch (upb_fielddef_type(f)) { @@ -1138,18 +1278,23 @@ static void putrawstr(const char* str, int len, const upb_fielddef* f, upb_sink_endstr(sink, getsel(f, UPB_HANDLER_ENDSTR)); } -static void putsubmsg(zval* submsg, const upb_fielddef* f, upb_sink* sink, +static void putsubmsg(zval* submsg_php, const upb_fielddef* f, upb_sink* sink, int depth TSRMLS_DC) { - upb_sink subsink; + if (Z_TYPE_P(submsg_php) == IS_NULL) return; - if (Z_TYPE_P(submsg) == IS_NULL) return; + MessageHeader *submsg = UNBOX(MessageHeader, submsg_php); + putrawsubmsg(submsg, f, sink, depth TSRMLS_CC); +} + +static void putrawsubmsg(MessageHeader* submsg, const upb_fielddef* f, + upb_sink* sink, int depth TSRMLS_DC) { + upb_sink subsink; - zval* php_descriptor = get_def_obj(upb_fielddef_msgsubdef(f)); Descriptor* subdesc = - (Descriptor*)zend_object_store_get_object(php_descriptor TSRMLS_CC); + UNBOX_HASHTABLE_VALUE(Descriptor, get_def_obj(upb_fielddef_msgsubdef(f))); upb_sink_startsubmsg(sink, getsel(f, UPB_HANDLER_STARTSUBMSG), &subsink); - putmsg(submsg, subdesc, &subsink, depth + 1 TSRMLS_CC); + putrawmsg(submsg, subdesc, &subsink, depth + 1 TSRMLS_CC); upb_sink_endsubmsg(sink, getsel(f, UPB_HANDLER_ENDSUBMSG)); } @@ -1161,9 +1306,10 @@ static void putarray(zval* array, const upb_fielddef* f, upb_sink* sink, int size, i; assert(array != NULL); - RepeatedField* intern = - (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); - size = zend_hash_num_elements(HASH_OF(intern->array)); + RepeatedField* intern = UNBOX(RepeatedField, array); + HashTable *ht = PHP_PROTO_HASH_OF(intern->array); + size = zend_hash_num_elements(ht); + // size = zend_hash_num_elements(PHP_PROTO_HASH_OF(intern->array)); if (size == 0) return; upb_sink_startseq(sink, getsel(f, UPB_HANDLER_STARTSEQ), &subsink); @@ -1190,12 +1336,28 @@ static void putarray(zval* array, const upb_fielddef* f, upb_sink* sink, T(UPB_TYPE_UINT64, uint64, uint64_t) case UPB_TYPE_STRING: - case UPB_TYPE_BYTES: - putstr(*((zval**)memory), f, &subsink); + case UPB_TYPE_BYTES: { +#if PHP_MAJOR_VERSION < 7 + const char* rawstr = Z_STRVAL_P(*(zval**)memory); + int len = Z_STRLEN_P(*(zval**)memory); +#else + const char* rawstr = ZSTR_VAL(*(zend_string**)memory); + int len = ZSTR_LEN(*(zend_string**)memory); +#endif + putrawstr(rawstr, len, f, &subsink); break; - case UPB_TYPE_MESSAGE: - putsubmsg(*((zval**)memory), f, &subsink, depth TSRMLS_CC); + } + case UPB_TYPE_MESSAGE: { +#if PHP_MAJOR_VERSION < 7 + MessageHeader *submsg = UNBOX(MessageHeader, *(zval**)memory); +#else + MessageHeader *submsg = + (MessageHeader*)((char*)(*(zend_object**)memory) - + XtOffsetOf(MessageHeader, std)); +#endif + putrawsubmsg(submsg, f, &subsink, depth TSRMLS_CC); break; + } #undef T } @@ -1235,9 +1397,8 @@ static const upb_handlers* msgdef_json_serialize_handlers( // ----------------------------------------------------------------------------- PHP_METHOD(Message, serializeToString) { - zval* php_descriptor = get_ce_obj(Z_OBJCE_P(getThis())); Descriptor* desc = - (Descriptor*)zend_object_store_get_object(php_descriptor TSRMLS_CC); + UNBOX_HASHTABLE_VALUE(Descriptor, get_ce_obj(Z_OBJCE_P(getThis()))); stringsink sink; stringsink_init(&sink); @@ -1253,7 +1414,7 @@ PHP_METHOD(Message, serializeToString) { putmsg(getThis(), desc, upb_pb_encoder_input(encoder), 0 TSRMLS_CC); - RETVAL_STRINGL(sink.ptr, sink.len, 1); + PHP_PROTO_RETVAL_STRINGL(sink.ptr, sink.len, 1); stackenv_uninit(&se); stringsink_uninit(&sink); @@ -1261,13 +1422,13 @@ PHP_METHOD(Message, serializeToString) { } PHP_METHOD(Message, mergeFromString) { - zval* php_descriptor = get_ce_obj(Z_OBJCE_P(getThis())); Descriptor* desc = - (Descriptor*)zend_object_store_get_object(php_descriptor TSRMLS_CC); - MessageHeader* msg = zend_object_store_get_object(getThis() TSRMLS_CC); + UNBOX_HASHTABLE_VALUE(Descriptor, get_ce_obj(Z_OBJCE_P(getThis()))); + MessageHeader* msg = UNBOX(MessageHeader, getThis()); char *data = NULL; - int data_len; + PHP_PROTO_SIZE data_len; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &data_len) == FAILURE) { return; @@ -1290,9 +1451,8 @@ PHP_METHOD(Message, mergeFromString) { } PHP_METHOD(Message, jsonEncode) { - zval* php_descriptor = get_ce_obj(Z_OBJCE_P(getThis())); Descriptor* desc = - (Descriptor*)zend_object_store_get_object(php_descriptor TSRMLS_CC); + UNBOX_HASHTABLE_VALUE(Descriptor, get_ce_obj(Z_OBJCE_P(getThis()))); zend_bool preserve_proto_fieldnames = false; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", @@ -1314,7 +1474,7 @@ PHP_METHOD(Message, jsonEncode) { putmsg(getThis(), desc, upb_json_printer_input(printer), 0 TSRMLS_CC); - RETVAL_STRINGL(sink.ptr, sink.len, 1); + PHP_PROTO_RETVAL_STRINGL(sink.ptr, sink.len, 1); stackenv_uninit(&se); stringsink_uninit(&sink); @@ -1322,10 +1482,9 @@ PHP_METHOD(Message, jsonEncode) { } PHP_METHOD(Message, jsonDecode) { - zval* php_descriptor = get_ce_obj(Z_OBJCE_P(getThis())); Descriptor* desc = - (Descriptor*)zend_object_store_get_object(php_descriptor TSRMLS_CC); - MessageHeader* msg = zend_object_store_get_object(getThis() TSRMLS_CC); + UNBOX_HASHTABLE_VALUE(Descriptor, get_ce_obj(Z_OBJCE_P(getThis()))); + MessageHeader* msg = UNBOX(MessageHeader, getThis()); char *data = NULL; int data_len; diff --git a/third_party/protobuf/3.2.0/php/ext/google/protobuf/map.c b/third_party/protobuf/3.2.0/php/ext/google/protobuf/map.c index fae152e3fe..a5d4844661 100644 --- a/third_party/protobuf/3.2.0/php/ext/google/protobuf/map.c +++ b/third_party/protobuf/3.2.0/php/ext/google/protobuf/map.c @@ -103,16 +103,16 @@ static bool table_key(Map* self, zval* key, *out_length = Z_STRLEN_P(key); break; -#define CASE_TYPE(upb_type, type, c_type, php_type) \ - case UPB_TYPE_##upb_type: { \ - c_type type##_value; \ - if (!protobuf_convert_to_##type(key, &type##_value)) { \ - return false; \ - } \ - native_slot_set(self->key_type, NULL, buf, key TSRMLS_CC); \ - *out_key = buf; \ - *out_length = native_slot_size(self->key_type); \ - break; \ +#define CASE_TYPE(upb_type, type, c_type, php_type) \ + case UPB_TYPE_##upb_type: { \ + c_type type##_value; \ + if (!protobuf_convert_to_##type(key, &type##_value)) { \ + return false; \ + } \ + native_slot_set_by_array(self->key_type, NULL, buf, key TSRMLS_CC); \ + *out_key = buf; \ + *out_length = native_slot_size(self->key_type); \ + break; \ } CASE_TYPE(BOOL, bool, int8_t, BOOL) CASE_TYPE(INT32, int32, int32_t, LONG) @@ -148,7 +148,7 @@ static zend_function_entry map_field_methods[] = { // Forward declare static functions. -static bool map_field_write_dimension(zval *object, zval *key, +static void map_field_write_dimension(zval *object, zval *key, zval *value TSRMLS_DC); // ----------------------------------------------------------------------------- @@ -163,8 +163,7 @@ static void map_begin_internal(Map *map, MapIter *iter) { upb_strtable_begin(&iter->it, &map->table); } -static HashTable *map_field_get_gc(zval *object, zval ***table, - int *n TSRMLS_DC) { +static HashTable *map_field_get_gc(zval *object, CACHED_VALUE **table, int *n) { // TODO(teboring): Unfortunately, zend engine does not support garbage // collection for custom array. We have to use zend engine's native array // instead. @@ -173,111 +172,101 @@ static HashTable *map_field_get_gc(zval *object, zval ***table, return NULL; } -void map_field_init(TSRMLS_D) { - zend_class_entry class_type; - const char* class_name = "Google\\Protobuf\\Internal\\MapField"; - INIT_CLASS_ENTRY_EX(class_type, class_name, strlen(class_name), - map_field_methods); - - map_field_type = zend_register_internal_class(&class_type TSRMLS_CC); - map_field_type->create_object = map_field_create; - - zend_class_implements(map_field_type TSRMLS_CC, 2, spl_ce_ArrayAccess, - spl_ce_Countable); - - map_field_handlers = PEMALLOC(zend_object_handlers); - memcpy(map_field_handlers, zend_get_std_object_handlers(), - sizeof(zend_object_handlers)); - map_field_handlers->write_dimension = map_field_write_dimension; - map_field_handlers->get_gc = map_field_get_gc; +// Define map value element free function. +#if PHP_MAJOR_VERSION < 7 +static inline void php_proto_map_string_release(void *value) { + zval_ptr_dtor(value); } -zend_object_value map_field_create(zend_class_entry *ce TSRMLS_DC) { - zend_object_value retval = {0}; - Map *intern; - - intern = emalloc(sizeof(Map)); - memset(intern, 0, sizeof(Map)); - - zend_object_std_init(&intern->std, ce TSRMLS_CC); - object_properties_init(&intern->std, ce); - - // Table value type is always UINT64: this ensures enough space to store the - // native_slot value. - if (!upb_strtable_init(&intern->table, UPB_CTYPE_UINT64)) { - zend_error(E_USER_ERROR, "Could not allocate table."); +static inline void php_proto_map_object_release(void *value) { + zval_ptr_dtor(value); +} +#else +static inline void php_proto_map_string_release(void *value) { + zend_string* object = *(zend_string**)value; + zend_string_release(object); +} +static inline void php_proto_map_object_release(void *value) { + zend_object* object = *(zend_object**)value; + if(--GC_REFCOUNT(object) == 0) { + zend_objects_store_del(object); } - - retval.handle = zend_objects_store_put( - intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, - (zend_objects_free_object_storage_t)map_field_free, NULL TSRMLS_CC); - retval.handlers = map_field_handlers; - - return retval; } +#endif -void map_field_free(void *object TSRMLS_DC) { - Map *map = (Map *)object; - - switch (map->value_type) { +// Define object free method. +PHP_PROTO_OBJECT_FREE_START(Map, map_field) +MapIter it; +int len; +for (map_begin_internal(intern, &it); !map_done(&it); map_next(&it)) { + upb_value value = map_iter_value(&it, &len); + void *mem = upb_value_memory(&value); + switch (intern->value_type) { case UPB_TYPE_MESSAGE: + php_proto_map_object_release(mem); + break; case UPB_TYPE_STRING: - case UPB_TYPE_BYTES: { - MapIter it; - int len; - for (map_begin_internal(map, &it); !map_done(&it); map_next(&it)) { - upb_value value = map_iter_value(&it, &len); - void *mem = upb_value_memory(&value); - zval_ptr_dtor(mem); - } + case UPB_TYPE_BYTES: + php_proto_map_string_release(mem); break; - } default: break; } - - upb_strtable_uninit(&map->table); - zend_object_std_dtor(&map->std TSRMLS_CC); - efree(object); } - -void map_field_create_with_field(zend_class_entry *ce, const upb_fielddef *field, - zval **map_field TSRMLS_DC) { +upb_strtable_uninit(&intern->table); +PHP_PROTO_OBJECT_FREE_END + +PHP_PROTO_OBJECT_DTOR_START(Map, map_field) +PHP_PROTO_OBJECT_DTOR_END + +// Define object create method. +PHP_PROTO_OBJECT_CREATE_START(Map, map_field) +// Table value type is always UINT64: this ensures enough space to store the +// native_slot value. +if (!upb_strtable_init(&intern->table, UPB_CTYPE_UINT64)) { + zend_error(E_USER_ERROR, "Could not allocate table."); +} +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); +map_field_handlers->write_dimension = map_field_write_dimension; +map_field_handlers->get_gc = map_field_get_gc; +PHP_PROTO_INIT_CLASS_END + +void map_field_create_with_field(const zend_class_entry *ce, + const upb_fielddef *field, + CACHED_VALUE *map_field PHP_PROTO_TSRMLS_DC) { const upb_fielddef *key_field = map_field_key(field); const upb_fielddef *value_field = map_field_value(field); map_field_create_with_type( ce, upb_fielddef_type(key_field), upb_fielddef_type(value_field), - field_type_class(value_field TSRMLS_CC), map_field TSRMLS_CC); + field_type_class(value_field TSRMLS_CC), map_field PHP_PROTO_TSRMLS_CC); } -void map_field_create_with_type(zend_class_entry *ce, upb_fieldtype_t key_type, +void map_field_create_with_type(const zend_class_entry *ce, + upb_fieldtype_t key_type, upb_fieldtype_t value_type, const zend_class_entry *msg_ce, - zval **map_field TSRMLS_DC) { - MAKE_STD_ZVAL(*map_field); - Z_TYPE_PP(map_field) = IS_OBJECT; - Z_OBJVAL_PP(map_field) = - map_field_type->create_object(map_field_type TSRMLS_CC); - - Map* intern = - (Map*)zend_object_store_get_object(*map_field TSRMLS_CC); - + CACHED_VALUE *map_field PHP_PROTO_TSRMLS_DC) { + CREATE_OBJ_ON_ALLOCATED_ZVAL_PTR(CACHED_PTR_TO_ZVAL_PTR(map_field), + map_field_type); + Map *intern = UNBOX(Map, CACHED_TO_ZVAL_PTR(*map_field)); intern->key_type = key_type; intern->value_type = value_type; intern->msg_ce = msg_ce; } -static void map_field_free_element(void *object) { -} - // ----------------------------------------------------------------------------- // MapField Handlers // ----------------------------------------------------------------------------- static bool map_field_read_dimension(zval *object, zval *key, int type, - zval **retval TSRMLS_DC) { - Map *intern = - (Map *)zend_object_store_get_object(object TSRMLS_CC); + CACHED_VALUE *retval TSRMLS_DC) { + Map *intern = UNBOX(Map, object); char keybuf[TABLE_KEY_BUF_LENGTH]; const char* keyval = NULL; @@ -292,7 +281,7 @@ static bool map_field_read_dimension(zval *object, zval *key, int type, if (upb_strtable_lookup2(&intern->table, keyval, length, &v)) { void* mem = upb_value_memory(&v); - native_slot_get(intern->value_type, mem, retval TSRMLS_CC); + native_slot_get_by_array(intern->value_type, mem, retval TSRMLS_CC); return true; } else { zend_error(E_USER_ERROR, "Given key doesn't exist."); @@ -310,9 +299,9 @@ bool map_index_set(Map *intern, const char* keyval, int length, upb_value v) { return true; } -static bool map_field_write_dimension(zval *object, zval *key, +static void map_field_write_dimension(zval *object, zval *key, zval *value TSRMLS_DC) { - Map *intern = (Map *)zend_object_store_get_object(object TSRMLS_CC); + Map *intern = UNBOX(Map, object); char keybuf[TABLE_KEY_BUF_LENGTH]; const char* keyval = NULL; @@ -320,14 +309,14 @@ static bool map_field_write_dimension(zval *object, zval *key, upb_value v; void* mem; if (!table_key(intern, key, keybuf, &keyval, &length TSRMLS_CC)) { - return false; + return; } mem = upb_value_memory(&v); memset(mem, 0, native_slot_size(intern->value_type)); - if (!native_slot_set(intern->value_type, intern->msg_ce, mem, - value TSRMLS_CC)) { - return false; + if (!native_slot_set_by_array(intern->value_type, intern->msg_ce, mem, + value TSRMLS_CC)) { + return; } #ifndef NDEBUG v.ctype = UPB_CTYPE_UINT64; @@ -337,14 +326,12 @@ static bool map_field_write_dimension(zval *object, zval *key, upb_strtable_remove2(&intern->table, keyval, length, NULL); if (!upb_strtable_insert2(&intern->table, keyval, length, v)) { zend_error(E_USER_ERROR, "Could not insert into table"); - return false; + return; } - - return true; } static bool map_field_unset_dimension(zval *object, zval *key TSRMLS_DC) { - Map *intern = (Map *)zend_object_store_get_object(object TSRMLS_CC); + Map *intern = UNBOX(Map, object); char keybuf[TABLE_KEY_BUF_LENGTH]; const char* keyval = NULL; @@ -375,8 +362,7 @@ PHP_METHOD(MapField, __construct) { return; } - Map* intern = - (Map*)zend_object_store_get_object(getThis() TSRMLS_CC); + Map *intern = UNBOX(Map, getThis()); intern->key_type = to_fieldtype(key_type); intern->value_type = to_fieldtype(value_type); intern->msg_ce = klass; @@ -404,7 +390,7 @@ PHP_METHOD(MapField, offsetExists) { return; } - Map *intern = (Map *)zend_object_store_get_object(getThis() TSRMLS_CC); + Map *intern = UNBOX(Map, getThis()); char keybuf[TABLE_KEY_BUF_LENGTH]; const char* keyval = NULL; @@ -427,7 +413,7 @@ PHP_METHOD(MapField, offsetGet) { return; } map_field_read_dimension(getThis(), index, BP_VAR_R, - return_value_ptr TSRMLS_CC); + ZVAL_PTR_TO_CACHED_PTR(return_value) TSRMLS_CC); } PHP_METHOD(MapField, offsetSet) { @@ -449,8 +435,7 @@ PHP_METHOD(MapField, offsetUnset) { } PHP_METHOD(MapField, count) { - Map *intern = - (Map *)zend_object_store_get_object(getThis() TSRMLS_CC); + Map *intern = UNBOX(Map, getThis()); if (zend_parse_parameters_none() == FAILURE) { return; diff --git a/third_party/protobuf/3.2.0/php/ext/google/protobuf/message.c b/third_party/protobuf/3.2.0/php/ext/google/protobuf/message.c index 59ce6ae6d9..cabc39879e 100644 --- a/third_party/protobuf/3.2.0/php/ext/google/protobuf/message.c +++ b/third_party/protobuf/3.2.0/php/ext/google/protobuf/message.c @@ -53,40 +53,64 @@ static zend_function_entry message_methods[] = { // Forward declare static functions. +#if PHP_MAJOR_VERSION < 7 static void message_set_property(zval* object, zval* member, zval* value, - const zend_literal* key TSRMLS_DC); + php_proto_zend_literal key TSRMLS_DC); static zval* message_get_property(zval* object, zval* member, int type, const zend_literal* key TSRMLS_DC); static zval** message_get_property_ptr_ptr(zval* object, zval* member, int type, - const zend_literal* key TSRMLS_DC); -static HashTable* message_get_properties(zval* object TSRMLS_DC); + php_proto_zend_literal key TSRMLS_DC); static HashTable* message_get_gc(zval* object, zval*** table, int* n TSRMLS_DC); - -static zend_object_value message_create(zend_class_entry* ce TSRMLS_DC); -static void message_free(void* object TSRMLS_DC); +#else +static void message_set_property(zval* object, zval* member, zval* value, + void** cache_slot); +static zval* message_get_property(zval* object, zval* member, int type, + void** cache_slot, zval* rv); +static zval* message_get_property_ptr_ptr(zval* object, zval* member, int type, + void** cache_slot); +static HashTable* message_get_gc(zval* object, zval** table, int* n); +#endif +static HashTable* message_get_properties(zval* object TSRMLS_DC); // ----------------------------------------------------------------------------- // PHP Message Handlers // ----------------------------------------------------------------------------- -void message_init(TSRMLS_D) { - zend_class_entry class_type; - INIT_CLASS_ENTRY(class_type, "Google\\Protobuf\\Internal\\Message", - message_methods); - message_type = zend_register_internal_class(&class_type TSRMLS_CC); - - message_handlers = PEMALLOC(zend_object_handlers); - memcpy(message_handlers, zend_get_std_object_handlers(), - sizeof(zend_object_handlers)); +// Define object free method. +PHP_PROTO_OBJECT_FREE_START(MessageHeader, message) + FREE(intern->data); +PHP_PROTO_OBJECT_FREE_END + +PHP_PROTO_OBJECT_DTOR_START(MessageHeader, message) +PHP_PROTO_OBJECT_DTOR_END + +// Define object create method. +PHP_PROTO_OBJECT_CREATE_START(MessageHeader, message) +// Because php call this create func before calling the sub-message's +// constructor defined in PHP, it's possible that the decriptor of this class +// hasn't been added to descritpor pool (when the class is first +// instantiated). In that case, we will defer the initialization of the custom +// data to the parent Message's constructor, which will be called by +// sub-message's constructors after the descriptor has been added. +PHP_PROTO_OBJECT_CREATE_END(MessageHeader, message) + +// Init class entry. +PHP_PROTO_INIT_CLASS_START("Google\\Protobuf\\Internal\\Message", + MessageHeader, message) message_handlers->write_property = message_set_property; message_handlers->read_property = message_get_property; message_handlers->get_property_ptr_ptr = message_get_property_ptr_ptr; message_handlers->get_properties = message_get_properties; message_handlers->get_gc = message_get_gc; -} +PHP_PROTO_INIT_CLASS_END +#if PHP_MAJOR_VERSION < 7 static void message_set_property(zval* object, zval* member, zval* value, - const zend_literal* key TSRMLS_DC) { + php_proto_zend_literal key TSRMLS_DC) { +#else +static void message_set_property(zval* object, zval* member, zval* value, + void** cache_slot) { +#endif if (Z_TYPE_P(member) != IS_STRING) { zend_error(E_USER_ERROR, "Unexpected type for field name"); return; @@ -100,7 +124,7 @@ static void message_set_property(zval* object, zval* member, zval* value, const upb_fielddef* field; - MessageHeader* self = zend_object_store_get_object(object TSRMLS_CC); + MessageHeader* self = UNBOX(MessageHeader, object); field = upb_msgdef_ntofz(self->descriptor->msgdef, Z_STRVAL_P(member)); if (field == NULL) { @@ -110,46 +134,55 @@ static void message_set_property(zval* object, zval* member, zval* value, layout_set(self->descriptor->layout, self, field, value TSRMLS_CC); } +#if PHP_MAJOR_VERSION < 7 static zval* message_get_property(zval* object, zval* member, int type, const zend_literal* key TSRMLS_DC) { +#else +static zval* message_get_property(zval* object, zval* member, int type, + void** cache_slot, zval* rv) { +#endif if (Z_TYPE_P(member) != IS_STRING) { zend_error(E_USER_ERROR, "Property name has to be a string."); - return EG(uninitialized_zval_ptr); + return PHP_PROTO_GLOBAL_UNINITIALIZED_ZVAL; } if (Z_OBJCE_P(object) != EG(scope)) { // User cannot get property directly (e.g., $a = $m->a) zend_error(E_USER_ERROR, "Cannot access private property."); - return EG(uninitialized_zval_ptr); + return PHP_PROTO_GLOBAL_UNINITIALIZED_ZVAL; } - zend_property_info* property_info = NULL; - - // All properties should have been declared in the generated code and have - // corresponding zvals in properties_table. - ulong h = zend_get_hash_value(Z_STRVAL_P(member), Z_STRLEN_P(member) + 1); - if (zend_hash_quick_find(&Z_OBJCE_P(object)->properties_info, - Z_STRVAL_P(member), Z_STRLEN_P(member) + 1, h, - (void**)&property_info) != SUCCESS) { - zend_error(E_USER_ERROR, "Property does not exist."); - return EG(uninitialized_zval_ptr); - } - - MessageHeader* self = - (MessageHeader*)zend_object_store_get_object(object TSRMLS_CC); - + MessageHeader* self = UNBOX(MessageHeader, object); const upb_fielddef* field; field = upb_msgdef_ntofz(self->descriptor->msgdef, Z_STRVAL_P(member)); if (field == NULL) { - return EG(uninitialized_zval_ptr); + return PHP_PROTO_GLOBAL_UNINITIALIZED_ZVAL; } + + zend_property_info* property_info; +#if PHP_MAJOR_VERSION < 7 + property_info = + zend_get_property_info(Z_OBJCE_P(object), member, true TSRMLS_CC); return layout_get( self->descriptor->layout, message_data(self), field, &Z_OBJ_P(object)->properties_table[property_info->offset] TSRMLS_CC); +#else + property_info = + zend_get_property_info(Z_OBJCE_P(object), Z_STR_P(member), true); + return layout_get( + self->descriptor->layout, message_data(self), field, + OBJ_PROP(Z_OBJ_P(object), property_info->offset) TSRMLS_CC); +#endif } +#if PHP_MAJOR_VERSION < 7 static zval** message_get_property_ptr_ptr(zval* object, zval* member, int type, - const zend_literal* key TSRMLS_DC) { + php_proto_zend_literal key + TSRMLS_DC) { +#else +static zval* message_get_property_ptr_ptr(zval* object, zval* member, int type, + void** cache_slot) { +#endif return NULL; } @@ -157,68 +190,37 @@ static HashTable* message_get_properties(zval* object TSRMLS_DC) { return NULL; } -static HashTable* message_get_gc(zval* object, zval*** table, int* n TSRMLS_DC) { - zend_object* zobj = Z_OBJ_P(object); - *table = zobj->properties_table; - *n = zobj->ce->default_properties_count; - return NULL; +static HashTable* message_get_gc(zval* object, CACHED_VALUE** table, + int* n TSRMLS_DC) { + zend_object* zobj = Z_OBJ_P(object); + *table = zobj->properties_table; + *n = zobj->ce->default_properties_count; + return NULL; } // ----------------------------------------------------------------------------- // C Message Utilities // ----------------------------------------------------------------------------- -void* message_data(void* msg) { - return ((uint8_t*)msg) + sizeof(MessageHeader); +void* message_data(MessageHeader* msg) { + return msg->data; } -static void message_free(void* object TSRMLS_DC) { - MessageHeader* msg = (MessageHeader*)object; - int i; - - for (i = 0; i < msg->std.ce->default_properties_count; i++) { - zval_ptr_dtor(&msg->std.properties_table[i]); - } - efree(msg->std.properties_table); - efree(msg); -} - -static zend_object_value message_create(zend_class_entry* ce TSRMLS_DC) { - zend_object_value return_value; - - zval* php_descriptor = get_ce_obj(ce); - - Descriptor* desc = zend_object_store_get_object(php_descriptor TSRMLS_CC); - MessageHeader* msg = (MessageHeader*)ALLOC_N( - uint8_t, sizeof(MessageHeader) + desc->layout->size); - memset(message_data(msg), 0, desc->layout->size); - +void custom_data_init(const zend_class_entry* ce, + MessageHeader* intern PHP_PROTO_TSRMLS_DC) { + Descriptor* desc = UNBOX_HASHTABLE_VALUE(Descriptor, get_ce_obj(ce)); + intern->data = ALLOC_N(uint8_t, desc->layout->size); + memset(message_data(intern), 0, desc->layout->size); // We wrap first so that everything in the message object is GC-rooted in // case a collection happens during object creation in layout_init(). - msg->descriptor = desc; - - zend_object_std_init(&msg->std, ce TSRMLS_CC); - object_properties_init(&msg->std, ce); - layout_init(desc->layout, message_data(msg), - msg->std.properties_table TSRMLS_CC); - - return_value.handle = zend_objects_store_put( - msg, (zend_objects_store_dtor_t)zend_objects_destroy_object, message_free, - NULL TSRMLS_CC); - - return_value.handlers = message_handlers; - return return_value; + intern->descriptor = desc; + layout_init(desc->layout, message_data(intern), + intern->std.properties_table PHP_PROTO_TSRMLS_CC); } -void message_create_with_type(zend_class_entry* ce, zval** message TSRMLS_DC) { - MAKE_STD_ZVAL(*message); - Z_TYPE_PP(message) = IS_OBJECT; - Z_OBJVAL_PP(message) = ce->create_object(ce TSRMLS_CC); - Z_DELREF_PP(message); -} - -void build_class_from_descriptor(zval* php_descriptor TSRMLS_DC) { - Descriptor* desc = UNBOX(Descriptor, php_descriptor); +void build_class_from_descriptor( + PHP_PROTO_HASHTABLE_VALUE php_descriptor TSRMLS_DC) { + Descriptor* desc = UNBOX_HASHTABLE_VALUE(Descriptor, php_descriptor); // Map entries don't have existing php class. if (upb_msgdef_mapentry(desc->msgdef)) { @@ -243,26 +245,18 @@ void build_class_from_descriptor(zval* php_descriptor TSRMLS_DC) { // modified. As a result, the first created instance will be a normal zend // object. Here, we manually modify it to our message in such a case. PHP_METHOD(Message, __construct) { - if (Z_OBJVAL_P(getThis()).handlers != message_handlers) { - zend_class_entry* ce = Z_OBJCE_P(getThis()); - zval_dtor(getThis()); - Z_OBJVAL_P(getThis()) = message_create(ce TSRMLS_CC); + zend_class_entry* ce = Z_OBJCE_P(getThis()); + if (EXPECTED(class_added(ce))) { + MessageHeader* intern = UNBOX(MessageHeader, getThis()); + custom_data_init(ce, intern PHP_PROTO_TSRMLS_CC); } } PHP_METHOD(Message, clear) { - MessageHeader* msg = - (MessageHeader*)zend_object_store_get_object(getThis() TSRMLS_CC); + MessageHeader* msg = UNBOX(MessageHeader, getThis()); Descriptor* desc = msg->descriptor; zend_class_entry* ce = desc->klass; - int i; - - for (i = 0; i < msg->std.ce->default_properties_count; i++) { - zval_ptr_dtor(&msg->std.properties_table[i]); - } - efree(msg->std.properties_table); - zend_object_std_init(&msg->std, ce TSRMLS_CC); object_properties_init(&msg->std, ce); layout_init(desc->layout, message_data(msg), msg->std.properties_table TSRMLS_CC); @@ -275,10 +269,8 @@ PHP_METHOD(Message, mergeFrom) { return; } - MessageHeader* from = - (MessageHeader*)zend_object_store_get_object(value TSRMLS_CC); - MessageHeader* to = - (MessageHeader*)zend_object_store_get_object(getThis() TSRMLS_CC); + MessageHeader* from = UNBOX(MessageHeader, value); + MessageHeader* to = UNBOX(MessageHeader, getThis()); if(from->descriptor != to->descriptor) { zend_error(E_USER_ERROR, "Cannot merge messages with different class."); @@ -289,36 +281,37 @@ PHP_METHOD(Message, mergeFrom) { } PHP_METHOD(Message, readOneof) { - long index; + PHP_PROTO_LONG index; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) { return; } - MessageHeader* msg = - (MessageHeader*)zend_object_store_get_object(getThis() TSRMLS_CC); + MessageHeader* msg = UNBOX(MessageHeader, getThis()); const upb_fielddef* field = upb_msgdef_itof(msg->descriptor->msgdef, index); int property_cache_index = msg->descriptor->layout->fields[upb_fielddef_index(field)].cache_index; - zval** cache_ptr = &(msg->std.properties_table)[property_cache_index]; + zval* property_ptr = OBJ_PROP(Z_OBJ_P(getThis()), property_cache_index); + // Unlike singular fields, oneof fields share cached property. So we cannot + // let lay_get modify the cached property. Instead, we pass in the return + // value directly. layout_get(msg->descriptor->layout, message_data(msg), field, - &return_value TSRMLS_CC); + ZVAL_PTR_TO_CACHED_PTR(return_value) TSRMLS_CC); } PHP_METHOD(Message, writeOneof) { - long index; + PHP_PROTO_LONG index; zval* value; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz", &index, &value) == FAILURE) { return; } - MessageHeader* msg = - (MessageHeader*)zend_object_store_get_object(getThis() TSRMLS_CC); + MessageHeader* msg = UNBOX(MessageHeader, getThis()); const upb_fielddef* field = upb_msgdef_itof(msg->descriptor->msgdef, index); @@ -327,19 +320,18 @@ PHP_METHOD(Message, writeOneof) { PHP_METHOD(Message, whichOneof) { char* oneof_name; - int length; + PHP_PROTO_SIZE length; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &oneof_name, &length) == FAILURE) { return; } - MessageHeader* msg = - (MessageHeader*)zend_object_store_get_object(getThis() TSRMLS_CC); + MessageHeader* msg = UNBOX(MessageHeader, getThis()); const upb_oneofdef* oneof = upb_msgdef_ntoo(msg->descriptor->msgdef, oneof_name, length); const char* oneof_case_name = layout_get_oneof_case( msg->descriptor->layout, message_data(msg), oneof TSRMLS_CC); - RETURN_STRING(oneof_case_name, 1); + PHP_PROTO_RETURN_STRING(oneof_case_name, 1); } diff --git a/third_party/protobuf/3.2.0/php/ext/google/protobuf/package.xml b/third_party/protobuf/3.2.0/php/ext/google/protobuf/package.xml index aac73d0511..a2a8e0668c 100644 --- a/third_party/protobuf/3.2.0/php/ext/google/protobuf/package.xml +++ b/third_party/protobuf/3.2.0/php/ext/google/protobuf/package.xml @@ -13,16 +13,16 @@ 2017-01-13 - 3.2.0a1 - 3.2.0a1 + 3.3.0 + 3.3.0 - alpha - alpha + stable + stable 3-Clause BSD License -Second alpha release. +GA release.

@@ -87,5 +87,21 @@ First alpha release Second alpha release. + + + 3.3.0 + 3.3.0 + + + stable + stable + + 2017-04-28 + + 3-Clause BSD License + +GA release. + + diff --git a/third_party/protobuf/3.2.0/php/ext/google/protobuf/protobuf.c b/third_party/protobuf/3.2.0/php/ext/google/protobuf/protobuf.c index ea85b999f8..6a848b278e 100644 --- a/third_party/protobuf/3.2.0/php/ext/google/protobuf/protobuf.c +++ b/third_party/protobuf/3.2.0/php/ext/google/protobuf/protobuf.c @@ -55,39 +55,60 @@ static void add_to_table(HashTable* t, const void* def, void* value) { uint nIndex = (ulong)def & t->nTableMask; zval* pDest = NULL; - zend_hash_index_update(t, (zend_ulong)def, &value, sizeof(zval*), (void**)&pDest); + php_proto_zend_hash_index_update(t, (zend_ulong)def, &value, sizeof(zval*), + (void**)&pDest); } static void* get_from_table(const HashTable* t, const void* def) { void** value; - if (zend_hash_index_find(t, (zend_ulong)def, (void**)&value) == FAILURE) { + if (php_proto_zend_hash_index_find(t, (zend_ulong)def, (void**)&value) == + FAILURE) { zend_error(E_ERROR, "PHP object not found for given definition.\n"); return NULL; } return *value; } +static bool exist_in_table(const HashTable* t, const void* def) { + void** value; + return (php_proto_zend_hash_index_find(t, (zend_ulong)def, (void**)&value) == + SUCCESS); +} + static void add_to_list(HashTable* t, void* value) { zval* pDest = NULL; - zend_hash_next_index_insert(t, &value, sizeof(void*), (void**)&pDest); + php_proto_zend_hash_next_index_insert(t, &value, sizeof(void*), + (void**)&pDest); } -void add_def_obj(const void* def, zval* value) { +void add_def_obj(const void* def, PHP_PROTO_HASHTABLE_VALUE value) { +#if PHP_MAJOR_VERSION < 7 Z_ADDREF_P(value); +#else + ++GC_REFCOUNT(value); +#endif add_to_table(upb_def_to_php_obj_map, def, value); } -zval* get_def_obj(const void* def) { - return (zval*)get_from_table(upb_def_to_php_obj_map, def); +PHP_PROTO_HASHTABLE_VALUE get_def_obj(const void* def) { + return (PHP_PROTO_HASHTABLE_VALUE)get_from_table(upb_def_to_php_obj_map, def); } -void add_ce_obj(const void* ce, zval* value) { +void add_ce_obj(const void* ce, PHP_PROTO_HASHTABLE_VALUE value) { +#if PHP_MAJOR_VERSION < 7 Z_ADDREF_P(value); +#else + ++GC_REFCOUNT(value); +#endif add_to_table(ce_to_php_obj_map, ce, value); } -zval* get_ce_obj(const void* ce) { - return (zval*)get_from_table(ce_to_php_obj_map, ce); +PHP_PROTO_HASHTABLE_VALUE get_ce_obj(const void* ce) { + return (PHP_PROTO_HASHTABLE_VALUE)get_from_table(ce_to_php_obj_map, ce); +} + +bool class_added(const void* ce) { + return exist_in_table(ce_to_php_obj_map, ce); } // ----------------------------------------------------------------------------- @@ -125,12 +146,23 @@ static PHP_GINIT_FUNCTION(protobuf) { static PHP_GSHUTDOWN_FUNCTION(protobuf) { } +#if PHP_MAJOR_VERSION >= 7 +static void php_proto_hashtable_descriptor_release(zval* value) { + void* ptr = Z_PTR_P(value); + zend_object* object = *(zend_object**)ptr; + if(--GC_REFCOUNT(object) == 0) { + zend_objects_store_del(object); + } + efree(ptr); +} +#endif + static PHP_RINIT_FUNCTION(protobuf) { ALLOC_HASHTABLE(upb_def_to_php_obj_map); - zend_hash_init(upb_def_to_php_obj_map, 16, NULL, ZVAL_PTR_DTOR, 0); + zend_hash_init(upb_def_to_php_obj_map, 16, NULL, HASHTABLE_VALUE_DTOR, 0); ALLOC_HASHTABLE(ce_to_php_obj_map); - zend_hash_init(ce_to_php_obj_map, 16, NULL, ZVAL_PTR_DTOR, 0); + zend_hash_init(ce_to_php_obj_map, 16, NULL, HASHTABLE_VALUE_DTOR, 0); generated_pool = NULL; generated_pool_php = NULL; @@ -145,10 +177,12 @@ static PHP_RSHUTDOWN_FUNCTION(protobuf) { zend_hash_destroy(ce_to_php_obj_map); FREE_HASHTABLE(ce_to_php_obj_map); +#if PHP_MAJOR_VERSION < 7 if (generated_pool_php != NULL) { zval_dtor(generated_pool_php); FREE_ZVAL(generated_pool_php); } +#endif return 0; } @@ -170,6 +204,7 @@ static PHP_MINIT_FUNCTION(protobuf) { static PHP_MSHUTDOWN_FUNCTION(protobuf) { PEFREE(message_handlers); PEFREE(repeated_field_handlers); + PEFREE(repeated_field_iter_handlers); PEFREE(map_field_handlers); return 0; diff --git a/third_party/protobuf/3.2.0/php/ext/google/protobuf/protobuf.h b/third_party/protobuf/3.2.0/php/ext/google/protobuf/protobuf.h index 2287f7e617..e6d42ebacc 100644 --- a/third_party/protobuf/3.2.0/php/ext/google/protobuf/protobuf.h +++ b/third_party/protobuf/3.2.0/php/ext/google/protobuf/protobuf.h @@ -37,11 +37,328 @@ #include "upb.h" #define PHP_PROTOBUF_EXTNAME "protobuf" -#define PHP_PROTOBUF_VERSION "3.2.0a1" +#define PHP_PROTOBUF_VERSION "3.3.0" #define MAX_LENGTH_OF_INT64 20 #define SIZEOF_INT64 8 +// ----------------------------------------------------------------------------- +// PHP7 Wrappers +// ---------------------------------------------------------------------------- + +#if PHP_MAJOR_VERSION < 7 + +#define php_proto_zend_literal const zend_literal* +#define PHP_PROTO_CASE_IS_BOOL IS_BOOL +#define PHP_PROTO_SIZE int +#define PHP_PROTO_LONG long +#define PHP_PROTO_TSRMLS_DC TSRMLS_DC +#define PHP_PROTO_TSRMLS_CC TSRMLS_CC + +// PHP String + +#define PHP_PROTO_ZVAL_STRING(zval_ptr, s, copy) \ + ZVAL_STRING(zval_ptr, s, copy) +#define PHP_PROTO_ZVAL_STRINGL(zval_ptr, s, len, copy) \ + ZVAL_STRINGL(zval_ptr, s, len, copy) +#define PHP_PROTO_RETURN_STRING(s, copy) RETURN_STRING(s, copy) +#define PHP_PROTO_RETURN_STRINGL(s, len, copy) RETURN_STRINGL(s, len, copy) +#define PHP_PROTO_RETVAL_STRINGL(s, len, copy) RETVAL_STRINGL(s, len, copy) +#define php_proto_zend_make_printable_zval(from, to) \ + { \ + int use_copy; \ + zend_make_printable_zval(from, to, &use_copy); \ + } + +// PHP Array + +#define PHP_PROTO_HASH_OF(array) Z_ARRVAL_P(array) + +#define php_proto_zend_hash_index_update(ht, h, pData, nDataSize, pDest) \ + zend_hash_index_update(ht, h, pData, nDataSize, pDest) + +#define php_proto_zend_hash_index_find(ht, h, pDest) \ + zend_hash_index_find(ht, h, pDest) + +#define php_proto_zend_hash_next_index_insert(ht, pData, nDataSize, pDest) \ + zend_hash_next_index_insert(ht, pData, nDataSize, pDest) + +#define php_proto_zend_hash_get_current_data_ex(ht, pDest, pos) \ + zend_hash_get_current_data_ex(ht, pDest, pos) + +// PHP Object + +#define PHP_PROTO_WRAP_OBJECT_START(name) \ + struct name { \ + zend_object std; +#define PHP_PROTO_WRAP_OBJECT_END \ + }; + +#define PHP_PROTO_INIT_CLASS_START(CLASSNAME, CAMELNAME, LOWWERNAME) \ + void LOWWERNAME##_init(TSRMLS_D) { \ + zend_class_entry class_type; \ + const char* class_name = CLASSNAME; \ + INIT_CLASS_ENTRY_EX(class_type, CLASSNAME, strlen(CLASSNAME), \ + LOWWERNAME##_methods); \ + LOWWERNAME##_type = zend_register_internal_class(&class_type TSRMLS_CC); \ + LOWWERNAME##_type->create_object = LOWWERNAME##_create; \ + LOWWERNAME##_handlers = PEMALLOC(zend_object_handlers); \ + memcpy(LOWWERNAME##_handlers, zend_get_std_object_handlers(), \ + sizeof(zend_object_handlers)); +#define PHP_PROTO_INIT_CLASS_END \ + } + +#define PHP_PROTO_OBJECT_CREATE_START(NAME, LOWWERNAME) \ + static zend_object_value LOWWERNAME##_create( \ + zend_class_entry* ce TSRMLS_DC) { \ + PHP_PROTO_ALLOC_CLASS_OBJECT(NAME, ce); \ + zend_object_std_init(&intern->std, ce TSRMLS_CC); \ + object_properties_init(&intern->std, ce); +#define PHP_PROTO_OBJECT_CREATE_END(NAME, LOWWERNAME) \ + PHP_PROTO_FREE_CLASS_OBJECT(NAME, LOWWERNAME##_free, LOWWERNAME##_handlers); \ + } + +#define PHP_PROTO_OBJECT_FREE_START(classname, lowername) \ + void lowername##_free(void* object TSRMLS_DC) { \ + classname* intern = object; +#define PHP_PROTO_OBJECT_FREE_END \ + zend_object_std_dtor(&intern->std TSRMLS_CC); \ + efree(intern); \ + } + +#define PHP_PROTO_OBJECT_DTOR_START(classname, lowername) +#define PHP_PROTO_OBJECT_DTOR_END + +#define CACHED_VALUE zval* +#define CACHED_TO_ZVAL_PTR(VALUE) (VALUE) +#define CACHED_PTR_TO_ZVAL_PTR(VALUE) (*VALUE) +#define ZVAL_PTR_TO_CACHED_PTR(VALUE) (&VALUE) + +#define CREATE_OBJ_ON_ALLOCATED_ZVAL_PTR(zval_ptr, class_type) \ + ZVAL_OBJ(zval_ptr, class_type->create_object(class_type TSRMLS_CC)); + +#define PHP_PROTO_SEPARATE_ZVAL_IF_NOT_REF(value) \ + SEPARATE_ZVAL_IF_NOT_REF(value) + +#define PHP_PROTO_GLOBAL_UNINITIALIZED_ZVAL EG(uninitialized_zval_ptr) + +#define OBJ_PROP(PROPERTIES, OFFSET) (PROPERTIES)->properties_table[OFFSET] + +#define php_proto_zval_ptr_dtor(zval_ptr) \ + zval_ptr_dtor(&(zval_ptr)) + +#define PHP_PROTO_ALLOC_CLASS_OBJECT(class_object, class_type) \ + class_object* intern; \ + intern = (class_object*)emalloc(sizeof(class_object)); \ + memset(intern, 0, sizeof(class_object)); + +#define PHP_PROTO_FREE_CLASS_OBJECT(class_object, class_object_free, handler) \ + zend_object_value retval = {0}; \ + retval.handle = zend_objects_store_put( \ + intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, \ + class_object_free, NULL TSRMLS_CC); \ + retval.handlers = handler; \ + return retval; + +#define PHP_PROTO_ALLOC_ARRAY(zval_ptr) \ + ALLOC_HASHTABLE(Z_ARRVAL_P(zval_ptr)); \ + Z_TYPE_P(zval_ptr) = IS_ARRAY; + +#define ZVAL_OBJ(zval_ptr, call_create) \ + Z_TYPE_P(zval_ptr) = IS_OBJECT; \ + Z_OBJVAL_P(zval_ptr) = call_create; + +#define UNBOX(class_name, val) \ + (class_name*)zend_object_store_get_object(val TSRMLS_CC); + +#define UNBOX_HASHTABLE_VALUE(class_name, val) UNBOX(class_name, val) + +#define HASHTABLE_VALUE_DTOR ZVAL_PTR_DTOR + +#define PHP_PROTO_HASHTABLE_VALUE zval* + +#define CREATE_HASHTABLE_VALUE(OBJ, WRAPPED_OBJ, OBJ_TYPE, OBJ_CLASS_ENTRY) \ + OBJ_TYPE* OBJ; \ + PHP_PROTO_HASHTABLE_VALUE WRAPPED_OBJ; \ + MAKE_STD_ZVAL(WRAPPED_OBJ); \ + ZVAL_OBJ(WRAPPED_OBJ, \ + OBJ_CLASS_ENTRY->create_object(OBJ_CLASS_ENTRY TSRMLS_CC)); \ + OBJ = UNBOX_HASHTABLE_VALUE(OBJ_TYPE, WRAPPED_OBJ); \ + Z_DELREF_P(desc_php); + +#define PHP_PROTO_CE_DECLARE zend_class_entry** +#define PHP_PROTO_CE_UNREF(ce) (*ce) + +#define php_proto_zend_lookup_class(name, name_length, ce) \ + zend_lookup_class(name, name_length, ce TSRMLS_CC) + +#else // PHP_MAJOR_VERSION >= 7 + +#define php_proto_zend_literal void** +#define PHP_PROTO_CASE_IS_BOOL IS_TRUE: case IS_FALSE +#define PHP_PROTO_SIZE size_t +#define PHP_PROTO_LONG zend_long +#define PHP_PROTO_TSRMLS_DC +#define PHP_PROTO_TSRMLS_CC + +// PHP String + +#define PHP_PROTO_ZVAL_STRING(zval_ptr, s, copy) \ + ZVAL_STRING(zval_ptr, s) +#define PHP_PROTO_ZVAL_STRINGL(zval_ptr, s, len, copy) \ + ZVAL_STRINGL(zval_ptr, s, len) +#define PHP_PROTO_RETURN_STRING(s, copy) RETURN_STRING(s) +#define PHP_PROTO_RETURN_STRINGL(s, len, copy) RETURN_STRINGL(s, len) +#define PHP_PROTO_RETVAL_STRINGL(s, len, copy) RETVAL_STRINGL(s, len) +#define php_proto_zend_make_printable_zval(from, to) \ + zend_make_printable_zval(from, to) + +// PHP Array + +#define PHP_PROTO_HASH_OF(array) Z_ARRVAL_P(&array) + +static inline int php_proto_zend_hash_index_update(HashTable* ht, ulong h, + void* pData, uint nDataSize, + void** pDest) { + void* result = NULL; + result = zend_hash_index_update_mem(ht, h, pData, nDataSize); + if (pDest != NULL) *pDest = result; + return result != NULL ? SUCCESS : FAILURE; +} + +static inline int php_proto_zend_hash_index_find(const HashTable* ht, ulong h, + void** pDest) { + void* result = NULL; + result = zend_hash_index_find_ptr(ht, h); + if (pDest != NULL) *pDest = result; + return result != NULL ? SUCCESS : FAILURE; +} + +static inline int php_proto_zend_hash_next_index_insert(HashTable* ht, + void* pData, + uint nDataSize, + void** pDest) { + void* result = NULL; + result = zend_hash_next_index_insert_mem(ht, pData, nDataSize); + if (pDest != NULL) *pDest = result; + return result != NULL ? SUCCESS : FAILURE; +} + +static inline int php_proto_zend_hash_get_current_data_ex(HashTable* ht, + void** pDest, + HashPosition* pos) { + void* result = NULL; + result = zend_hash_get_current_data_ex(ht, pos); + if (pDest != NULL) *pDest = result; + return result != NULL ? SUCCESS : FAILURE; +} + +// PHP Object + +#define PHP_PROTO_WRAP_OBJECT_START(name) struct name { +#define PHP_PROTO_WRAP_OBJECT_END \ + zend_object std; \ + }; + +#define PHP_PROTO_INIT_CLASS_START(CLASSNAME, CAMELNAME, LOWWERNAME) \ + void LOWWERNAME##_init(TSRMLS_D) { \ + zend_class_entry class_type; \ + const char* class_name = CLASSNAME; \ + INIT_CLASS_ENTRY_EX(class_type, CLASSNAME, strlen(CLASSNAME), \ + LOWWERNAME##_methods); \ + LOWWERNAME##_type = zend_register_internal_class(&class_type TSRMLS_CC); \ + LOWWERNAME##_type->create_object = LOWWERNAME##_create; \ + LOWWERNAME##_handlers = PEMALLOC(zend_object_handlers); \ + memcpy(LOWWERNAME##_handlers, zend_get_std_object_handlers(), \ + sizeof(zend_object_handlers)); \ + LOWWERNAME##_handlers->free_obj = LOWWERNAME##_free; \ + LOWWERNAME##_handlers->dtor_obj = LOWWERNAME##_dtor; \ + LOWWERNAME##_handlers->offset = XtOffsetOf(CAMELNAME, std); +#define PHP_PROTO_INIT_CLASS_END \ + } + +#define PHP_PROTO_OBJECT_FREE_START(classname, lowername) \ + void lowername##_free(zend_object* object) { \ + classname* intern = \ + (classname*)((char*)object - XtOffsetOf(classname, std)); +#define PHP_PROTO_OBJECT_FREE_END \ + } + +#define PHP_PROTO_OBJECT_DTOR_START(classname, lowername) \ + void lowername##_dtor(zend_object* object) { \ + classname* intern = \ + (classname*)((char*)object - XtOffsetOf(classname, std)); +#define PHP_PROTO_OBJECT_DTOR_END \ + zend_object_std_dtor(object TSRMLS_CC); \ + } + +#define PHP_PROTO_OBJECT_CREATE_START(NAME, LOWWERNAME) \ + static zend_object* LOWWERNAME##_create(zend_class_entry* ce TSRMLS_DC) { \ + PHP_PROTO_ALLOC_CLASS_OBJECT(NAME, ce); \ + zend_object_std_init(&intern->std, ce TSRMLS_CC); \ + object_properties_init(&intern->std, ce); +#define PHP_PROTO_OBJECT_CREATE_END(NAME, LOWWERNAME) \ + PHP_PROTO_FREE_CLASS_OBJECT(NAME, LOWWERNAME##_free, LOWWERNAME##_handlers); \ + } + +#define CACHED_VALUE zval +#define CACHED_TO_ZVAL_PTR(VALUE) (&VALUE) +#define CACHED_PTR_TO_ZVAL_PTR(VALUE) (VALUE) +#define ZVAL_PTR_TO_CACHED_PTR(VALUE) (VALUE) + +#define CREATE_OBJ_ON_ALLOCATED_ZVAL_PTR(zval_ptr, class_type) \ + ZVAL_OBJ(zval_ptr, class_type->create_object(class_type)); + +#define PHP_PROTO_SEPARATE_ZVAL_IF_NOT_REF(value) ; + +#define PHP_PROTO_GLOBAL_UNINITIALIZED_ZVAL &EG(uninitialized_zval) + +#define php_proto_zval_ptr_dtor(zval_ptr) \ + zval_ptr_dtor(zval_ptr) + +#define PHP_PROTO_ALLOC_CLASS_OBJECT(class_object, class_type) \ + class_object* intern; \ + int size = sizeof(class_object) + zend_object_properties_size(class_type); \ + intern = ecalloc(1, size); \ + memset(intern, 0, size); + +#define PHP_PROTO_FREE_CLASS_OBJECT(class_object, class_object_free, handler) \ + intern->std.handlers = handler; \ + return &intern->std; + +#define PHP_PROTO_ALLOC_ARRAY(zval_ptr) \ + ZVAL_NEW_ARR(zval_ptr) + +#define UNBOX(class_name, val) \ + (class_name*)((char*)Z_OBJ_P(val) - XtOffsetOf(class_name, std)); + +#define UNBOX_HASHTABLE_VALUE(class_name, val) \ + (class_name*)((char*)val - XtOffsetOf(class_name, std)) + +#define HASHTABLE_VALUE_DTOR php_proto_hashtable_descriptor_release + +#define PHP_PROTO_HASHTABLE_VALUE zend_object* + +#define CREATE_HASHTABLE_VALUE(OBJ, WRAPPED_OBJ, OBJ_TYPE, OBJ_CLASS_ENTRY) \ + OBJ_TYPE* OBJ; \ + PHP_PROTO_HASHTABLE_VALUE WRAPPED_OBJ; \ + WRAPPED_OBJ = OBJ_CLASS_ENTRY->create_object(OBJ_CLASS_ENTRY); \ + OBJ = UNBOX_HASHTABLE_VALUE(OBJ_TYPE, WRAPPED_OBJ); \ + --GC_REFCOUNT(WRAPPED_OBJ); + +#define PHP_PROTO_CE_DECLARE zend_class_entry* +#define PHP_PROTO_CE_UNREF(ce) (ce) + +static inline int php_proto_zend_lookup_class( + const char* name, int name_length, zend_class_entry** ce TSRMLS_DC) { + zend_string *zstr_name = zend_string_init(name, name_length, 0); + *ce = zend_lookup_class(zstr_name); + zend_string_release(zstr_name); + return *ce != NULL ? SUCCESS : FAILURE; +} + +#endif // PHP_MAJOR_VERSION >= 7 + // ----------------------------------------------------------------------------- // Forward Declaration // ---------------------------------------------------------------------------- @@ -55,7 +372,8 @@ struct MessageHeader; struct MessageLayout; struct RepeatedField; struct RepeatedFieldIter; -struct MapField; +struct Map; +struct Oneof; typedef struct DescriptorPool DescriptorPool; typedef struct Descriptor Descriptor; @@ -66,7 +384,8 @@ typedef struct MessageHeader MessageHeader; typedef struct MessageLayout MessageLayout; typedef struct RepeatedField RepeatedField; typedef struct RepeatedFieldIter RepeatedFieldIter; -typedef struct MapField MapField; +typedef struct Map Map; +typedef struct Oneof Oneof; // ----------------------------------------------------------------------------- // Globals. @@ -88,13 +407,14 @@ void message_init(TSRMLS_D); // Global map from upb {msg,enum}defs to wrapper Descriptor/EnumDescriptor // instances. -void add_def_obj(const void* def, zval* value); -zval* get_def_obj(const void* def); +void add_def_obj(const void* def, PHP_PROTO_HASHTABLE_VALUE value); +PHP_PROTO_HASHTABLE_VALUE get_def_obj(const void* def); // Global map from PHP class entries to wrapper Descriptor/EnumDescriptor // instances. -void add_ce_obj(const void* ce, zval* value); -zval* get_ce_obj(const void* ce); +void add_ce_obj(const void* ce, PHP_PROTO_HASHTABLE_VALUE value); +PHP_PROTO_HASHTABLE_VALUE get_ce_obj(const void* ce); +bool class_added(const void* ce); extern zend_class_entry* map_field_type; extern zend_class_entry* repeated_field_type; @@ -103,20 +423,25 @@ extern zend_class_entry* repeated_field_type; // Descriptor. // ----------------------------------------------------------------------------- -struct DescriptorPool { - zend_object std; +PHP_PROTO_WRAP_OBJECT_START(DescriptorPool) upb_symtab* symtab; HashTable* pending_list; -}; +PHP_PROTO_WRAP_OBJECT_END PHP_METHOD(DescriptorPool, getGeneratedPool); PHP_METHOD(DescriptorPool, internalAddGeneratedFile); -extern zval* generated_pool_php; // wrapper of generated pool +// wrapper of generated pool +#if PHP_MAJOR_VERSION < 7 +extern zval* generated_pool_php; +void descriptor_pool_free(void* object TSRMLS_DC); +#else +extern zend_object *generated_pool_php; +void descriptor_pool_free(zend_object* object); +#endif extern DescriptorPool* generated_pool; // The actual generated pool -struct Descriptor { - zend_object std; +PHP_PROTO_WRAP_OBJECT_START(Descriptor) const upb_msgdef* msgdef; MessageLayout* layout; zend_class_entry* klass; // begins as NULL @@ -126,23 +451,21 @@ struct Descriptor { const upb_handlers* pb_serialize_handlers; const upb_handlers* json_serialize_handlers; const upb_handlers* json_serialize_handlers_preserve; -}; +PHP_PROTO_WRAP_OBJECT_END extern zend_class_entry* descriptor_type; void descriptor_name_set(Descriptor *desc, const char *name); -struct FieldDescriptor { - zend_object std; +PHP_PROTO_WRAP_OBJECT_START(FieldDescriptor) const upb_fielddef* fielddef; -}; +PHP_PROTO_WRAP_OBJECT_END -struct EnumDescriptor { - zend_object std; +PHP_PROTO_WRAP_OBJECT_START(EnumDescriptor) const upb_enumdef* enumdef; zend_class_entry* klass; // begins as NULL // VALUE module; // begins as nil -}; +PHP_PROTO_WRAP_OBJECT_END extern zend_class_entry* enum_descriptor_type; @@ -150,13 +473,15 @@ extern zend_class_entry* enum_descriptor_type; // Message class creation. // ----------------------------------------------------------------------------- -void* message_data(void* msg); -void message_create_with_type(zend_class_entry* ce, zval** message TSRMLS_DC); +void* message_data(MessageHeader* msg); +void custom_data_init(const zend_class_entry* ce, + MessageHeader* msg PHP_PROTO_TSRMLS_DC); // Build PHP class for given descriptor. Instead of building from scratch, this // function modifies existing class which has been partially defined in PHP // code. -void build_class_from_descriptor(zval* php_descriptor TSRMLS_DC); +void build_class_from_descriptor( + PHP_PROTO_HASHTABLE_VALUE php_descriptor TSRMLS_DC); extern zend_object_handlers* message_handlers; @@ -227,18 +552,17 @@ struct MessageLayout { size_t size; }; -struct MessageHeader { - zend_object std; // Stores properties table and class info of PHP instance. - // This is needed for MessageHeader to be accessed via PHP. +PHP_PROTO_WRAP_OBJECT_START(MessageHeader) + void* data; // Point to the real message data. + // Place needs to be consistent with map_parse_frame_data_t. Descriptor* descriptor; // Kept alive by self.class.descriptor reference. - // The real message data is appended after MessageHeader. -}; +PHP_PROTO_WRAP_OBJECT_END MessageLayout* create_layout(const upb_msgdef* msgdef); void layout_init(MessageLayout* layout, void* storage, - zval** properties_table TSRMLS_DC); + CACHED_VALUE* properties_table PHP_PROTO_TSRMLS_DC); zval* layout_get(MessageLayout* layout, const void* storage, - const upb_fielddef* field, zval** cache TSRMLS_DC); + const upb_fielddef* field, CACHED_VALUE* cache TSRMLS_DC); void layout_set(MessageLayout* layout, MessageHeader* header, const upb_fielddef* field, zval* val TSRMLS_DC); void layout_merge(MessageLayout* layout, MessageHeader* from, @@ -308,7 +632,12 @@ PHP_METHOD(Util, checkRepeatedField); size_t native_slot_size(upb_fieldtype_t type); bool native_slot_set(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, zval** cache); +// String/Message is stored differently in array/map from normal message fields. +// So we need to make a special method to handle that. +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); // 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 @@ -317,8 +646,13 @@ void native_slot_init(upb_fieldtype_t type, void* memory, zval** cache); // for providing such a zval object. Instead the caller needs to provide one // (cache) and update it with the actual data (memory). void native_slot_get(upb_fieldtype_t type, const void* memory, - zval** cache TSRMLS_DC); -void native_slot_get_default(upb_fieldtype_t type, zval** cache TSRMLS_DC); + CACHED_VALUE* cache TSRMLS_DC); +// String/Message is stored differently in array/map from normal message fields. +// So we need to make a special method to handle that. +void native_slot_get_by_array(upb_fieldtype_t type, const void* memory, + CACHED_VALUE* cache TSRMLS_DC); +void native_slot_get_default(upb_fieldtype_t type, + CACHED_VALUE* cache TSRMLS_DC); // ----------------------------------------------------------------------------- // Map Field. @@ -326,13 +660,12 @@ void native_slot_get_default(upb_fieldtype_t type, zval** cache TSRMLS_DC); extern zend_object_handlers* map_field_handlers; -typedef struct { - zend_object std; +PHP_PROTO_WRAP_OBJECT_START(Map) upb_fieldtype_t key_type; upb_fieldtype_t value_type; const zend_class_entry* msg_ce; // class entry for value message upb_strtable table; -} Map; +PHP_PROTO_WRAP_OBJECT_END typedef struct { Map* self; @@ -349,14 +682,14 @@ upb_value map_iter_value(MapIter* iter, int* len); const upb_fielddef* map_entry_key(const upb_msgdef* msgdef); const upb_fielddef* map_entry_value(const upb_msgdef* msgdef); -zend_object_value map_field_create(zend_class_entry *ce TSRMLS_DC); -void map_field_create_with_field(zend_class_entry *ce, const upb_fielddef *field, - zval **map_field TSRMLS_DC); -void map_field_create_with_type(zend_class_entry *ce, upb_fieldtype_t key_type, +void map_field_create_with_field(const zend_class_entry* ce, + const upb_fielddef* field, + CACHED_VALUE* map_field PHP_PROTO_TSRMLS_DC); +void map_field_create_with_type(const zend_class_entry* ce, + upb_fieldtype_t key_type, upb_fieldtype_t value_type, - const zend_class_entry *msg_ce, - zval **map_field TSRMLS_DC); -void map_field_free(void* object TSRMLS_DC); + const zend_class_entry* msg_ce, + CACHED_VALUE* map_field PHP_PROTO_TSRMLS_DC); void* upb_value_memory(upb_value* v); #define MAP_KEY_FIELD 1 @@ -382,33 +715,36 @@ PHP_METHOD(MapField, count); // ----------------------------------------------------------------------------- extern zend_object_handlers* repeated_field_handlers; +extern zend_object_handlers* repeated_field_iter_handlers; -struct RepeatedField { - zend_object std; +PHP_PROTO_WRAP_OBJECT_START(RepeatedField) +#if PHP_MAJOR_VERSION < 7 zval* array; +#else + zval array; +#endif upb_fieldtype_t type; const zend_class_entry* msg_ce; // class entry for containing message // (for message field only). -}; +PHP_PROTO_WRAP_OBJECT_END -struct RepeatedFieldIter { - zend_object std; +PHP_PROTO_WRAP_OBJECT_START(RepeatedFieldIter) RepeatedField* repeated_field; long position; -}; - -void repeated_field_create_with_field(zend_class_entry* ce, - const upb_fielddef* field, - zval** repeated_field TSRMLS_DC); -void repeated_field_create_with_type(zend_class_entry* ce, upb_fieldtype_t type, - const zend_class_entry* msg_ce, - zval** repeated_field TSRMLS_DC); +PHP_PROTO_WRAP_OBJECT_END + +void repeated_field_create_with_field( + zend_class_entry* ce, const upb_fielddef* field, + CACHED_VALUE* repeated_field PHP_PROTO_TSRMLS_DC); +void repeated_field_create_with_type( + zend_class_entry* ce, upb_fieldtype_t type, const zend_class_entry* msg_ce, + CACHED_VALUE* repeated_field PHP_PROTO_TSRMLS_DC); // Return the element at the index position from the repeated field. There is // not restriction on the type of stored elements. void *repeated_field_index_native(RepeatedField *intern, int index TSRMLS_DC); // Add the element to the end of the repeated field. There is not restriction on // the type of stored elements. -void repeated_field_push_native(RepeatedField *intern, void *value TSRMLS_DC); +void repeated_field_push_native(RepeatedField *intern, void *value); PHP_METHOD(RepeatedField, __construct); PHP_METHOD(RepeatedField, append); @@ -429,12 +765,11 @@ PHP_METHOD(RepeatedFieldIter, valid); // Oneof Field. // ----------------------------------------------------------------------------- -typedef struct { - zend_object std; +PHP_PROTO_WRAP_OBJECT_START(Oneof) upb_oneofdef* oneofdef; int index; // Index of field in oneof. -1 if not set. char value[NATIVE_SLOT_MAX_SIZE]; -} Oneof; +PHP_PROTO_WRAP_OBJECT_END // Oneof case slot value to indicate that no oneof case is set. The value `0` is // safe because field numbers are used as case identifiers, and no field can @@ -446,24 +781,13 @@ typedef struct { // ----------------------------------------------------------------------------- upb_fieldtype_t to_fieldtype(upb_descriptortype_t type); -const zend_class_entry *field_type_class(const upb_fielddef *field TSRMLS_DC); +const zend_class_entry* field_type_class( + const upb_fielddef* field PHP_PROTO_TSRMLS_DC); // ----------------------------------------------------------------------------- // Utilities. // ----------------------------------------------------------------------------- -// PHP <-> C conversion. -#define UNBOX(class_name, val) \ - (class_name*)zend_object_store_get_object(val TSRMLS_CC); - -#define BOX(class_name, wrapper, intern, free_func) \ - MAKE_STD_ZVAL(wrapper); \ - Z_TYPE_P(wrapper) = IS_OBJECT; \ - Z_OBJVAL_P(wrapper) \ - .handle = \ - zend_objects_store_put(intern, NULL, free_func, NULL TSRMLS_CC); \ - Z_OBJVAL_P(wrapper).handlers = zend_get_std_object_handlers(); - // Memory management #define ALLOC(class_name) (class_name*) emalloc(sizeof(class_name)) #define PEMALLOC(class_name) (class_name*) pemalloc(sizeof(class_name), 1) @@ -471,19 +795,15 @@ const zend_class_entry *field_type_class(const upb_fielddef *field TSRMLS_DC); #define FREE(object) efree(object) #define PEFREE(object) pefree(object, 1) -// Create PHP internal instance. -#define CREATE(class_name, intern, init_func) \ - intern = ALLOC(class_name); \ - memset(intern, 0, sizeof(class_name)); \ - init_func(intern TSRMLS_CC); - // String argument. #define STR(str) (str), strlen(str) // Zend Value +#if PHP_MAJOR_VERSION < 7 #define Z_OBJ_P(zval_p) \ ((zend_object*)(EG(objects_store) \ .object_buckets[Z_OBJ_HANDLE_P(zval_p)] \ .bucket.obj.object)) +#endif #endif // __GOOGLE_PROTOBUF_PHP_PROTOBUF_H__ diff --git a/third_party/protobuf/3.2.0/php/ext/google/protobuf/storage.c b/third_party/protobuf/3.2.0/php/ext/google/protobuf/storage.c index af7c292f0f..6318f88c65 100644 --- a/third_party/protobuf/3.2.0/php/ext/google/protobuf/storage.c +++ b/third_party/protobuf/3.2.0/php/ext/google/protobuf/storage.c @@ -57,7 +57,7 @@ size_t native_slot_size(upb_fieldtype_t type) { } } -static bool native_slot_is_default(upb_fieldtype_t type, void* memory) { +static bool native_slot_is_default(upb_fieldtype_t type, const void* memory) { switch (type) { #define CASE_TYPE(upb_type, c_type) \ case UPB_TYPE_##upb_type: { \ @@ -75,15 +75,17 @@ static bool native_slot_is_default(upb_fieldtype_t type, void* memory) { #undef CASE_TYPE case UPB_TYPE_STRING: case UPB_TYPE_BYTES: - return Z_STRLEN_PP(DEREF(memory, zval**)) == 0; + return Z_STRLEN_P(CACHED_PTR_TO_ZVAL_PTR(DEREF(memory, CACHED_VALUE*))) == + 0; case UPB_TYPE_MESSAGE: - return Z_TYPE_PP(DEREF(memory, zval**)) == IS_NULL; + return Z_TYPE_P(CACHED_PTR_TO_ZVAL_PTR(DEREF(memory, CACHED_VALUE*))) == + IS_NULL; default: return false; } } bool native_slot_set(upb_fieldtype_t type, const zend_class_entry* klass, - void* memory, zval* value TSRMLS_DC) { + void* memory, zval* value PHP_PROTO_TSRMLS_DC) { switch (type) { case UPB_TYPE_STRING: case UPB_TYPE_BYTES: { @@ -95,14 +97,14 @@ bool native_slot_set(upb_fieldtype_t type, const zend_class_entry* klass, zend_error(E_USER_ERROR, "Given string is not UTF8 encoded."); return false; } - if (*(zval**)memory != NULL) { + + zval* cached_zval = CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)memory); + if (EXPECTED(cached_zval != NULL)) { +#if PHP_MAJOR_VERSION < 7 REPLACE_ZVAL_VALUE((zval**)memory, value, 1); - } else { - // Handles repeated/map string field. Memory provided by - // RepeatedField/Map is not initialized. - MAKE_STD_ZVAL(DEREF(memory, zval*)); - ZVAL_STRINGL(DEREF(memory, zval*), Z_STRVAL_P(value), Z_STRLEN_P(value), - 1); +#else + zend_assign_to_variable(cached_zval, value, IS_CV); +#endif } break; } @@ -115,13 +117,18 @@ bool native_slot_set(upb_fieldtype_t type, const zend_class_entry* klass, zend_error(E_USER_ERROR, "Given message does not have correct class."); return false; } - if (EXPECTED(DEREF(memory, zval*) != value)) { - if (DEREF(memory, zval*) != NULL) { - zval_ptr_dtor((zval**)memory); - } - DEREF(memory, zval*) = value; - Z_ADDREF_P(value); + + zval* property_ptr = CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)memory); + if (EXPECTED(property_ptr != value)) { + php_proto_zval_ptr_dtor(property_ptr); } + +#if PHP_MAJOR_VERSION < 7 + DEREF(memory, zval*) = value; + Z_ADDREF_P(value); +#else + ZVAL_ZVAL(property_ptr, value, 1, 0); +#endif break; } @@ -151,7 +158,59 @@ bool native_slot_set(upb_fieldtype_t type, const zend_class_entry* klass, return true; } -void native_slot_init(upb_fieldtype_t type, void* memory, zval** cache) { +bool native_slot_set_by_array(upb_fieldtype_t type, + const zend_class_entry* klass, void* memory, + zval* value TSRMLS_DC) { + switch (type) { + case UPB_TYPE_STRING: + case UPB_TYPE_BYTES: { + if (!protobuf_convert_to_string(value)) { + return false; + } + if (type == UPB_TYPE_STRING && + !is_structurally_valid_utf8(Z_STRVAL_P(value), Z_STRLEN_P(value))) { + zend_error(E_USER_ERROR, "Given string is not UTF8 encoded."); + return false; + } + + // Handles repeated/map string field. Memory provided by + // RepeatedField/Map is not initialized. +#if PHP_MAJOR_VERSION < 7 + MAKE_STD_ZVAL(DEREF(memory, zval*)); + PHP_PROTO_ZVAL_STRINGL(DEREF(memory, zval*), Z_STRVAL_P(value), + Z_STRLEN_P(value), 1); +#else + *(zend_string**)memory = zend_string_dup(Z_STR_P(value), 0); +#endif + break; + } + case UPB_TYPE_MESSAGE: { + if (Z_TYPE_P(value) != IS_OBJECT) { + zend_error(E_USER_ERROR, "Given value is not message."); + return false; + } + if (Z_TYPE_P(value) == IS_OBJECT && klass != Z_OBJCE_P(value)) { + zend_error(E_USER_ERROR, "Given message does not have correct class."); + return false; + } +#if PHP_MAJOR_VERSION < 7 + if (EXPECTED(DEREF(memory, zval*) != value)) { + DEREF(memory, zval*) = value; + Z_ADDREF_P(value); + } +#else + DEREF(memory, zend_object*) = Z_OBJ_P(value); + ++GC_REFCOUNT(Z_OBJ_P(value)); +#endif + break; + } + default: + return native_slot_set(type, klass, memory, value TSRMLS_CC); + } + return true; +} + +void native_slot_init(upb_fieldtype_t type, void* memory, void* cache) { zval* tmp = NULL; switch (type) { case UPB_TYPE_FLOAT: @@ -166,7 +225,7 @@ void native_slot_init(upb_fieldtype_t type, void* memory, zval** cache) { case UPB_TYPE_STRING: case UPB_TYPE_BYTES: case UPB_TYPE_MESSAGE: - DEREF(memory, zval**) = cache; + DEREF(memory, CACHED_VALUE*) = cache; break; case UPB_TYPE_ENUM: case UPB_TYPE_INT32: @@ -187,38 +246,38 @@ void native_slot_init(upb_fieldtype_t type, void* memory, zval** cache) { } void native_slot_get(upb_fieldtype_t type, const void* memory, - zval** cache TSRMLS_DC) { + CACHED_VALUE* cache TSRMLS_DC) { switch (type) { -#define CASE(upb_type, php_type, c_type) \ - case UPB_TYPE_##upb_type: \ - SEPARATE_ZVAL_IF_NOT_REF(cache); \ - ZVAL_##php_type(*cache, DEREF(memory, c_type)); \ - return; +#define CASE(upb_type, php_type, c_type) \ + case UPB_TYPE_##upb_type: \ + PHP_PROTO_SEPARATE_ZVAL_IF_NOT_REF(cache); \ + ZVAL_##php_type(CACHED_PTR_TO_ZVAL_PTR(cache), DEREF(memory, c_type)); \ + return; -CASE(FLOAT, DOUBLE, float) -CASE(DOUBLE, DOUBLE, double) -CASE(BOOL, BOOL, int8_t) -CASE(INT32, LONG, int32_t) -CASE(ENUM, LONG, uint32_t) + CASE(FLOAT, DOUBLE, float) + CASE(DOUBLE, DOUBLE, double) + CASE(BOOL, BOOL, int8_t) + CASE(INT32, LONG, int32_t) + CASE(ENUM, LONG, uint32_t) #undef CASE #if SIZEOF_LONG == 4 -#define CASE(upb_type, c_type) \ - case UPB_TYPE_##upb_type: { \ - SEPARATE_ZVAL_IF_NOT_REF(cache); \ - char buffer[MAX_LENGTH_OF_INT64]; \ - sprintf(buffer, "%lld", DEREF(memory, c_type)); \ - ZVAL_STRING(*cache, buffer, 1); \ - return; \ - } +#define CASE(upb_type, c_type) \ + case UPB_TYPE_##upb_type: { \ + PHP_PROTO_SEPARATE_ZVAL_IF_NOT_REF(cache); \ + char buffer[MAX_LENGTH_OF_INT64]; \ + sprintf(buffer, "%lld", DEREF(memory, c_type)); \ + PHP_PROTO_ZVAL_STRING(CACHED_PTR_TO_ZVAL_PTR(cache), buffer, 1); \ + return; \ + } #else -#define CASE(upb_type, c_type) \ - case UPB_TYPE_##upb_type: { \ - SEPARATE_ZVAL_IF_NOT_REF(cache); \ - ZVAL_LONG(*cache, DEREF(memory, c_type)); \ - return; \ - } +#define CASE(upb_type, c_type) \ + case UPB_TYPE_##upb_type: { \ + PHP_PROTO_SEPARATE_ZVAL_IF_NOT_REF(cache); \ + ZVAL_LONG(CACHED_PTR_TO_ZVAL_PTR(cache), DEREF(memory, c_type)); \ + return; \ + } #endif CASE(UINT64, uint64_t) CASE(INT64, int64_t) @@ -227,32 +286,34 @@ CASE(INT64, int64_t) case UPB_TYPE_UINT32: { // Prepend bit-1 for negative numbers, so that uint32 value will be // consistent on both 32-bit and 64-bit architectures. - SEPARATE_ZVAL_IF_NOT_REF(cache); + PHP_PROTO_SEPARATE_ZVAL_IF_NOT_REF(cache); int value = DEREF(memory, int32_t); if (sizeof(int) == 8) { value |= (-((value >> 31) & 0x1) & 0xFFFFFFFF00000000); } - ZVAL_LONG(*cache, value); + ZVAL_LONG(CACHED_PTR_TO_ZVAL_PTR(cache), value); return; } case UPB_TYPE_STRING: case UPB_TYPE_BYTES: { - // For optional string/bytes fields, the cache is owned by the containing - // message and should have been updated during setting/decoding. However, - // for repeated string/bytes fields, the cache is provided by zend engine - // and has not been updated. - zval* value = DEREF(memory, zval*); - if (*cache != value) { - ZVAL_STRINGL(*cache, Z_STRVAL_P(value), Z_STRLEN_P(value), 1); + // For optional string/bytes/message fields, the cache is owned by the + // containing message and should have been updated during + // setting/decoding. However, oneof accessor call this function by + // providing the return value directly, which is not the same as the cache + // value. + zval* value = CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)memory); + if (CACHED_PTR_TO_ZVAL_PTR(cache) != value) { + PHP_PROTO_ZVAL_STRINGL(CACHED_PTR_TO_ZVAL_PTR(cache), Z_STRVAL_P(value), + Z_STRLEN_P(value), 1); } break; } case UPB_TYPE_MESSAGE: { // Same as above for string/bytes fields. - zval* value = DEREF(memory, zval*); - if (*cache != value) { - ZVAL_ZVAL(*cache, value, 1, 0); + zval* value = CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)memory); + if (CACHED_PTR_TO_ZVAL_PTR(cache) != value) { + ZVAL_ZVAL(CACHED_PTR_TO_ZVAL_PTR(cache), value, 1, 0); } return; } @@ -261,12 +322,46 @@ CASE(INT64, int64_t) } } -void native_slot_get_default(upb_fieldtype_t type, zval** cache TSRMLS_DC) { +void native_slot_get_by_array(upb_fieldtype_t type, const void* memory, + CACHED_VALUE* cache TSRMLS_DC) { switch (type) { -#define CASE(upb_type, php_type) \ - case UPB_TYPE_##upb_type: \ - SEPARATE_ZVAL_IF_NOT_REF(cache); \ - ZVAL_##php_type(*cache, 0); \ + case UPB_TYPE_STRING: + case UPB_TYPE_BYTES: { +#if PHP_MAJOR_VERSION < 7 + zval* value = CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)memory); + if (EXPECTED(CACHED_PTR_TO_ZVAL_PTR(cache) != value)) { + PHP_PROTO_ZVAL_STRINGL(CACHED_PTR_TO_ZVAL_PTR(cache), + Z_STRVAL_P(value), Z_STRLEN_P(value), 1); + } +#else + ZVAL_NEW_STR(cache, zend_string_dup(*(zend_string**)memory, 0)); +#endif + return; + } + case UPB_TYPE_MESSAGE: { +#if PHP_MAJOR_VERSION < 7 + zval* value = CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)memory); + if (EXPECTED(CACHED_PTR_TO_ZVAL_PTR(cache) != value)) { + ZVAL_ZVAL(CACHED_PTR_TO_ZVAL_PTR(cache), value, 1, 0); + } +#else + ++GC_REFCOUNT(*(zend_object**)memory); + ZVAL_OBJ(cache, *(zend_object**)memory); +#endif + 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) { +#define CASE(upb_type, php_type) \ + case UPB_TYPE_##upb_type: \ + PHP_PROTO_SEPARATE_ZVAL_IF_NOT_REF(cache); \ + ZVAL_##php_type(CACHED_PTR_TO_ZVAL_PTR(cache), 0); \ return; CASE(FLOAT, DOUBLE) @@ -279,19 +374,19 @@ void native_slot_get_default(upb_fieldtype_t type, zval** cache TSRMLS_DC) { #undef CASE #if SIZEOF_LONG == 4 -#define CASE(upb_type) \ - case UPB_TYPE_##upb_type: { \ - SEPARATE_ZVAL_IF_NOT_REF(cache); \ - ZVAL_STRING(*cache, "0", 1); \ - return; \ - } +#define CASE(upb_type) \ + case UPB_TYPE_##upb_type: { \ + PHP_PROTO_SEPARATE_ZVAL_IF_NOT_REF(cache); \ + PHP_PROTO_ZVAL_STRING(CACHED_PTR_TO_ZVAL_PTR(cache), "0", 1); \ + return; \ + } #else -#define CASE(upb_type) \ - case UPB_TYPE_##upb_type: { \ - SEPARATE_ZVAL_IF_NOT_REF(cache); \ - ZVAL_LONG(*cache, 0); \ - return; \ - } +#define CASE(upb_type) \ + case UPB_TYPE_##upb_type: { \ + PHP_PROTO_SEPARATE_ZVAL_IF_NOT_REF(cache); \ + ZVAL_LONG(CACHED_PTR_TO_ZVAL_PTR(cache), 0); \ + return; \ + } #endif CASE(UINT64) CASE(INT64) @@ -299,13 +394,13 @@ CASE(INT64) case UPB_TYPE_STRING: case UPB_TYPE_BYTES: { - SEPARATE_ZVAL_IF_NOT_REF(cache); - ZVAL_STRINGL(*cache, "", 0, 1); + PHP_PROTO_SEPARATE_ZVAL_IF_NOT_REF(cache); + PHP_PROTO_ZVAL_STRINGL(CACHED_PTR_TO_ZVAL_PTR(cache), "", 0, 1); break; } case UPB_TYPE_MESSAGE: { - SEPARATE_ZVAL_IF_NOT_REF(cache); - ZVAL_NULL(*cache); + PHP_PROTO_SEPARATE_ZVAL_IF_NOT_REF(cache); + ZVAL_NULL(CACHED_PTR_TO_ZVAL_PTR(cache)); return; } default: @@ -359,14 +454,15 @@ const upb_fielddef* map_entry_value(const upb_msgdef* msgdef) { return value_field; } -const zend_class_entry* field_type_class(const upb_fielddef* field TSRMLS_DC) { +const zend_class_entry* field_type_class( + const upb_fielddef* field PHP_PROTO_TSRMLS_DC) { if (upb_fielddef_type(field) == UPB_TYPE_MESSAGE) { - zval* desc_php = get_def_obj(upb_fielddef_subdef(field)); - Descriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC); + Descriptor* desc = UNBOX_HASHTABLE_VALUE( + Descriptor, get_def_obj(upb_fielddef_subdef(field))); return desc->klass; } else if (upb_fielddef_type(field) == UPB_TYPE_ENUM) { - zval* desc_php = get_def_obj(upb_fielddef_subdef(field)); - EnumDescriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC); + EnumDescriptor* desc = UNBOX_HASHTABLE_VALUE( + EnumDescriptor, get_def_obj(upb_fielddef_subdef(field))); return desc->klass; } return NULL; @@ -501,7 +597,7 @@ void free_layout(MessageLayout* layout) { } void layout_init(MessageLayout* layout, void* storage, - zval** properties_table TSRMLS_DC) { + CACHED_VALUE* properties_table PHP_PROTO_TSRMLS_DC) { int i; upb_msg_field_iter it; for (upb_msg_field_begin(&it, layout->msgdef), i = 0; !upb_msg_field_done(&it); @@ -510,20 +606,27 @@ void layout_init(MessageLayout* layout, void* storage, void* memory = slot_memory(layout, storage, field); uint32_t* oneof_case = slot_oneof_case(layout, storage, field); int cache_index = slot_property_cache(layout, storage, field); - zval** property_ptr = &properties_table[cache_index]; + CACHED_VALUE* property_ptr = &properties_table[cache_index]; if (upb_fielddef_containingoneof(field)) { memset(memory, 0, NATIVE_SLOT_MAX_SIZE); *oneof_case = ONEOF_CASE_NONE; } else if (is_map_field(field)) { zval_ptr_dtor(property_ptr); - map_field_create_with_field(map_field_type, field, property_ptr TSRMLS_CC); - DEREF(memory, zval**) = property_ptr; +#if PHP_MAJOR_VERSION < 7 + MAKE_STD_ZVAL(*property_ptr); +#endif + map_field_create_with_field(map_field_type, field, + property_ptr PHP_PROTO_TSRMLS_CC); + DEREF(memory, CACHED_VALUE*) = property_ptr; } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) { zval_ptr_dtor(property_ptr); +#if PHP_MAJOR_VERSION < 7 + MAKE_STD_ZVAL(*property_ptr); +#endif repeated_field_create_with_field(repeated_field_type, field, - property_ptr TSRMLS_CC); - DEREF(memory, zval**) = property_ptr; + property_ptr PHP_PROTO_TSRMLS_CC); + DEREF(memory, CACHED_VALUE*) = property_ptr; } else { native_slot_init(upb_fielddef_type(field), memory, property_ptr); } @@ -537,7 +640,7 @@ static void* value_memory(const upb_fielddef* field, void* memory) { case UPB_TYPE_STRING: case UPB_TYPE_BYTES: case UPB_TYPE_MESSAGE: - memory = DEREF(memory, zval**); + memory = DEREF(memory, CACHED_VALUE*); break; default: // No operation @@ -547,7 +650,7 @@ static void* value_memory(const upb_fielddef* field, void* memory) { } zval* layout_get(MessageLayout* layout, const void* storage, - const upb_fielddef* field, zval** cache TSRMLS_DC) { + const upb_fielddef* field, CACHED_VALUE* cache TSRMLS_DC) { void* memory = slot_memory(layout, storage, field); uint32_t* oneof_case = slot_oneof_case(layout, storage, field); @@ -558,13 +661,13 @@ zval* layout_get(MessageLayout* layout, const void* storage, native_slot_get(upb_fielddef_type(field), value_memory(field, memory), cache TSRMLS_CC); } - return *cache; + return CACHED_PTR_TO_ZVAL_PTR(cache); } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) { - return *cache; + return CACHED_PTR_TO_ZVAL_PTR(cache); } else { native_slot_get(upb_fielddef_type(field), value_memory(field, memory), cache TSRMLS_CC); - return *cache; + return CACHED_PTR_TO_ZVAL_PTR(cache); } } @@ -583,8 +686,7 @@ void layout_set(MessageLayout* layout, MessageHeader* header, switch (type) { case UPB_TYPE_MESSAGE: { const upb_msgdef* msg = upb_fielddef_msgsubdef(field); - zval* desc_php = get_def_obj(msg); - Descriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC); + Descriptor* desc = UNBOX_HASHTABLE_VALUE(Descriptor, get_def_obj(msg)); ce = desc->klass; // Intentionally fall through. } @@ -593,9 +695,9 @@ void layout_set(MessageLayout* layout, MessageHeader* header, int property_cache_index = header->descriptor->layout->fields[upb_fielddef_index(field)] .cache_index; - DEREF(memory, zval**) = + DEREF(memory, CACHED_VALUE*) = &(header->std.properties_table)[property_cache_index]; - memory = DEREF(memory, zval**); + memory = DEREF(memory, CACHED_VALUE*); break; } default: @@ -606,27 +708,130 @@ void layout_set(MessageLayout* layout, MessageHeader* header, *oneof_case = upb_fielddef_number(field); } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) { // Works for both repeated and map fields - memory = DEREF(memory, zval**); - if (EXPECTED(DEREF(memory, zval*) != val)) { - zval_ptr_dtor(memory); - DEREF(memory, zval*) = val; - Z_ADDREF_P(val); + memory = DEREF(memory, void**); + zval* property_ptr = CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)memory); + + if (EXPECTED(property_ptr != val)) { +#if PHP_MAJOR_VERSION < 7 + REPLACE_ZVAL_VALUE((zval**)memory, val, 1); +#else + php_proto_zval_ptr_dtor(property_ptr); + ZVAL_ZVAL(property_ptr, val, 1, 0); +#endif } } else { upb_fieldtype_t type = upb_fielddef_type(field); zend_class_entry *ce = NULL; if (type == UPB_TYPE_MESSAGE) { const upb_msgdef* msg = upb_fielddef_msgsubdef(field); - zval* desc_php = get_def_obj(msg); - Descriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC); + Descriptor* desc = UNBOX_HASHTABLE_VALUE(Descriptor, get_def_obj(msg)); ce = desc->klass; } native_slot_set(type, ce, value_memory(field, memory), val TSRMLS_CC); } } +static 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; + if (!native_slot_is_default(type, from_memory)) { + switch (type) { +#define CASE_TYPE(upb_type, c_type) \ + case UPB_TYPE_##upb_type: { \ + DEREF(to_memory, c_type) = DEREF(from_memory, c_type); \ + break; \ + } + CASE_TYPE(INT32, int32_t) + CASE_TYPE(UINT32, uint32_t) + CASE_TYPE(ENUM, int32_t) + CASE_TYPE(INT64, int64_t) + CASE_TYPE(UINT64, uint64_t) + CASE_TYPE(FLOAT, float) + CASE_TYPE(DOUBLE, double) + CASE_TYPE(BOOL, int8_t) + +#undef CASE_TYPE + case UPB_TYPE_STRING: + case UPB_TYPE_BYTES: + native_slot_set(type, NULL, value_memory(field, to_memory), + CACHED_PTR_TO_ZVAL_PTR(DEREF( + from_memory, CACHED_VALUE*)) PHP_PROTO_TSRMLS_CC); + break; + case UPB_TYPE_MESSAGE: { + const upb_msgdef* msg = upb_fielddef_msgsubdef(field); + Descriptor* desc = UNBOX_HASHTABLE_VALUE(Descriptor, get_def_obj(msg)); + ce = desc->klass; + if (native_slot_is_default(type, to_memory)) { +#if PHP_MAJOR_VERSION < 7 + SEPARATE_ZVAL_IF_NOT_REF((zval**)value_memory(field, to_memory)); +#endif + CREATE_OBJ_ON_ALLOCATED_ZVAL_PTR( + CACHED_PTR_TO_ZVAL_PTR(DEREF(to_memory, CACHED_VALUE*)), ce); + MessageHeader* submsg = + UNBOX(MessageHeader, + CACHED_PTR_TO_ZVAL_PTR(DEREF(to_memory, CACHED_VALUE*))); + custom_data_init(ce, submsg PHP_PROTO_TSRMLS_CC); + } + + MessageHeader* sub_from = + UNBOX(MessageHeader, + CACHED_PTR_TO_ZVAL_PTR(DEREF(from_memory, CACHED_VALUE*))); + MessageHeader* sub_to = + UNBOX(MessageHeader, + CACHED_PTR_TO_ZVAL_PTR(DEREF(to_memory, CACHED_VALUE*))); + + layout_merge(desc->layout, sub_from, sub_to PHP_PROTO_TSRMLS_CC); + break; + } + } + } +} + +static 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) { + case UPB_TYPE_STRING: + case UPB_TYPE_BYTES: { +#if PHP_MAJOR_VERSION < 7 + MAKE_STD_ZVAL(DEREF(to_memory, zval*)); + PHP_PROTO_ZVAL_STRINGL(DEREF(to_memory, zval*), + Z_STRVAL_P(*(zval**)from_memory), + Z_STRLEN_P(*(zval**)from_memory), 1); +#else + DEREF(to_memory, zend_string*) = + zend_string_dup(*(zend_string**)from_memory, 0); +#endif + break; + } + case UPB_TYPE_MESSAGE: { + const upb_msgdef* msg = upb_fielddef_msgsubdef(field); + Descriptor* desc = UNBOX_HASHTABLE_VALUE(Descriptor, get_def_obj(msg)); + zend_class_entry* ce = desc->klass; +#if PHP_MAJOR_VERSION < 7 + MAKE_STD_ZVAL(DEREF(to_memory, zval*)); + CREATE_OBJ_ON_ALLOCATED_ZVAL_PTR(DEREF(to_memory, zval*), ce); +#else + DEREF(to_memory, zend_object*) = ce->create_object(ce TSRMLS_CC); +#endif + MessageHeader* sub_from = UNBOX_HASHTABLE_VALUE( + MessageHeader, DEREF(from_memory, PHP_PROTO_HASHTABLE_VALUE)); + MessageHeader* sub_to = UNBOX_HASHTABLE_VALUE( + MessageHeader, DEREF(to_memory, PHP_PROTO_HASHTABLE_VALUE)); + custom_data_init(ce, sub_to PHP_PROTO_TSRMLS_CC); + + layout_merge(desc->layout, sub_from, sub_to PHP_PROTO_TSRMLS_CC); + break; + } + default: + native_slot_merge(field, from_memory, to_memory PHP_PROTO_TSRMLS_CC); + break; + } +} + void layout_merge(MessageLayout* layout, MessageHeader* from, - MessageHeader* to TSRMLS_DC) { + MessageHeader* to PHP_PROTO_TSRMLS_DC) { int i, j; upb_msg_field_iter it; @@ -639,11 +844,10 @@ void layout_merge(MessageLayout* layout, MessageHeader* from, if (upb_fielddef_containingoneof(field)) { uint32_t oneof_case_offset = - layout->fields[upb_fielddef_index(field)].case_offset + - sizeof(MessageHeader); + layout->fields[upb_fielddef_index(field)].case_offset; // For a oneof, check that this field is actually present -- skip all the // below if not. - if (DEREF(((uint8_t*)from + oneof_case_offset), uint32_t) != + if (DEREF((message_data(from) + oneof_case_offset), uint32_t) != upb_fielddef_number(field)) { continue; } @@ -658,7 +862,7 @@ void layout_merge(MessageLayout* layout, MessageHeader* from, case UPB_TYPE_BYTES: { int property_cache_index = layout->fields[upb_fielddef_index(field)].cache_index; - DEREF(to_memory, zval**) = + DEREF(to_memory, CACHED_VALUE*) = &(to->std.properties_table)[property_cache_index]; break; } @@ -676,141 +880,57 @@ void layout_merge(MessageLayout* layout, MessageHeader* from, int size, key_length, value_length; MapIter map_it; - zval* to_map_php = *DEREF(to_memory, zval**); - zval* from_map_php = *DEREF(from_memory, zval**); - Map* to_map = zend_object_store_get_object(to_map_php TSRMLS_CC); - Map* from_map = zend_object_store_get_object(from_map_php TSRMLS_CC); + zval* to_map_php = + CACHED_PTR_TO_ZVAL_PTR(DEREF(to_memory, CACHED_VALUE*)); + zval* from_map_php = + CACHED_PTR_TO_ZVAL_PTR(DEREF(from_memory, CACHED_VALUE*)); + Map* to_map = UNBOX(Map, to_map_php); + Map* from_map = UNBOX(Map, from_map_php); size = upb_strtable_count(&from_map->table); if (size == 0) continue; + const upb_msgdef *mapentry_def = upb_fielddef_msgsubdef(field); + const upb_fielddef *value_field = upb_msgdef_itof(mapentry_def, 2); + for (map_begin(from_map_php, &map_it TSRMLS_CC); !map_done(&map_it); map_next(&map_it)) { const char* key = map_iter_key(&map_it, &key_length); - upb_value value = map_iter_value(&map_it, &value_length); - void* mem = upb_value_memory(&value); - switch (to_map->value_type) { - case UPB_TYPE_MESSAGE: { - zval* new_message; - message_create_with_type(to_map->msg_ce, &new_message TSRMLS_CC); - Z_ADDREF_P(new_message); - - zval* subdesc_php = get_ce_obj(to_map->msg_ce); - Descriptor* subdesc = - zend_object_store_get_object(subdesc_php TSRMLS_CC); - MessageHeader* sub_from = - (MessageHeader*)zend_object_store_get_object(DEREF(mem, zval*) - TSRMLS_CC); - MessageHeader* sub_to = - (MessageHeader*)zend_object_store_get_object( - new_message TSRMLS_CC); - layout_merge(subdesc->layout, sub_from, sub_to TSRMLS_CC); - DEREF(mem, zval*) = new_message; - break; - } - case UPB_TYPE_BYTES: - case UPB_TYPE_STRING: - Z_ADDREF_PP((zval**)mem); - break; - default: - break; - } - map_index_set(to_map, key, key_length, value); + upb_value from_value = map_iter_value(&map_it, &value_length); + upb_value to_value; + void* from_mem = upb_value_memory(&from_value); + void* to_mem = upb_value_memory(&to_value); + memset(to_mem, 0, native_slot_size(to_map->value_type)); + + native_slot_merge_by_array(value_field, from_mem, + to_mem PHP_PROTO_TSRMLS_CC); + + map_index_set(to_map, key, key_length, to_value); } } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) { - zval* to_array_php = *DEREF(to_memory, zval**); - zval* from_array_php = *DEREF(from_memory, zval**); - RepeatedField* to_array = - zend_object_store_get_object(to_array_php TSRMLS_CC); - RepeatedField* from_array = - zend_object_store_get_object(from_array_php TSRMLS_CC); - - int size = zend_hash_num_elements(HASH_OF(from_array->array)); + zval* to_array_php = CACHED_PTR_TO_ZVAL_PTR(DEREF(to_memory, CACHED_VALUE*)); + zval* from_array_php = CACHED_PTR_TO_ZVAL_PTR(DEREF(from_memory, CACHED_VALUE*)); + RepeatedField* to_array = UNBOX(RepeatedField, to_array_php); + RepeatedField* from_array = UNBOX(RepeatedField, from_array_php); + + int size = zend_hash_num_elements(PHP_PROTO_HASH_OF(from_array->array)); if (size > 0) { for (j = 0; j < size; j++) { - void* memory = NULL; - zend_hash_index_find(HASH_OF(from_array->array), j, (void**)&memory); - switch (to_array->type) { - case UPB_TYPE_STRING: - case UPB_TYPE_BYTES: { - zval* str; - MAKE_STD_ZVAL(str); - ZVAL_STRINGL(str, Z_STRVAL_PP((zval**)memory), - Z_STRLEN_PP((zval**)memory), 1); - memory = &str; - break; - } - case UPB_TYPE_MESSAGE: { - zval* new_message; - message_create_with_type(from_array->msg_ce, &new_message TSRMLS_CC); - Z_ADDREF_P(new_message); - - zval* subdesc_php = get_ce_obj(from_array->msg_ce); - Descriptor* subdesc = - zend_object_store_get_object(subdesc_php TSRMLS_CC); - MessageHeader* sub_from = - (MessageHeader*)zend_object_store_get_object( - DEREF(memory, zval*) TSRMLS_CC); - MessageHeader* sub_to = - (MessageHeader*)zend_object_store_get_object( - new_message TSRMLS_CC); - layout_merge(subdesc->layout, sub_from, sub_to TSRMLS_CC); - - memory = &new_message; - } - default: - break; - } - repeated_field_push_native(to_array, memory TSRMLS_CC); + void* from_memory = NULL; + void* to_memory = + ALLOC_N(char, native_slot_size(upb_fielddef_type(field))); + memset(to_memory, 0, native_slot_size(upb_fielddef_type(field))); + php_proto_zend_hash_index_find(PHP_PROTO_HASH_OF(from_array->array), + j, (void**)&from_memory); + native_slot_merge_by_array(field, from_memory, + to_memory PHP_PROTO_TSRMLS_CC); + repeated_field_push_native(to_array, to_memory); + FREE(to_memory); } } } else { - upb_fieldtype_t type = upb_fielddef_type(field); - zend_class_entry *ce = NULL; - if (!native_slot_is_default(type, from_memory)) { - switch (type) { -#define CASE_TYPE(upb_type, c_type) \ - case UPB_TYPE_##upb_type: { \ - DEREF(to_memory, c_type) = DEREF(from_memory, c_type); \ - break; \ - } - CASE_TYPE(INT32, int32_t) - CASE_TYPE(UINT32, uint32_t) - CASE_TYPE(ENUM, int32_t) - CASE_TYPE(INT64, int64_t) - CASE_TYPE(UINT64, uint64_t) - CASE_TYPE(FLOAT, float) - CASE_TYPE(DOUBLE, double) - CASE_TYPE(BOOL, int8_t) - -#undef CASE_TYPE - case UPB_TYPE_STRING: - case UPB_TYPE_BYTES: - native_slot_set(type, NULL, value_memory(field, to_memory), - *DEREF(from_memory, zval**) TSRMLS_CC); - break; - case UPB_TYPE_MESSAGE: { - const upb_msgdef* msg = upb_fielddef_msgsubdef(field); - zval* desc_php = get_def_obj(msg); - Descriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC); - ce = desc->klass; - if (native_slot_is_default(type, to_memory)) { - zval* new_message = NULL; - message_create_with_type(ce, &new_message TSRMLS_CC); - native_slot_set(type, ce, value_memory(field, to_memory), - new_message TSRMLS_CC); - } - MessageHeader* sub_from = - (MessageHeader*)zend_object_store_get_object( - *DEREF(from_memory, zval**) TSRMLS_CC); - MessageHeader* sub_to = - (MessageHeader*)zend_object_store_get_object( - *DEREF(to_memory, zval**) TSRMLS_CC); - layout_merge(desc->layout, sub_from, sub_to TSRMLS_CC); - } - } - } + native_slot_merge(field, from_memory, to_memory PHP_PROTO_TSRMLS_CC); } } } diff --git a/third_party/protobuf/3.2.0/php/ext/google/protobuf/type_check.c b/third_party/protobuf/3.2.0/php/ext/google/protobuf/type_check.c index fe9b18f0e3..fada8d6a79 100644 --- a/third_party/protobuf/3.2.0/php/ext/google/protobuf/type_check.c +++ b/third_party/protobuf/3.2.0/php/ext/google/protobuf/type_check.c @@ -325,9 +325,18 @@ CONVERT_TO_FLOAT(double); bool protobuf_convert_to_bool(zval* from, int8_t* to) { switch (Z_TYPE_P(from)) { +#if PHP_MAJOR_VERSION < 7 case IS_BOOL: *to = (int8_t)Z_BVAL_P(from); break; +#else + case IS_TRUE: + *to = 1; + break; + case IS_FALSE: + *to = 0; + break; +#endif case IS_LONG: *to = (int8_t)(Z_LVAL_P(from) != 0); break; @@ -357,12 +366,16 @@ bool protobuf_convert_to_string(zval* from) { case IS_STRING: { return true; } +#if PHP_MAJOR_VERSION < 7 case IS_BOOL: +#else + case IS_TRUE: + case IS_FALSE: +#endif case IS_LONG: case IS_DOUBLE: { - int use_copy; zval tmp; - zend_make_printable_zval(from, &tmp, &use_copy); + php_proto_zend_make_printable_zval(from, &tmp); ZVAL_COPY_VALUE(from, &tmp); return true; } @@ -417,34 +430,45 @@ PHP_METHOD(Util, checkMessage) { PHP_METHOD(Util, checkRepeatedField) { zval* val; - long type; + PHP_PROTO_LONG type; const zend_class_entry* klass = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl|C", &val, &type, &klass) == FAILURE) { return; } +#if PHP_MAJOR_VERSION >= 7 + if (Z_ISREF_P(val)) { + ZVAL_DEREF(val); + } +#endif + if (Z_TYPE_P(val) == IS_ARRAY) { - HashTable* table = Z_ARRVAL_P(val); + HashTable* table = HASH_OF(val); HashPosition pointer; void* memory; + +#if PHP_MAJOR_VERSION < 7 zval* repeated_field; + MAKE_STD_ZVAL(repeated_field); +#else + zval repeated_field; +#endif repeated_field_create_with_type(repeated_field_type, to_fieldtype(type), klass, &repeated_field TSRMLS_CC); - RepeatedField* intern = - (RepeatedField*)zend_object_store_get_object(repeated_field TSRMLS_CC); for (zend_hash_internal_pointer_reset_ex(table, &pointer); - zend_hash_get_current_data_ex(table, (void**)&memory, &pointer) == - SUCCESS; + php_proto_zend_hash_get_current_data_ex(table, (void**)&memory, + &pointer) == SUCCESS; zend_hash_move_forward_ex(table, &pointer)) { - repeated_field_handlers->write_dimension(repeated_field, NULL, - *(zval**)memory TSRMLS_CC); + repeated_field_handlers->write_dimension( + CACHED_TO_ZVAL_PTR(repeated_field), NULL, + CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)memory) TSRMLS_CC); } - Z_DELREF_P(repeated_field); - RETURN_ZVAL(repeated_field, 1, 0); + Z_DELREF_P(CACHED_TO_ZVAL_PTR(repeated_field)); + RETURN_ZVAL(CACHED_TO_ZVAL_PTR(repeated_field), 1, 0); } else if (Z_TYPE_P(val) == IS_OBJECT) { if (!instanceof_function(Z_OBJCE_P(val), repeated_field_type TSRMLS_CC)) { @@ -452,8 +476,7 @@ PHP_METHOD(Util, checkRepeatedField) { repeated_field_type->name); return; } - RepeatedField* intern = - (RepeatedField*)zend_object_store_get_object(val TSRMLS_CC); + RepeatedField* intern = UNBOX(RepeatedField, val); if (to_fieldtype(type) != intern->type) { zend_error(E_USER_ERROR, "Incorrect repeated field type."); return; @@ -474,43 +497,55 @@ PHP_METHOD(Util, checkRepeatedField) { PHP_METHOD(Util, checkMapField) { zval* val; - long key_type, value_type; + PHP_PROTO_LONG key_type, value_type; const zend_class_entry* klass = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zll|C", &val, &key_type, &value_type, &klass) == FAILURE) { return; } +#if PHP_MAJOR_VERSION >= 7 + if (Z_ISREF_P(val)) { + ZVAL_DEREF(val); + } +#endif + if (Z_TYPE_P(val) == IS_ARRAY) { HashTable* table = Z_ARRVAL_P(val); HashPosition pointer; - zval key, *map_field; + zval key; void* value; +#if PHP_MAJOR_VERSION < 7 + zval* map_field; + MAKE_STD_ZVAL(map_field); +#else + zval map_field; +#endif + map_field_create_with_type(map_field_type, to_fieldtype(key_type), to_fieldtype(value_type), klass, &map_field TSRMLS_CC); - Map* intern = - (Map*)zend_object_store_get_object(map_field TSRMLS_CC); for (zend_hash_internal_pointer_reset_ex(table, &pointer); - zend_hash_get_current_data_ex(table, (void**)&value, &pointer) == - SUCCESS; + php_proto_zend_hash_get_current_data_ex(table, (void**)&value, + &pointer) == SUCCESS; zend_hash_move_forward_ex(table, &pointer)) { zend_hash_get_current_key_zval_ex(table, &key, &pointer); - map_field_handlers->write_dimension(map_field, &key, - *(zval**)value TSRMLS_CC); + map_field_handlers->write_dimension( + CACHED_TO_ZVAL_PTR(map_field), &key, + CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)value) TSRMLS_CC); } - Z_DELREF_P(map_field); - RETURN_ZVAL(map_field, 1, 0); + Z_DELREF_P(CACHED_TO_ZVAL_PTR(map_field)); + RETURN_ZVAL(CACHED_TO_ZVAL_PTR(map_field), 1, 0); } else if (Z_TYPE_P(val) == IS_OBJECT) { if (!instanceof_function(Z_OBJCE_P(val), map_field_type TSRMLS_CC)) { zend_error(E_USER_ERROR, "Given value is not an instance of %s.", map_field_type->name); return; } - Map* intern = (Map*)zend_object_store_get_object(val TSRMLS_CC); + Map* intern = UNBOX(Map, val); if (to_fieldtype(key_type) != intern->key_type) { zend_error(E_USER_ERROR, "Incorrect map field key type."); return; diff --git a/third_party/protobuf/3.2.0/php/src/Google/Protobuf/Internal/DescriptorPool.php b/third_party/protobuf/3.2.0/php/src/Google/Protobuf/Internal/DescriptorPool.php index 1ef403cfb7..2c00dfb60b 100644 --- a/third_party/protobuf/3.2.0/php/src/Google/Protobuf/Internal/DescriptorPool.php +++ b/third_party/protobuf/3.2.0/php/src/Google/Protobuf/Internal/DescriptorPool.php @@ -95,6 +95,9 @@ class DescriptorPool foreach ($descriptor->getNestedType() as $nested_type) { $this->addDescriptor($nested_type); } + foreach ($descriptor->getEnumType() as $enum_type) { + $this->addEnumDescriptor($enum_type); + } } public function addEnumDescriptor($descriptor) diff --git a/third_party/protobuf/3.2.0/php/src/Google/Protobuf/Internal/GPBDecodeException.php b/third_party/protobuf/3.2.0/php/src/Google/Protobuf/Internal/GPBDecodeException.php new file mode 100644 index 0000000000..402d542f39 --- /dev/null +++ b/third_party/protobuf/3.2.0/php/src/Google/Protobuf/Internal/GPBDecodeException.php @@ -0,0 +1,47 @@ += 0 && $byte_limit <= PHP_INT_MAX - $current_position) { + if ($byte_limit >= 0 && + $byte_limit <= PHP_INT_MAX - $current_position && + $byte_limit <= $this->current_limit - $current_position) { $this->current_limit = $current_position + $byte_limit; + $this->recomputeBufferLimits(); } else { - // Negative or overflow. - $this->current_limit = PHP_INT_MAX; + throw new GPBDecodeException("Fail to push limit."); } - // We need to enforce all limits, not just the new one, so if the previous - // limit was before the new requested limit, we continue to enforce the - // previous limit. - $this->current_limit = min($this->current_limit, $old_limit); - - $this->recomputeBufferLimits(); return $old_limit; } @@ -370,7 +367,7 @@ class InputStream } public function incrementRecursionDepthAndPushLimit( - $byte_limit, &$old_limit, &$recursion_budget) + $byte_limit, &$old_limit, &$recursion_budget) { $old_limit = $this->pushLimit($byte_limit); $recursion_limit = --$this->recursion_limit; diff --git a/third_party/protobuf/3.2.0/php/src/Google/Protobuf/Internal/MapField.php b/third_party/protobuf/3.2.0/php/src/Google/Protobuf/Internal/MapField.php index 68c10c0824..55cc12ce85 100644 --- a/third_party/protobuf/3.2.0/php/src/Google/Protobuf/Internal/MapField.php +++ b/third_party/protobuf/3.2.0/php/src/Google/Protobuf/Internal/MapField.php @@ -155,7 +155,6 @@ function checkKey($key_type, &$key) GPBUtil::checkString($key, true); break; default: - var_dump($key_type); trigger_error( "Given type cannot be map key.", E_USER_ERROR); @@ -284,6 +283,9 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable GPBUtil::checkString($value, true); break; case GPBType::MESSAGE: + if (is_null($value)) { + trigger_error("Map element cannot be null.", E_USER_ERROR); + } GPBUtil::checkMessage($value, $this->klass); break; default: diff --git a/third_party/protobuf/3.2.0/php/src/Google/Protobuf/Internal/Message.php b/third_party/protobuf/3.2.0/php/src/Google/Protobuf/Internal/Message.php index 887c86ca6e..cd15e0f042 100644 --- a/third_party/protobuf/3.2.0/php/src/Google/Protobuf/Internal/Message.php +++ b/third_party/protobuf/3.2.0/php/src/Google/Protobuf/Internal/Message.php @@ -224,48 +224,57 @@ class Message switch ($field->getType()) { case GPBType::DOUBLE: if (!GPBWire::readDouble($input, $value)) { - return false; + throw new GPBDecodeException( + "Unexpected EOF inside double field."); } break; case GPBType::FLOAT: if (!GPBWire::readFloat($input, $value)) { - return false; + throw new GPBDecodeException( + "Unexpected EOF inside float field."); } break; case GPBType::INT64: if (!GPBWire::readInt64($input, $value)) { - return false; + throw new GPBDecodeException( + "Unexpected EOF inside int64 field."); } break; case GPBType::UINT64: if (!GPBWire::readUint64($input, $value)) { - return false; + throw new GPBDecodeException( + "Unexpected EOF inside uint64 field."); } break; case GPBType::INT32: if (!GPBWire::readInt32($input, $value)) { - return false; + throw new GPBDecodeException( + "Unexpected EOF inside int32 field."); } break; case GPBType::FIXED64: if (!GPBWire::readFixed64($input, $value)) { - return false; + throw new GPBDecodeException( + "Unexpected EOF inside fixed64 field."); } break; case GPBType::FIXED32: if (!GPBWire::readFixed32($input, $value)) { - return false; + throw new GPBDecodeException( + "Unexpected EOF inside fixed32 field."); } break; case GPBType::BOOL: if (!GPBWire::readBool($input, $value)) { - return false; + throw new GPBDecodeException( + "Unexpected EOF inside bool field."); } break; case GPBType::STRING: // TODO(teboring): Add utf-8 check. if (!GPBWire::readString($input, $value)) { - return false; + throw new GPBDecodeException( + "Unexpected EOF inside string field."); } break; case GPBType::GROUP: @@ -280,43 +289,51 @@ class Message $value = new $klass; } if (!GPBWire::readMessage($input, $value)) { - return false; + throw new GPBDecodeException( + "Unexpected EOF inside message."); } break; case GPBType::BYTES: if (!GPBWire::readString($input, $value)) { - return false; + throw new GPBDecodeException( + "Unexpected EOF inside bytes field."); } break; case GPBType::UINT32: if (!GPBWire::readUint32($input, $value)) { - return false; + throw new GPBDecodeException( + "Unexpected EOF inside uint32 field."); } break; case GPBType::ENUM: // TODO(teboring): Check unknown enum value. if (!GPBWire::readInt32($input, $value)) { - return false; + throw new GPBDecodeException( + "Unexpected EOF inside enum field."); } break; case GPBType::SFIXED32: if (!GPBWire::readSfixed32($input, $value)) { - return false; + throw new GPBDecodeException( + "Unexpected EOF inside sfixed32 field."); } break; case GPBType::SFIXED64: if (!GPBWire::readSfixed64($input, $value)) { - return false; + throw new GPBDecodeException( + "Unexpected EOF inside sfixed64 field."); } break; case GPBType::SINT32: if (!GPBWire::readSint32($input, $value)) { - return false; + throw new GPBDecodeException( + "Unexpected EOF inside sint32 field."); } break; case GPBType::SINT64: if (!GPBWire::readSint64($input, $value)) { - return false; + throw new GPBDecodeException( + "Unexpected EOF inside sint64 field."); } break; default: @@ -345,24 +362,21 @@ class Message } if ($value_format === GPBWire::NORMAL_FORMAT) { - if (!self::parseFieldFromStreamNoTag($input, $field, $value)) { - return false; - } + self::parseFieldFromStreamNoTag($input, $field, $value); } elseif ($value_format === GPBWire::PACKED_FORMAT) { $length = 0; if (!GPBWire::readInt32($input, $length)) { - return false; + throw new GPBDecodeException( + "Unexpected EOF inside packed length."); } $limit = $input->pushLimit($length); $getter = $field->getGetter(); while ($input->bytesUntilLimit() > 0) { - if (!self::parseFieldFromStreamNoTag($input, $field, $value)) { - return false; - } + self::parseFieldFromStreamNoTag($input, $field, $value); $this->$getter()[] = $value; } $input->popLimit($limit); - return true; + return; } else { return false; } @@ -377,8 +391,6 @@ class Message $setter = $field->getSetter(); $this->$setter($value); } - - return true; } /** @@ -567,7 +579,8 @@ class Message * specified message. * * @param string $data Binary protobuf data. - * @return bool Return true on success. + * @return null. + * @throws Exception Invalid data. */ public function mergeFromString($data) { @@ -595,9 +608,7 @@ class Message continue; } - if (!$this->parseFieldFromStream($tag, $input, $field)) { - return false; - } + $this->parseFieldFromStream($tag, $input, $field); } } diff --git a/third_party/protobuf/3.2.0/php/src/Google/Protobuf/Internal/RepeatedField.php b/third_party/protobuf/3.2.0/php/src/Google/Protobuf/Internal/RepeatedField.php index 0dc5d9d206..2ad4709a67 100644 --- a/third_party/protobuf/3.2.0/php/src/Google/Protobuf/Internal/RepeatedField.php +++ b/third_party/protobuf/3.2.0/php/src/Google/Protobuf/Internal/RepeatedField.php @@ -225,6 +225,10 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable GPBUtil::checkString($value, true); break; case GPBType::MESSAGE: + if (is_null($value)) { + trigger_error("RepeatedField element cannot be null.", + E_USER_ERROR); + } GPBUtil::checkMessage($value, $this->klass); break; default: diff --git a/third_party/protobuf/3.2.0/php/src/Google/Protobuf/descriptor.php b/third_party/protobuf/3.2.0/php/src/Google/Protobuf/descriptor.php index 2263af6ed1..fb69eda0dc 100644 --- a/third_party/protobuf/3.2.0/php/src/Google/Protobuf/descriptor.php +++ b/third_party/protobuf/3.2.0/php/src/Google/Protobuf/descriptor.php @@ -210,6 +210,12 @@ class Descriptor $nested_proto, $file_proto, $message_name_without_package)); } + // Handle nested enum. + foreach ($proto->getEnumType() as $enum_proto) { + $desc->addEnumType(EnumDescriptor::buildFromProto( + $enum_proto, $file_proto, $message_name_without_package)); + } + // Handle oneof fields. foreach ($proto->getOneofDecl() as $oneof_proto) { $desc->addOneofDecl( @@ -220,20 +226,36 @@ class Descriptor } } +function getClassNamePrefix( + $classname, + $file_proto) +{ + $option = $file_proto->getOptions(); + $prefix = is_null($option) ? "" : $option->getPhpClassPrefix(); + if ($prefix !== "") { + return $prefix; + } + + $reserved_words = array("Empty"); + foreach ($reserved_words as $reserved_word) { + if ($classname === $reserved_word) { + if ($file_proto->getPackage() === "google.protobuf") { + return "GPB"; + } else { + return "PB"; + } + } + } + + return ""; +} + function getClassNameWithoutPackage( $name, $file_proto) { - if ($name === "Empty" && $file_proto->getPackage() === "google.protobuf") { - return "GPBEmpty"; - } else { - $option = $file_proto->getOptions(); - $prefix = is_null($option) ? "" : $option->getPhpClassPrefix(); - // Nested message class names are seperated by '_', and package names - // are seperated by '\'. - return $prefix . implode('_', array_map('ucwords', - explode('.', $name))); - } + $classname = implode('_', array_map('ucwords', explode('.', $name))); + return getClassNamePrefix($classname, $file_proto) . $classname; } function getFullClassName( diff --git a/third_party/protobuf/3.2.0/php/tests/array_test.php b/third_party/protobuf/3.2.0/php/tests/array_test.php index a4cad7196c..b55408da52 100644 --- a/third_party/protobuf/3.2.0/php/tests/array_test.php +++ b/third_party/protobuf/3.2.0/php/tests/array_test.php @@ -751,23 +751,13 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase $arr []= $sub_m; $this->assertSame(1, $arr[0]->getA()); - $null = null; - $arr []= $null; - $this->assertNull($arr[1]); - - $this->assertEquals(2, count($arr)); - - for ($i = 0; $i < count($arr); $i++) { - $arr[$i] = $null; - $this->assertNull($arr[$i]); - } + $this->assertEquals(1, count($arr)); // Test set. + $sub_m = new TestMessage_Sub(); + $sub_m->setA(2); $arr [0]= $sub_m; - $this->assertSame(1, $arr[0]->getA()); - - $arr [1]= $null; - $this->assertNull($arr[1]); + $this->assertSame(2, $arr[0]->getA()); } /** @@ -817,6 +807,27 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase $arr []= new TestMessage; } + /** + * @expectedException PHPUnit_Framework_Error + */ + public function testMessageAppendNullFail() + { + $arr = new RepeatedField(GPBType::MESSAGE, TestMessage_Sub::class); + $null = null; + $arr []= $null; + } + + /** + * @expectedException PHPUnit_Framework_Error + */ + public function testMessageSetNullFail() + { + $arr = new RepeatedField(GPBType::MESSAGE, TestMessage_Sub::class); + $arr []= new TestMessage_Sub(); + $null = null; + $arr[0] = $null; + } + ######################################################### # Test offset type ######################################################### diff --git a/third_party/protobuf/3.2.0/php/tests/encode_decode_test.php b/third_party/protobuf/3.2.0/php/tests/encode_decode_test.php index 94adf7931c..288df5696d 100644 --- a/third_party/protobuf/3.2.0/php/tests/encode_decode_test.php +++ b/third_party/protobuf/3.2.0/php/tests/encode_decode_test.php @@ -211,6 +211,204 @@ class EncodeDecodeTest extends TestBase $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')); + } + # TODO(teboring): Add test back when php implementation is ready for json # encode/decode. # public function testJsonEncode() diff --git a/third_party/protobuf/3.2.0/php/tests/gdb_test.sh b/third_party/protobuf/3.2.0/php/tests/gdb_test.sh index 45a2841fd6..0809bef3b9 100755 --- a/third_party/protobuf/3.2.0/php/tests/gdb_test.sh +++ b/third_party/protobuf/3.2.0/php/tests/gdb_test.sh @@ -3,10 +3,8 @@ # gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which # phpunit` --bootstrap autoload.php tmp_test.php # -gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which phpunit` --bootstrap autoload.php array_test.php +gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which phpunit` --bootstrap autoload.php well_known_test.php # -# # gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so -# memory_leak_test.php +# gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php # -# # USE_ZEND_ALLOC=0 valgrind --leak-check=yes php -# -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php +# USE_ZEND_ALLOC=0 valgrind --leak-check=yes php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php diff --git a/third_party/protobuf/3.2.0/php/tests/generated_class_test.php b/third_party/protobuf/3.2.0/php/tests/generated_class_test.php index 39e6c6c41c..21ee849078 100644 --- a/third_party/protobuf/3.2.0/php/tests/generated_class_test.php +++ b/third_party/protobuf/3.2.0/php/tests/generated_class_test.php @@ -1,7 +1,7 @@ assertEquals(TestEnum::ONE, $m->getOptionalEnum()); } + public function testNestedEnum() + { + $m = new TestMessage(); + $m->setOptionalNestedEnum(\Foo\TestMessage_NestedEnum::ZERO); + } + ######################################################### # Test float field. ######################################################### @@ -832,12 +838,20 @@ class GeneratedClassTest extends TestBase public function testMessageWithoutNamespace() { - $m = new NoNameSpaceMessage(); + $m = new TestMessage(); + $sub = new NoNameSpaceMessage(); + $m->setOptionalNoNamespaceMessage($sub); + $m->getRepeatedNoNamespaceMessage()[] = new NoNameSpaceMessage(); + + $n = new NoNamespaceMessage(); + $n->setB(NoNamespaceMessage_NestedEnum::ZERO); } public function testEnumWithoutNamespace() { - $m = new NoNameSpaceEnum(); + $m = new TestMessage(); + $m->setOptionalNoNamespaceEnum(NoNameSpaceEnum::VALUE_A); + $m->getRepeatedNoNamespaceEnum()[] = NoNameSpaceEnum::VALUE_A; } ######################################################### @@ -852,4 +866,15 @@ class GeneratedClassTest extends TestBase $m->setPrefixMessage($n); $this->assertSame(1, $m->getPrefixMessage()->getA()); } + + ######################################################### + # Test prefix for reserved words. + ######################################################### + + public function testPrefixForReservedWords() + { + $m = new \Foo\TestMessage_Empty(); + $m = new \Foo\PBEmpty(); + $m = new \PrefixEmpty(); + } } diff --git a/third_party/protobuf/3.2.0/php/tests/map_field_test.php b/third_party/protobuf/3.2.0/php/tests/map_field_test.php index d4ec44fc9a..2fda91352a 100644 --- a/third_party/protobuf/3.2.0/php/tests/map_field_test.php +++ b/third_party/protobuf/3.2.0/php/tests/map_field_test.php @@ -616,11 +616,7 @@ class MapFieldTest extends PHPUnit_Framework_TestCase { $arr[0] = $sub_m; $this->assertSame(1, $arr[0]->getA()); - $null = NULL; - $arr[1] = $null; - $this->assertNull($arr[1]); - - $this->assertEquals(2, count($arr)); + $this->assertEquals(1, count($arr)); } /** @@ -653,6 +649,17 @@ class MapFieldTest extends PHPUnit_Framework_TestCase { $arr[0] = new TestMessage_Sub(); } + /** + * @expectedException PHPUnit_Framework_Error + */ + public function testMessageSetNullFail() + { + $arr = + new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class); + $null = NULL; + $arr[0] = $null; + } + ######################################################### # Test memory leak ######################################################### diff --git a/third_party/protobuf/3.2.0/php/tests/memory_leak_test.php b/third_party/protobuf/3.2.0/php/tests/memory_leak_test.php index 5dd79519ae..361982b550 100644 --- a/third_party/protobuf/3.2.0/php/tests/memory_leak_test.php +++ b/third_party/protobuf/3.2.0/php/tests/memory_leak_test.php @@ -2,17 +2,25 @@ # phpunit has memory leak by itself. Thus, it cannot be used to test memory leak. +require_once('generated/NoNamespaceEnum.php'); +require_once('generated/NoNamespaceMessage.php'); +require_once('generated/NoNamespaceMessage_NestedEnum.php'); +require_once('generated/PrefixEmpty.php'); require_once('generated/PrefixTestPrefix.php'); require_once('generated/Bar/TestInclude.php'); +require_once('generated/Foo/PBEmpty.php'); require_once('generated/Foo/TestEnum.php'); require_once('generated/Foo/TestIncludePrefixMessage.php'); require_once('generated/Foo/TestMessage.php'); +require_once('generated/Foo/TestMessage_Empty.php'); +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/TestUnpackedMessage.php'); require_once('generated/GPBMetadata/Proto/Test.php'); require_once('generated/GPBMetadata/Proto/TestInclude.php'); +require_once('generated/GPBMetadata/Proto/TestNoNamespace.php'); require_once('generated/GPBMetadata/Proto/TestPrefix.php'); require_once('test_util.php'); @@ -83,7 +91,8 @@ $n = new TestMessage(); $n->mergeFromString($data); assert(1 === $n->getOneofMessage()->getA()); -$from = new TestMessage(); -$to = new TestMessage(); -TestUtil::setTestMessage($from); -$to->mergeFrom($from); +# $from = new TestMessage(); +# $to = new TestMessage(); +# TestUtil::setTestMessage($from); +# $to->mergeFrom($from); +# TestUtil::assertTestMessage($to); diff --git a/third_party/protobuf/3.2.0/php/tests/proto/test.proto b/third_party/protobuf/3.2.0/php/tests/proto/test.proto index 1a47a3f291..3922925451 100644 --- a/third_party/protobuf/3.2.0/php/tests/proto/test.proto +++ b/third_party/protobuf/3.2.0/php/tests/proto/test.proto @@ -1,6 +1,7 @@ syntax = "proto3"; import 'proto/test_include.proto'; +import 'proto/test_no_namespace.proto'; import 'proto/test_prefix.proto'; package foo; @@ -96,12 +97,34 @@ message TestMessage { // Reserved for non-existing field test. // int32 non_exist = 89; + + NoNamespaceMessage optional_no_namespace_message = 91; + NoNamespaceEnum optional_no_namespace_enum = 92; + repeated NoNamespaceMessage repeated_no_namespace_message = 93; + repeated NoNamespaceEnum repeated_no_namespace_enum = 94; + + enum NestedEnum { + ZERO = 0; + } + + NestedEnum optional_nested_enum = 101; + + // Test prefix for reserved words. + message Empty { + int32 a = 1; + } } enum TestEnum { ZERO = 0; ONE = 1; TWO = 2; + ECHO = 3; // Test reserved name. +} + +// Test prefix for reserved words. +message Empty { + int32 a = 1; } message TestPackedMessage { diff --git a/third_party/protobuf/3.2.0/php/tests/proto/test_import_descriptor_proto.proto b/third_party/protobuf/3.2.0/php/tests/proto/test_import_descriptor_proto.proto new file mode 100644 index 0000000000..2a19940dec --- /dev/null +++ b/third_party/protobuf/3.2.0/php/tests/proto/test_import_descriptor_proto.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; + +import "google/protobuf/descriptor.proto"; + +message TestImportDescriptorProto { + extend google.protobuf.MethodOptions { + int32 a = 72295727; + } +} + +extend google.protobuf.MethodOptions { + int32 a = 72295728; +} + diff --git a/third_party/protobuf/3.2.0/php/tests/proto/test_no_namespace.proto b/third_party/protobuf/3.2.0/php/tests/proto/test_no_namespace.proto index b8c4fdf2fc..58f13d47bc 100644 --- a/third_party/protobuf/3.2.0/php/tests/proto/test_no_namespace.proto +++ b/third_party/protobuf/3.2.0/php/tests/proto/test_no_namespace.proto @@ -1,10 +1,16 @@ syntax = "proto3"; -message NoNameSpaceMessage { +message NoNamespaceMessage { int32 a = 1; + + enum NestedEnum { + ZERO = 0; + } + NestedEnum b = 2; + repeated NestedEnum c = 3; } -enum NoNameSpaceEnum { +enum NoNamespaceEnum { VALUE_A = 0; VALUE_B = 1; } diff --git a/third_party/protobuf/3.2.0/php/tests/proto/test_prefix.proto b/third_party/protobuf/3.2.0/php/tests/proto/test_prefix.proto index 045821217c..9bfbad7f82 100644 --- a/third_party/protobuf/3.2.0/php/tests/proto/test_prefix.proto +++ b/third_party/protobuf/3.2.0/php/tests/proto/test_prefix.proto @@ -5,3 +5,8 @@ option php_class_prefix = "Prefix"; message TestPrefix { int32 a = 1; } + +// Test prefix for reserved words. +message Empty { + int32 a = 1; +} diff --git a/third_party/protobuf/3.2.0/php/tests/test_util.php b/third_party/protobuf/3.2.0/php/tests/test_util.php index 61f94aa108..9dbcbb62c9 100644 --- a/third_party/protobuf/3.2.0/php/tests/test_util.php +++ b/third_party/protobuf/3.2.0/php/tests/test_util.php @@ -51,8 +51,6 @@ class TestUtil public static function setTestMessage(TestMessage $m) { - $sub = new TestMessage_Sub(); - $m->setOptionalInt32(-42); $m->setOptionalInt64(-43); $m->setOptionalUint32(42); @@ -69,6 +67,7 @@ class TestUtil $m->setOptionalString('a'); $m->setOptionalBytes('b'); $m->setOptionalEnum(TestEnum::ONE); + $sub = new TestMessage_Sub(); $m->setOptionalMessage($sub); $m->getOptionalMessage()->SetA(33); diff --git a/third_party/protobuf/3.2.0/php/tests/well_known_test.php b/third_party/protobuf/3.2.0/php/tests/well_known_test.php index 40ff1c8f03..0c2aec13a9 100644 --- a/third_party/protobuf/3.2.0/php/tests/well_known_test.php +++ b/third_party/protobuf/3.2.0/php/tests/well_known_test.php @@ -4,8 +4,14 @@ use Google\Protobuf\GPBEmpty; class WellKnownTest extends PHPUnit_Framework_TestCase { - public function testNone() { - $msg = new GPBEmpty(); + public function testNone() + { + $msg = new GPBEmpty(); + } + + public function testImportDescriptorProto() + { + $msg = new TestImportDescriptorProto(); } } diff --git a/third_party/protobuf/3.2.0/protobuf-java-3.2.0.jar b/third_party/protobuf/3.2.0/protobuf-java-3.2.0.jar deleted file mode 100644 index b1f970176d..0000000000 Binary files a/third_party/protobuf/3.2.0/protobuf-java-3.2.0.jar and /dev/null differ diff --git a/third_party/protobuf/3.2.0/protobuf-java-util-3.2.0.jar b/third_party/protobuf/3.2.0/protobuf-java-util-3.2.0.jar deleted file mode 100644 index 2fb0a207ee..0000000000 Binary files a/third_party/protobuf/3.2.0/protobuf-java-util-3.2.0.jar and /dev/null differ diff --git a/third_party/protobuf/3.2.0/protobuf.bzl b/third_party/protobuf/3.2.0/protobuf.bzl index 73c396d556..9cb17f019c 100644 --- a/third_party/protobuf/3.2.0/protobuf.bzl +++ b/third_party/protobuf/3.2.0/protobuf.bzl @@ -108,6 +108,7 @@ def _proto_gen_impl(ctx): arguments=args + import_flags + [s.path for s in srcs], executable=ctx.executable.protoc, mnemonic="ProtoCompile", + use_default_shell_env=True, ) return struct( diff --git a/third_party/protobuf/3.2.0/protoc-artifacts/pom.xml b/third_party/protobuf/3.2.0/protoc-artifacts/pom.xml index 28a2511926..a06c99982a 100644 --- a/third_party/protobuf/3.2.0/protoc-artifacts/pom.xml +++ b/third_party/protobuf/3.2.0/protoc-artifacts/pom.xml @@ -10,7 +10,7 @@ com.google.protobuf protoc - 3.2.0 + 3.3.0 pom Protobuf Compiler diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/__init__.py b/third_party/protobuf/3.2.0/python/google/protobuf/__init__.py index 7fd9e5a458..0375d72d0d 100755 --- a/third_party/protobuf/3.2.0/python/google/protobuf/__init__.py +++ b/third_party/protobuf/3.2.0/python/google/protobuf/__init__.py @@ -30,7 +30,7 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '3.2.0' +__version__ = '3.3.0' if __name__ != '__main__': try: diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/descriptor_database.py b/third_party/protobuf/3.2.0/python/google/protobuf/descriptor_database.py index 1333f9966e..40bcdd720b 100644 --- a/third_party/protobuf/3.2.0/python/google/protobuf/descriptor_database.py +++ b/third_party/protobuf/3.2.0/python/google/protobuf/descriptor_database.py @@ -54,9 +54,9 @@ class DescriptorDatabase(object): Args: file_desc_proto: The FileDescriptorProto to add. Raises: - DescriptorDatabaseException: if an attempt is made to add a proto - with the same name but different definition than an exisiting - proto in the database. + DescriptorDatabaseConflictingDefinitionError: if an attempt is made to + add a proto with the same name but different definition than an + exisiting proto in the database. """ proto_name = file_desc_proto.name if proto_name not in self._file_desc_protos_by_file: @@ -65,7 +65,7 @@ class DescriptorDatabase(object): raise DescriptorDatabaseConflictingDefinitionError( '%s already added, but with different descriptor.' % proto_name) - # Add the top-level Message, Enum and Extension descriptors to the index. + # Add all the top-level descriptors to the index. package = file_desc_proto.package for message in file_desc_proto.message_type: self._file_desc_protos_by_symbol.update( @@ -76,6 +76,9 @@ class DescriptorDatabase(object): for extension in file_desc_proto.extension: self._file_desc_protos_by_symbol[ '.'.join((package, extension.name))] = file_desc_proto + for service in file_desc_proto.service: + self._file_desc_protos_by_symbol[ + '.'.join((package, service.name))] = file_desc_proto def FindFileByName(self, name): """Finds the file descriptor proto by file name. diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/descriptor_pool.py b/third_party/protobuf/3.2.0/python/google/protobuf/descriptor_pool.py index fc3a7f4404..29e9f1e3f9 100644 --- a/third_party/protobuf/3.2.0/python/google/protobuf/descriptor_pool.py +++ b/third_party/protobuf/3.2.0/python/google/protobuf/descriptor_pool.py @@ -124,8 +124,12 @@ class DescriptorPool(object): self._descriptor_db = descriptor_db self._descriptors = {} self._enum_descriptors = {} + self._service_descriptors = {} self._file_descriptors = {} self._toplevel_extensions = {} + # TODO(jieluo): Remove _file_desc_by_toplevel_extension when + # FieldDescriptor.file is added in code gen. + self._file_desc_by_toplevel_extension = {} # We store extensions in two two-level mappings: The first key is the # descriptor of the message being extended, the second key is the extension # full name or its tag number. @@ -169,12 +173,12 @@ class DescriptorPool(object): raise TypeError('Expected instance of descriptor.Descriptor.') self._descriptors[desc.full_name] = desc - self.AddFileDescriptor(desc.file) + self._AddFileDescriptor(desc.file) def AddEnumDescriptor(self, enum_desc): """Adds an EnumDescriptor to the pool. - This method also registers the FileDescriptor associated with the message. + This method also registers the FileDescriptor associated with the enum. Args: enum_desc: An EnumDescriptor. @@ -184,7 +188,19 @@ class DescriptorPool(object): raise TypeError('Expected instance of descriptor.EnumDescriptor.') self._enum_descriptors[enum_desc.full_name] = enum_desc - self.AddFileDescriptor(enum_desc.file) + self._AddFileDescriptor(enum_desc.file) + + def AddServiceDescriptor(self, service_desc): + """Adds a ServiceDescriptor to the pool. + + Args: + service_desc: A ServiceDescriptor. + """ + + if not isinstance(service_desc, descriptor.ServiceDescriptor): + raise TypeError('Expected instance of descriptor.ServiceDescriptor.') + + self._service_descriptors[service_desc.full_name] = service_desc def AddExtensionDescriptor(self, extension): """Adds a FieldDescriptor describing an extension to the pool. @@ -238,6 +254,23 @@ class DescriptorPool(object): file_desc: A FileDescriptor. """ + self._AddFileDescriptor(file_desc) + # TODO(jieluo): This is a temporary solution for FieldDescriptor.file. + # Remove it when FieldDescriptor.file is added in code gen. + for extension in file_desc.extensions_by_name.values(): + self._file_desc_by_toplevel_extension[ + extension.full_name] = file_desc + + def _AddFileDescriptor(self, file_desc): + """Adds a FileDescriptor to the pool, non-recursively. + + If the FileDescriptor contains messages or enums, the caller must explicitly + register them. + + Args: + file_desc: A FileDescriptor. + """ + if not isinstance(file_desc, descriptor.FileDescriptor): raise TypeError('Expected instance of descriptor.FileDescriptor.') self._file_descriptors[file_desc.name] = file_desc @@ -252,7 +285,7 @@ class DescriptorPool(object): A FileDescriptor for the named file. Raises: - KeyError: if the file can not be found in the pool. + KeyError: if the file cannot be found in the pool. """ try: @@ -281,7 +314,7 @@ class DescriptorPool(object): A FileDescriptor that contains the specified symbol. Raises: - KeyError: if the file can not be found in the pool. + KeyError: if the file cannot be found in the pool. """ symbol = _NormalizeFullyQualifiedName(symbol) @@ -296,15 +329,24 @@ class DescriptorPool(object): pass try: - file_proto = self._internal_db.FindFileContainingSymbol(symbol) - except KeyError as error: - if self._descriptor_db: - file_proto = self._descriptor_db.FindFileContainingSymbol(symbol) - else: - raise error - if not file_proto: + return self._FindFileContainingSymbolInDb(symbol) + except KeyError: + pass + + try: + return self._file_desc_by_toplevel_extension[symbol] + except KeyError: + pass + + # Try nested extensions inside a message. + message_name, _, extension_name = symbol.rpartition('.') + try: + message = self.FindMessageTypeByName(message_name) + assert message.extensions_by_name[extension_name] + return message.file + + except KeyError: raise KeyError('Cannot find a file containing %s' % symbol) - return self._ConvertFileProtoToFileDescriptor(file_proto) def FindMessageTypeByName(self, full_name): """Loads the named descriptor from the pool. @@ -314,11 +356,14 @@ class DescriptorPool(object): Returns: The descriptor for the named type. + + Raises: + KeyError: if the message cannot be found in the pool. """ full_name = _NormalizeFullyQualifiedName(full_name) if full_name not in self._descriptors: - self.FindFileContainingSymbol(full_name) + self._FindFileContainingSymbolInDb(full_name) return self._descriptors[full_name] def FindEnumTypeByName(self, full_name): @@ -329,11 +374,14 @@ class DescriptorPool(object): Returns: The enum descriptor for the named type. + + Raises: + KeyError: if the enum cannot be found in the pool. """ full_name = _NormalizeFullyQualifiedName(full_name) if full_name not in self._enum_descriptors: - self.FindFileContainingSymbol(full_name) + self._FindFileContainingSymbolInDb(full_name) return self._enum_descriptors[full_name] def FindFieldByName(self, full_name): @@ -344,6 +392,9 @@ class DescriptorPool(object): Returns: The field descriptor for the named field. + + Raises: + KeyError: if the field cannot be found in the pool. """ full_name = _NormalizeFullyQualifiedName(full_name) message_name, _, field_name = full_name.rpartition('.') @@ -358,6 +409,9 @@ class DescriptorPool(object): Returns: A FieldDescriptor, describing the named extension. + + Raises: + KeyError: if the extension cannot be found in the pool. """ full_name = _NormalizeFullyQualifiedName(full_name) try: @@ -374,7 +428,7 @@ class DescriptorPool(object): scope = self.FindMessageTypeByName(message_name) except KeyError: # Some extensions are defined at file scope. - scope = self.FindFileContainingSymbol(full_name) + scope = self._FindFileContainingSymbolInDb(full_name) return scope.extensions_by_name[extension_name] def FindExtensionByNumber(self, message_descriptor, number): @@ -390,7 +444,7 @@ class DescriptorPool(object): Returns: A FieldDescriptor describing the extension. - Raise: + Raises: KeyError: when no extension with the given number is known for the specified message. """ @@ -410,6 +464,46 @@ class DescriptorPool(object): """ return list(self._extensions_by_number[message_descriptor].values()) + def FindServiceByName(self, full_name): + """Loads the named service descriptor from the pool. + + Args: + full_name: The full name of the service descriptor to load. + + Returns: + The service descriptor for the named service. + + Raises: + KeyError: if the service cannot be found in the pool. + """ + full_name = _NormalizeFullyQualifiedName(full_name) + if full_name not in self._service_descriptors: + self._FindFileContainingSymbolInDb(full_name) + return self._service_descriptors[full_name] + + def _FindFileContainingSymbolInDb(self, symbol): + """Finds the file in descriptor DB containing the specified symbol. + + Args: + symbol: The name of the symbol to search for. + + Returns: + A FileDescriptor that contains the specified symbol. + + Raises: + KeyError: if the file cannot be found in the descriptor database. + """ + try: + file_proto = self._internal_db.FindFileContainingSymbol(symbol) + except KeyError as error: + if self._descriptor_db: + file_proto = self._descriptor_db.FindFileContainingSymbol(symbol) + else: + raise error + if not file_proto: + raise KeyError('Cannot find a file containing %s' % symbol) + return self._ConvertFileProtoToFileDescriptor(file_proto) + def _ConvertFileProtoToFileDescriptor(self, file_proto): """Creates a FileDescriptor from a proto or returns a cached copy. @@ -804,6 +898,7 @@ class DescriptorPool(object): methods=methods, options=_OptionsOrNone(service_proto), file=file_desc) + self._service_descriptors[service_name] = desc return desc def _MakeMethodDescriptor(self, method_proto, service_name, package, scope, diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/internal/containers.py b/third_party/protobuf/3.2.0/python/google/protobuf/internal/containers.py index de13018eef..68be9e54a8 100755 --- a/third_party/protobuf/3.2.0/python/google/protobuf/internal/containers.py +++ b/third_party/protobuf/3.2.0/python/google/protobuf/internal/containers.py @@ -275,7 +275,7 @@ class RepeatedScalarFieldContainer(BaseContainer): new_values = [self._type_checker.CheckValue(elem) for elem in elem_seq_iter] if new_values: self._values.extend(new_values) - self._message_listener.Modified() + self._message_listener.Modified() def MergeFrom(self, other): """Appends the contents of another repeated field of the same type to this diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/internal/descriptor_pool_test.py b/third_party/protobuf/3.2.0/python/google/protobuf/internal/descriptor_pool_test.py index 1e710dcf82..c1733a48b4 100644 --- a/third_party/protobuf/3.2.0/python/google/protobuf/internal/descriptor_pool_test.py +++ b/third_party/protobuf/3.2.0/python/google/protobuf/internal/descriptor_pool_test.py @@ -63,6 +63,9 @@ from google.protobuf import symbol_database class DescriptorPoolTest(unittest.TestCase): def setUp(self): + # TODO(jieluo): Should make the pool which is created by + # serialized_pb same with generated pool. + # TODO(jieluo): More test coverage for the generated pool. self.pool = descriptor_pool.DescriptorPool() self.factory_test1_fd = descriptor_pb2.FileDescriptorProto.FromString( factory_test1_pb2.DESCRIPTOR.serialized_pb) @@ -71,6 +74,13 @@ class DescriptorPoolTest(unittest.TestCase): self.pool.Add(self.factory_test1_fd) self.pool.Add(self.factory_test2_fd) + self.pool.Add(descriptor_pb2.FileDescriptorProto.FromString( + unittest_import_public_pb2.DESCRIPTOR.serialized_pb)) + self.pool.Add(descriptor_pb2.FileDescriptorProto.FromString( + unittest_import_pb2.DESCRIPTOR.serialized_pb)) + self.pool.Add(descriptor_pb2.FileDescriptorProto.FromString( + unittest_pb2.DESCRIPTOR.serialized_pb)) + def testFindFileByName(self): name1 = 'google/protobuf/internal/factory_test1.proto' file_desc1 = self.pool.FindFileByName(name1) @@ -107,6 +117,26 @@ class DescriptorPoolTest(unittest.TestCase): self.assertEqual('google.protobuf.python.internal', file_desc2.package) self.assertIn('Factory2Message', file_desc2.message_types_by_name) + # Tests top level extension. + file_desc3 = self.pool.FindFileContainingSymbol( + 'google.protobuf.python.internal.another_field') + self.assertIsInstance(file_desc3, descriptor.FileDescriptor) + self.assertEqual('google/protobuf/internal/factory_test2.proto', + file_desc3.name) + + # Tests nested extension inside a message. + file_desc4 = self.pool.FindFileContainingSymbol( + 'google.protobuf.python.internal.Factory2Message.one_more_field') + self.assertIsInstance(file_desc4, descriptor.FileDescriptor) + self.assertEqual('google/protobuf/internal/factory_test2.proto', + file_desc4.name) + + # Tests the generated pool. + assert descriptor_pool.Default().FindFileContainingSymbol( + 'google.protobuf.python.internal.Factory2Message.one_more_field') + assert descriptor_pool.Default().FindFileContainingSymbol( + 'google.protobuf.python.internal.another_field') + def testFindFileContainingSymbolFailure(self): with self.assertRaises(KeyError): self.pool.FindFileContainingSymbol('Does not exist') @@ -311,6 +341,10 @@ class DescriptorPoolTest(unittest.TestCase): self.pool.FindExtensionByName( 'google.protobuf.python.internal.Factory1Message.list_value') + def testFindService(self): + service = self.pool.FindServiceByName('protobuf_unittest.TestService') + self.assertEqual(service.full_name, 'protobuf_unittest.TestService') + def testUserDefinedDB(self): db = descriptor_database.DescriptorDatabase() self.pool = descriptor_pool.DescriptorPool(db) @@ -643,6 +677,17 @@ class AddDescriptorTest(unittest.TestCase): self._TestEnum('') self._TestEnum('.') + @unittest.skipIf(api_implementation.Type() == 'cpp', + 'With the cpp implementation, Add() must be called first') + def testService(self): + pool = descriptor_pool.DescriptorPool() + with self.assertRaises(KeyError): + pool.FindServiceByName('protobuf_unittest.TestService') + pool.AddServiceDescriptor(unittest_pb2._TESTSERVICE) + self.assertEqual( + 'protobuf_unittest.TestService', + pool.FindServiceByName('protobuf_unittest.TestService').full_name) + @unittest.skipIf(api_implementation.Type() == 'cpp', 'With the cpp implementation, Add() must be called first') def testFile(self): diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/internal/encoder.py b/third_party/protobuf/3.2.0/python/google/protobuf/internal/encoder.py index 48ef2df31c..80e59cab0a 100755 --- a/third_party/protobuf/3.2.0/python/google/protobuf/internal/encoder.py +++ b/third_party/protobuf/3.2.0/python/google/protobuf/internal/encoder.py @@ -340,7 +340,7 @@ def MessageSetItemSizer(field_number): # Map is special: it needs custom logic to compute its size properly. -def MapSizer(field_descriptor): +def MapSizer(field_descriptor, is_message_map): """Returns a sizer for a map field.""" # Can't look at field_descriptor.message_type._concrete_class because it may @@ -355,9 +355,12 @@ def MapSizer(field_descriptor): # It's wasteful to create the messages and throw them away one second # later since we'll do the same for the actual encode. But there's not an # obvious way to avoid this within the current design without tons of code - # duplication. + # duplication. For message map, value.ByteSize() should be called to + # update the status. entry_msg = message_type._concrete_class(key=key, value=value) total += message_sizer(entry_msg) + if is_message_map: + value.ByteSize() return total return FieldSize diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/internal/message_test.py b/third_party/protobuf/3.2.0/python/google/protobuf/internal/message_test.py index 9986c0d99b..e8b794f0e4 100755 --- a/third_party/protobuf/3.2.0/python/google/protobuf/internal/message_test.py +++ b/third_party/protobuf/3.2.0/python/google/protobuf/internal/message_test.py @@ -564,6 +564,11 @@ class MessageTest(BaseTestCase): self.assertIsInstance(m.repeated_nested_message, collections.MutableSequence) + def testRepeatedFieldInsideNestedMessage(self, message_module): + m = message_module.NestedTestAllTypes() + m.payload.repeated_int32.extend([]) + self.assertTrue(m.HasField('payload')) + def ensureNestedMessageExists(self, msg, attribute): """Make sure that a nested message object exists. @@ -1432,6 +1437,18 @@ class Proto3Test(BaseTestCase): self.assertIn(-456, msg2.map_int32_foreign_message) self.assertEqual(2, len(msg2.map_int32_foreign_message)) + def testMapByteSize(self): + msg = map_unittest_pb2.TestMap() + msg.map_int32_int32[1] = 1 + size = msg.ByteSize() + msg.map_int32_int32[1] = 128 + self.assertEqual(msg.ByteSize(), size + 1) + + msg.map_int32_foreign_message[19].c = 1 + size = msg.ByteSize() + msg.map_int32_foreign_message[19].c = 128 + self.assertEqual(msg.ByteSize(), size + 1) + def testMergeFrom(self): msg = map_unittest_pb2.TestMap() msg.map_int32_int32[12] = 34 @@ -1456,7 +1473,15 @@ class Proto3Test(BaseTestCase): self.assertEqual(5, msg2.map_int32_foreign_message[111].c) self.assertEqual(10, msg2.map_int32_foreign_message[222].c) self.assertFalse(msg2.map_int32_foreign_message[222].HasField('d')) - self.assertEqual(15, old_map_value.c) + if api_implementation.Type() != 'cpp': + # During the call to MergeFrom(), the C++ implementation will have + # deallocated the underlying message, but this is very difficult to detect + # properly. The line below is likely to cause a segmentation fault. + # With the Python implementation, old_map_value is just 'detached' from + # the main message. Using it will not crash of course, but since it still + # have a reference to the parent message I'm sure we can find interesting + # ways to cause inconsistencies. + self.assertEqual(15, old_map_value.c) # Verify that there is only one entry per key, even though the MergeFrom # may have internally created multiple entries for a single key in the diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/internal/python_message.py b/third_party/protobuf/3.2.0/python/google/protobuf/internal/python_message.py index 4b7010390a..cb97cb2847 100755 --- a/third_party/protobuf/3.2.0/python/google/protobuf/internal/python_message.py +++ b/third_party/protobuf/3.2.0/python/google/protobuf/internal/python_message.py @@ -288,7 +288,8 @@ def _AttachFieldHelpers(cls, field_descriptor): if is_map_entry: field_encoder = encoder.MapEncoder(field_descriptor) - sizer = encoder.MapSizer(field_descriptor) + sizer = encoder.MapSizer(field_descriptor, + _IsMessageMapField(field_descriptor)) elif _IsMessageSetExtension(field_descriptor): field_encoder = encoder.MessageSetItemEncoder(field_descriptor.number) sizer = encoder.MessageSetItemSizer(field_descriptor.number) @@ -891,7 +892,7 @@ def _AddHasExtensionMethod(cls): def _InternalUnpackAny(msg): """Unpacks Any message and returns the unpacked message. - This internal method is differnt from public Any Unpack method which takes + This internal method is different from public Any Unpack method which takes the target message as argument. _InternalUnpackAny method does not have target message type and need to find the message type in descriptor pool. diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/internal/python_protobuf.cc b/third_party/protobuf/3.2.0/python/google/protobuf/internal/python_protobuf.cc new file mode 100644 index 0000000000..f90cc4387e --- /dev/null +++ b/third_party/protobuf/3.2.0/python/google/protobuf/internal/python_protobuf.cc @@ -0,0 +1,63 @@ +// 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: qrczak@google.com (Marcin Kowalczyk) + +#include + +namespace google { +namespace protobuf { +namespace python { + +static const Message* GetCProtoInsidePyProtoStub(PyObject* msg) { + return NULL; +} +static Message* MutableCProtoInsidePyProtoStub(PyObject* msg) { + return NULL; +} + +// This is initialized with a default, stub implementation. +// If python-google.protobuf.cc is loaded, the function pointer is overridden +// with a full implementation. +const Message* (*GetCProtoInsidePyProtoPtr)(PyObject* msg) = + GetCProtoInsidePyProtoStub; +Message* (*MutableCProtoInsidePyProtoPtr)(PyObject* msg) = + MutableCProtoInsidePyProtoStub; + +const Message* GetCProtoInsidePyProto(PyObject* msg) { + return GetCProtoInsidePyProtoPtr(msg); +} +Message* MutableCProtoInsidePyProto(PyObject* msg) { + return MutableCProtoInsidePyProtoPtr(msg); +} + +} // namespace python +} // namespace protobuf +} // namespace google diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/internal/reflection_test.py b/third_party/protobuf/3.2.0/python/google/protobuf/internal/reflection_test.py index 0e88101578..55b0d72e1e 100755 --- a/third_party/protobuf/3.2.0/python/google/protobuf/internal/reflection_test.py +++ b/third_party/protobuf/3.2.0/python/google/protobuf/internal/reflection_test.py @@ -1551,7 +1551,14 @@ class ReflectionTest(BaseTestCase): container = copy.deepcopy(proto1.repeated_int32) self.assertEqual([2, 3], container) - # TODO(anuraag): Implement deepcopy for repeated composite / extension dict + message1 = proto1.repeated_nested_message.add() + message1.bb = 1 + messages = copy.deepcopy(proto1.repeated_nested_message) + self.assertEqual(proto1.repeated_nested_message, messages) + message1.bb = 2 + self.assertNotEqual(proto1.repeated_nested_message, messages) + + # TODO(anuraag): Implement deepcopy for extension dict def testClear(self): proto = unittest_pb2.TestAllTypes() diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/internal/symbol_database_test.py b/third_party/protobuf/3.2.0/python/google/protobuf/internal/symbol_database_test.py index 4f5173b2a2..af42681ae2 100644 --- a/third_party/protobuf/3.2.0/python/google/protobuf/internal/symbol_database_test.py +++ b/third_party/protobuf/3.2.0/python/google/protobuf/internal/symbol_database_test.py @@ -60,6 +60,7 @@ class SymbolDatabaseTest(unittest.TestCase): db.RegisterMessage(unittest_pb2.TestAllTypes.RepeatedGroup) db.RegisterEnumDescriptor(unittest_pb2.ForeignEnum.DESCRIPTOR) db.RegisterEnumDescriptor(unittest_pb2.TestAllTypes.NestedEnum.DESCRIPTOR) + db.RegisterServiceDescriptor(unittest_pb2._TESTSERVICE) return db def testGetPrototype(self): @@ -109,7 +110,13 @@ class SymbolDatabaseTest(unittest.TestCase): self._Database().pool.FindMessageTypeByName( 'protobuf_unittest.TestAllTypes.NestedMessage').full_name) - def testFindFindContainingSymbol(self): + def testFindServiceByName(self): + self.assertEqual( + 'protobuf_unittest.TestService', + self._Database().pool.FindServiceByName( + 'protobuf_unittest.TestService').full_name) + + def testFindFileContainingSymbol(self): # Lookup based on either enum or message. self.assertEqual( 'google/protobuf/unittest.proto', diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/internal/text_format_test.py b/third_party/protobuf/3.2.0/python/google/protobuf/internal/text_format_test.py index 176cbd151a..188310b236 100755 --- a/third_party/protobuf/3.2.0/python/google/protobuf/internal/text_format_test.py +++ b/third_party/protobuf/3.2.0/python/google/protobuf/internal/text_format_test.py @@ -1119,6 +1119,11 @@ class Proto3Tests(unittest.TestCase): packed_message = unittest_pb2.OneString() message.any_value.Unpack(packed_message) self.assertEqual('string', packed_message.data) + message.Clear() + text_format.Parse(text, message, descriptor_pool=descriptor_pool.Default()) + packed_message = unittest_pb2.OneString() + message.any_value.Unpack(packed_message) + self.assertEqual('string', packed_message.data) def testMergeExpandedAnyRepeated(self): message = any_test_pb2.TestAny() @@ -1373,6 +1378,52 @@ class TokenizerTest(unittest.TestCase): self.assertEqual('# some comment', tokenizer.ConsumeComment()) self.assertTrue(tokenizer.AtEnd()) + def testConsumeLineComment(self): + tokenizer = text_format.Tokenizer('# some comment'.splitlines(), + skip_comments=False) + self.assertFalse(tokenizer.AtEnd()) + self.assertEqual((False, '# some comment'), + tokenizer.ConsumeCommentOrTrailingComment()) + self.assertTrue(tokenizer.AtEnd()) + + def testConsumeTwoLineComments(self): + text = '# some comment\n# another comment' + tokenizer = text_format.Tokenizer(text.splitlines(), skip_comments=False) + self.assertEqual((False, '# some comment'), + tokenizer.ConsumeCommentOrTrailingComment()) + self.assertFalse(tokenizer.AtEnd()) + self.assertEqual((False, '# another comment'), + tokenizer.ConsumeCommentOrTrailingComment()) + self.assertTrue(tokenizer.AtEnd()) + + def testConsumeAndCheckTrailingComment(self): + text = 'some_number: 4 # some comment' # trailing comment on the same line + tokenizer = text_format.Tokenizer(text.splitlines(), skip_comments=False) + self.assertRaises(text_format.ParseError, + tokenizer.ConsumeCommentOrTrailingComment) + + self.assertEqual('some_number', tokenizer.ConsumeIdentifier()) + self.assertEqual(tokenizer.token, ':') + tokenizer.NextToken() + self.assertRaises(text_format.ParseError, + tokenizer.ConsumeCommentOrTrailingComment) + self.assertEqual(4, tokenizer.ConsumeInteger()) + self.assertFalse(tokenizer.AtEnd()) + + self.assertEqual((True, '# some comment'), + tokenizer.ConsumeCommentOrTrailingComment()) + self.assertTrue(tokenizer.AtEnd()) + + def testHashinComment(self): + text = 'some_number: 4 # some comment # not a new comment' + tokenizer = text_format.Tokenizer(text.splitlines(), skip_comments=False) + self.assertEqual('some_number', tokenizer.ConsumeIdentifier()) + self.assertEqual(tokenizer.token, ':') + tokenizer.NextToken() + self.assertEqual(4, tokenizer.ConsumeInteger()) + self.assertEqual((True, '# some comment # not a new comment'), + tokenizer.ConsumeCommentOrTrailingComment()) + self.assertTrue(tokenizer.AtEnd()) if __name__ == '__main__': unittest.main() diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/pyext/descriptor.cc b/third_party/protobuf/3.2.0/python/google/protobuf/pyext/descriptor.cc index 924ae0b9cd..f13e1bc14e 100644 --- a/third_party/protobuf/3.2.0/python/google/protobuf/pyext/descriptor.cc +++ b/third_party/protobuf/3.2.0/python/google/protobuf/pyext/descriptor.cc @@ -32,6 +32,7 @@ #include #include +#include #include #include @@ -1666,6 +1667,15 @@ PyObject* PyServiceDescriptor_FromDescriptor( &PyServiceDescriptor_Type, service_descriptor, NULL); } +const ServiceDescriptor* PyServiceDescriptor_AsDescriptor(PyObject* obj) { + if (!PyObject_TypeCheck(obj, &PyServiceDescriptor_Type)) { + PyErr_SetString(PyExc_TypeError, "Not a ServiceDescriptor"); + return NULL; + } + return reinterpret_cast( + reinterpret_cast(obj)->descriptor); +} + namespace method_descriptor { // Unchecked accessor to the C++ pointer. @@ -1769,6 +1779,15 @@ PyObject* PyMethodDescriptor_FromDescriptor( &PyMethodDescriptor_Type, method_descriptor, NULL); } +const MethodDescriptor* PyMethodDescriptor_AsDescriptor(PyObject* obj) { + if (!PyObject_TypeCheck(obj, &PyMethodDescriptor_Type)) { + PyErr_SetString(PyExc_TypeError, "Not a MethodDescriptor"); + return NULL; + } + return reinterpret_cast( + reinterpret_cast(obj)->descriptor); +} + // Add a enum values to a type dictionary. static bool AddEnumValues(PyTypeObject *type, const EnumDescriptor* enum_descriptor) { diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/pyext/descriptor.h b/third_party/protobuf/3.2.0/python/google/protobuf/pyext/descriptor.h index 1ae0e672ed..f081df842d 100644 --- a/third_party/protobuf/3.2.0/python/google/protobuf/pyext/descriptor.h +++ b/third_party/protobuf/3.2.0/python/google/protobuf/pyext/descriptor.h @@ -80,6 +80,8 @@ const Descriptor* PyMessageDescriptor_AsDescriptor(PyObject* obj); const FieldDescriptor* PyFieldDescriptor_AsDescriptor(PyObject* obj); const EnumDescriptor* PyEnumDescriptor_AsDescriptor(PyObject* obj); const FileDescriptor* PyFileDescriptor_AsDescriptor(PyObject* obj); +const ServiceDescriptor* PyServiceDescriptor_AsDescriptor(PyObject* obj); +const MethodDescriptor* PyMethodDescriptor_AsDescriptor(PyObject* obj); // Returns the raw C++ pointer. const void* PyDescriptor_AsVoidPtr(PyObject* obj); diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/pyext/descriptor_pool.cc b/third_party/protobuf/3.2.0/python/google/protobuf/pyext/descriptor_pool.cc index fa66bf9ace..16f4d49d25 100644 --- a/third_party/protobuf/3.2.0/python/google/protobuf/pyext/descriptor_pool.cc +++ b/third_party/protobuf/3.2.0/python/google/protobuf/pyext/descriptor_pool.cc @@ -39,6 +39,7 @@ #include #include #include +#include #if PY_MAJOR_VERSION >= 3 #define PyString_FromStringAndSize PyUnicode_FromStringAndSize @@ -437,8 +438,23 @@ PyObject* AddExtensionDescriptor(PyDescriptorPool* self, PyObject* descriptor) { Py_RETURN_NONE; } -// The code below loads new Descriptors from a serialized FileDescriptorProto. +PyObject* AddServiceDescriptor(PyDescriptorPool* self, PyObject* descriptor) { + const ServiceDescriptor* service_descriptor = + PyServiceDescriptor_AsDescriptor(descriptor); + if (!service_descriptor) { + return NULL; + } + if (service_descriptor != + self->pool->FindServiceByName(service_descriptor->full_name())) { + PyErr_Format(PyExc_ValueError, + "The service descriptor %s does not belong to this pool", + service_descriptor->full_name().c_str()); + return NULL; + } + Py_RETURN_NONE; +} +// The code below loads new Descriptors from a serialized FileDescriptorProto. // Collects errors that occur during proto file building to allow them to be // propagated in the python exception instead of only living in ERROR logs. @@ -538,6 +554,8 @@ static PyMethodDef Methods[] = { "No-op. Add() must have been called before." }, { "AddExtensionDescriptor", (PyCFunction)AddExtensionDescriptor, METH_O, "No-op. Add() must have been called before." }, + { "AddServiceDescriptor", (PyCFunction)AddServiceDescriptor, METH_O, + "No-op. Add() must have been called before." }, { "FindFileByName", (PyCFunction)FindFileByName, METH_O, "Searches for a file descriptor by its .proto name." }, diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/pyext/descriptor_pool.h b/third_party/protobuf/3.2.0/python/google/protobuf/pyext/descriptor_pool.h index c4d7d40343..53ee53dc5e 100644 --- a/third_party/protobuf/3.2.0/python/google/protobuf/pyext/descriptor_pool.h +++ b/third_party/protobuf/3.2.0/python/google/protobuf/pyext/descriptor_pool.h @@ -85,6 +85,7 @@ extern PyTypeObject PyDescriptorPool_Type; namespace cdescriptor_pool { + // Looks up a message by name. // Returns a message Descriptor, or NULL if not found. const Descriptor* FindMessageTypeByName(PyDescriptorPool* self, diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/pyext/message.cc b/third_party/protobuf/3.2.0/python/google/protobuf/pyext/message.cc index c810b7885f..85aaa46fe0 100644 --- a/third_party/protobuf/3.2.0/python/google/protobuf/pyext/message.cc +++ b/third_party/protobuf/3.2.0/python/google/protobuf/pyext/message.cc @@ -779,7 +779,7 @@ PyObject* CheckString(PyObject* arg, const FieldDescriptor* descriptor) { encoded_string = arg; // Already encoded. Py_INCREF(encoded_string); } else { - encoded_string = PyUnicode_AsEncodedObject(arg, "utf-8", NULL); + encoded_string = PyUnicode_AsEncodedString(arg, "utf-8", NULL); } } else { // In this case field type is "bytes". diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/pyext/python_protobuf.h b/third_party/protobuf/3.2.0/python/google/protobuf/pyext/python_protobuf.h deleted file mode 100644 index beb6e4604a..0000000000 --- a/third_party/protobuf/3.2.0/python/google/protobuf/pyext/python_protobuf.h +++ /dev/null @@ -1,57 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: qrczak@google.com (Marcin Kowalczyk) -// -// This module exposes the C proto inside the given Python proto, in -// case the Python proto is implemented with a C proto. - -#ifndef GOOGLE_PROTOBUF_PYTHON_PYTHON_PROTOBUF_H__ -#define GOOGLE_PROTOBUF_PYTHON_PYTHON_PROTOBUF_H__ - -#include - -namespace google { -namespace protobuf { - -class Message; - -namespace python { - -// Return the pointer to the C proto inside the given Python proto, -// or NULL when this is not a Python proto implemented with a C proto. -const Message* GetCProtoInsidePyProto(PyObject* msg); -Message* MutableCProtoInsidePyProto(PyObject* msg); - -} // namespace python -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_PYTHON_PYTHON_PROTOBUF_H__ diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/pyext/repeated_composite_container.cc b/third_party/protobuf/3.2.0/python/google/protobuf/pyext/repeated_composite_container.cc index 43a2bc12d9..9cb4e9a1be 100644 --- a/third_party/protobuf/3.2.0/python/google/protobuf/pyext/repeated_composite_container.cc +++ b/third_party/protobuf/3.2.0/python/google/protobuf/pyext/repeated_composite_container.cc @@ -47,6 +47,7 @@ #include #include #include +#include #if PY_MAJOR_VERSION >= 3 #define PyInt_Check PyLong_Check @@ -485,6 +486,32 @@ int Release(RepeatedCompositeContainer* self) { return 0; } +PyObject* DeepCopy(RepeatedCompositeContainer* self, PyObject* arg) { + ScopedPyObjectPtr cloneObj( + PyType_GenericAlloc(&RepeatedCompositeContainer_Type, 0)); + if (cloneObj == NULL) { + return NULL; + } + RepeatedCompositeContainer* clone = + reinterpret_cast(cloneObj.get()); + + Message* new_message = self->message->New(); + clone->parent = NULL; + clone->parent_field_descriptor = self->parent_field_descriptor; + clone->message = new_message; + clone->owner.reset(new_message); + Py_INCREF(self->child_message_class); + clone->child_message_class = self->child_message_class; + clone->child_messages = PyList_New(0); + + new_message->GetReflection() + ->GetMutableRepeatedFieldRef(new_message, + self->parent_field_descriptor) + .MergeFrom(self->message->GetReflection()->GetRepeatedFieldRef( + *self->message, self->parent_field_descriptor)); + return cloneObj.release(); +} + int SetOwner(RepeatedCompositeContainer* self, const shared_ptr& new_owner) { GOOGLE_CHECK_ATTACHED(self); @@ -551,6 +578,8 @@ static PyMappingMethods MpMethods = { }; static PyMethodDef Methods[] = { + { "__deepcopy__", (PyCFunction)DeepCopy, METH_VARARGS, + "Makes a deep copy of the class." }, { "add", (PyCFunction) Add, METH_VARARGS | METH_KEYWORDS, "Adds an object to the repeated container." }, { "extend", (PyCFunction) Extend, METH_O, diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/pyext/scoped_pyobject_ptr.h b/third_party/protobuf/3.2.0/python/google/protobuf/pyext/scoped_pyobject_ptr.h index a128cd4c61..a2afa7f19d 100644 --- a/third_party/protobuf/3.2.0/python/google/protobuf/pyext/scoped_pyobject_ptr.h +++ b/third_party/protobuf/3.2.0/python/google/protobuf/pyext/scoped_pyobject_ptr.h @@ -36,61 +36,70 @@ #include #include - namespace google { -class ScopedPyObjectPtr { +namespace protobuf { +namespace python { + +// Owns a python object and decrements the reference count on destruction. +// This class is not threadsafe. +template +class ScopedPythonPtr { public: - // Constructor. Defaults to initializing with NULL. - // There is no way to create an uninitialized ScopedPyObjectPtr. - explicit ScopedPyObjectPtr(PyObject* p = NULL) : ptr_(p) { } + // Takes the ownership of the specified object to ScopedPythonPtr. + // The reference count of the specified py_object is not incremented. + explicit ScopedPythonPtr(PyObjectStruct* py_object = NULL) + : ptr_(py_object) {} - // Destructor. If there is a PyObject object, delete it. - ~ScopedPyObjectPtr() { - Py_XDECREF(ptr_); - } + // If a PyObject is owned, decrement its reference count. + ~ScopedPythonPtr() { Py_XDECREF(ptr_); } - // Reset. Deletes the current owned object, if any. - // Then takes ownership of a new object, if given. + // Deletes the current owned object, if any. + // Then takes ownership of a new object without incrementing the reference + // count. // This function must be called with a reference that you own. // this->reset(this->get()) is wrong! // this->reset(this->release()) is OK. - PyObject* reset(PyObject* p = NULL) { + PyObjectStruct* reset(PyObjectStruct* p = NULL) { Py_XDECREF(ptr_); ptr_ = p; return ptr_; } - // Releases ownership of the object. + // Releases ownership of the object without decrementing the reference count. // The caller now owns the returned reference. - PyObject* release() { + PyObjectStruct* release() { PyObject* p = ptr_; ptr_ = NULL; return p; } - PyObject* operator->() const { + PyObjectStruct* operator->() const { assert(ptr_ != NULL); return ptr_; } - PyObject* get() const { return ptr_; } + PyObjectStruct* get() const { return ptr_; } - Py_ssize_t refcnt() const { return Py_REFCNT(ptr_); } + PyObject* as_pyobject() const { return reinterpret_cast(ptr_); } + // Increments the reference count fo the current object. + // Should not be called when no object is held. void inc() const { Py_INCREF(ptr_); } - // Comparison operators. - // These return whether a ScopedPyObjectPtr and a raw pointer - // refer to the same object, not just to two different but equal - // objects. - bool operator==(const PyObject* p) const { return ptr_ == p; } - bool operator!=(const PyObject* p) const { return ptr_ != p; } + // True when a ScopedPyObjectPtr and a raw pointer refer to the same object. + // Comparison operators are non reflexive. + bool operator==(const PyObjectStruct* p) const { return ptr_ == p; } + bool operator!=(const PyObjectStruct* p) const { return ptr_ != p; } private: - PyObject* ptr_; + PyObjectStruct* ptr_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ScopedPyObjectPtr); + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ScopedPythonPtr); }; +typedef ScopedPythonPtr ScopedPyObjectPtr; + +} // namespace python +} // namespace protobuf } // namespace google #endif // GOOGLE_PROTOBUF_PYTHON_CPP_SCOPED_PYOBJECT_PTR_H__ diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/python_protobuf.h b/third_party/protobuf/3.2.0/python/google/protobuf/python_protobuf.h new file mode 100644 index 0000000000..beb6e4604a --- /dev/null +++ b/third_party/protobuf/3.2.0/python/google/protobuf/python_protobuf.h @@ -0,0 +1,57 @@ +// 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: qrczak@google.com (Marcin Kowalczyk) +// +// This module exposes the C proto inside the given Python proto, in +// case the Python proto is implemented with a C proto. + +#ifndef GOOGLE_PROTOBUF_PYTHON_PYTHON_PROTOBUF_H__ +#define GOOGLE_PROTOBUF_PYTHON_PYTHON_PROTOBUF_H__ + +#include + +namespace google { +namespace protobuf { + +class Message; + +namespace python { + +// Return the pointer to the C proto inside the given Python proto, +// or NULL when this is not a Python proto implemented with a C proto. +const Message* GetCProtoInsidePyProto(PyObject* msg); +Message* MutableCProtoInsidePyProto(PyObject* msg); + +} // namespace python +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_PYTHON_PYTHON_PROTOBUF_H__ diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/reflection.py b/third_party/protobuf/3.2.0/python/google/protobuf/reflection.py index 05bafd692f..f4ce8caf9b 100755 --- a/third_party/protobuf/3.2.0/python/google/protobuf/reflection.py +++ b/third_party/protobuf/3.2.0/python/google/protobuf/reflection.py @@ -107,7 +107,7 @@ def MakeClass(descriptor): The Message class object described by the descriptor. """ if descriptor in MESSAGE_CLASS_CACHE: - return MESSAGE_CLASS_CACHE[descriptor] + return MESSAGE_CLASS_CACHE[descriptor] attributes = {} for name, nested_type in descriptor.nested_types_by_name.items(): @@ -115,7 +115,7 @@ def MakeClass(descriptor): attributes[GeneratedProtocolMessageType._DESCRIPTOR_KEY] = descriptor - result = GeneratedProtocolMessageType(str(descriptor.name), (message.Message,), - attributes) + result = GeneratedProtocolMessageType( + str(descriptor.name), (message.Message,), attributes) MESSAGE_CLASS_CACHE[descriptor] = result return result diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/symbol_database.py b/third_party/protobuf/3.2.0/python/google/protobuf/symbol_database.py index ecbef21114..07341efaf4 100644 --- a/third_party/protobuf/3.2.0/python/google/protobuf/symbol_database.py +++ b/third_party/protobuf/3.2.0/python/google/protobuf/symbol_database.py @@ -94,6 +94,17 @@ class SymbolDatabase(message_factory.MessageFactory): self.pool.AddEnumDescriptor(enum_descriptor) return enum_descriptor + def RegisterServiceDescriptor(self, service_descriptor): + """Registers the given service descriptor in the local database. + + Args: + service_descriptor: a descriptor.ServiceDescriptor. + + Returns: + The provided descriptor. + """ + self.pool.AddServiceDescriptor(service_descriptor) + def RegisterFileDescriptor(self, file_descriptor): """Registers the given file descriptor in the local database. diff --git a/third_party/protobuf/3.2.0/python/google/protobuf/text_format.py b/third_party/protobuf/3.2.0/python/google/protobuf/text_format.py index 90f6ce42a4..c216e097d9 100755 --- a/third_party/protobuf/3.2.0/python/google/protobuf/text_format.py +++ b/third_party/protobuf/3.2.0/python/google/protobuf/text_format.py @@ -422,7 +422,8 @@ class _Printer(object): def Parse(text, message, allow_unknown_extension=False, - allow_field_number=False): + allow_field_number=False, + descriptor_pool=None): """Parses a text representation of a protocol message into a message. Args: @@ -431,6 +432,7 @@ def Parse(text, allow_unknown_extension: if True, skip over missing extensions and keep parsing allow_field_number: if True, both field number and field name are allowed. + descriptor_pool: A DescriptorPool used to resolve Any types. Returns: The same message passed as argument. @@ -440,8 +442,11 @@ def Parse(text, """ if not isinstance(text, str): text = text.decode('utf-8') - return ParseLines( - text.split('\n'), message, allow_unknown_extension, allow_field_number) + return ParseLines(text.split('\n'), + message, + allow_unknown_extension, + allow_field_number, + descriptor_pool=descriptor_pool) def Merge(text, @@ -479,7 +484,8 @@ def Merge(text, def ParseLines(lines, message, allow_unknown_extension=False, - allow_field_number=False): + allow_field_number=False, + descriptor_pool=None): """Parses a text representation of a protocol message into a message. Args: @@ -496,7 +502,9 @@ def ParseLines(lines, Raises: ParseError: On text parsing problems. """ - parser = _Parser(allow_unknown_extension, allow_field_number) + parser = _Parser(allow_unknown_extension, + allow_field_number, + descriptor_pool=descriptor_pool) return parser.ParseLines(lines, message) @@ -513,6 +521,7 @@ def MergeLines(lines, allow_unknown_extension: if True, skip over missing extensions and keep parsing allow_field_number: if True, both field number and field name are allowed. + descriptor_pool: A DescriptorPool used to resolve Any types. Returns: The same message passed as argument. @@ -1023,6 +1032,22 @@ class Tokenizer(object): self.NextToken() return result + def ConsumeCommentOrTrailingComment(self): + """Consumes a comment, returns a 2-tuple (trailing bool, comment str).""" + + # Tokenizer initializes _previous_line and _previous_column to 0. As the + # tokenizer starts, it looks like there is a previous token on the line. + just_started = self._line == 0 and self._column == 0 + + before_parsing = self._previous_line + comment = self.ConsumeComment() + + # A trailing comment is a comment on the same line than the previous token. + trailing = (self._previous_line == before_parsing + and not just_started) + + return trailing, comment + def TryConsumeIdentifier(self): try: self.ConsumeIdentifier() diff --git a/third_party/protobuf/3.2.0/ruby/google-protobuf.gemspec b/third_party/protobuf/3.2.0/ruby/google-protobuf.gemspec index 1e30ae4d7d..836b1dd282 100644 --- a/third_party/protobuf/3.2.0/ruby/google-protobuf.gemspec +++ b/third_party/protobuf/3.2.0/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.2.0.1" + s.version = "3.3.0" s.licenses = ["BSD-3-Clause"] s.summary = "Protocol Buffers" s.description = "Protocol Buffers are Google's data interchange format." diff --git a/third_party/protobuf/3.2.0/src/Makefile.am b/third_party/protobuf/3.2.0/src/Makefile.am index bcd81576b2..22026d2fcf 100644 --- a/third_party/protobuf/3.2.0/src/Makefile.am +++ b/third_party/protobuf/3.2.0/src/Makefile.am @@ -37,18 +37,19 @@ protodir = $(includedir) # If you are adding new files here, also remember to change the build files for # all other languages, //protoc-artifacts/build-zip.sh and run # //update_file_list.sh for bazel. -nobase_dist_proto_DATA = google/protobuf/descriptor.proto \ - google/protobuf/any.proto \ - google/protobuf/api.proto \ - google/protobuf/duration.proto \ - google/protobuf/empty.proto \ - google/protobuf/field_mask.proto \ - google/protobuf/source_context.proto \ - google/protobuf/struct.proto \ - google/protobuf/timestamp.proto \ - google/protobuf/type.proto \ - google/protobuf/wrappers.proto \ - google/protobuf/compiler/plugin.proto +nobase_dist_proto_DATA = google/protobuf/descriptor.proto \ + google/protobuf/any.proto \ + google/protobuf/api.proto \ + google/protobuf/duration.proto \ + google/protobuf/empty.proto \ + google/protobuf/field_mask.proto \ + google/protobuf/source_context.proto \ + google/protobuf/struct.proto \ + google/protobuf/timestamp.proto \ + google/protobuf/type.proto \ + google/protobuf/wrappers.proto \ + google/protobuf/compiler/plugin.proto \ + google/protobuf/compiler/profile.proto # Not sure why these don't get cleaned automatically. clean-local: @@ -115,6 +116,7 @@ nobase_include_HEADERS = \ google/protobuf/generated_enum_reflection.h \ google/protobuf/generated_enum_util.h \ google/protobuf/generated_message_reflection.h \ + google/protobuf/generated_message_table_driven.h \ google/protobuf/generated_message_util.h \ google/protobuf/has_bits.h \ google/protobuf/map_entry.h \ @@ -127,6 +129,7 @@ nobase_include_HEADERS = \ google/protobuf/message.h \ google/protobuf/message_lite.h \ google/protobuf/metadata.h \ + google/protobuf/metadata_lite.h \ google/protobuf/reflection.h \ google/protobuf/reflection_ops.h \ google/protobuf/repeated_field.h \ @@ -155,6 +158,7 @@ nobase_include_HEADERS = \ google/protobuf/compiler/parser.h \ google/protobuf/compiler/plugin.h \ google/protobuf/compiler/plugin.pb.h \ + google/protobuf/compiler/profile.pb.h \ google/protobuf/compiler/cpp/cpp_generator.h \ google/protobuf/compiler/csharp/csharp_generator.h \ google/protobuf/compiler/csharp/csharp_names.h \ @@ -180,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 12:0:0 -export-dynamic -no-undefined +libprotobuf_lite_la_LDFLAGS = -version-info 13:0: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 @@ -194,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 \ @@ -225,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 12:0:0 -export-dynamic -no-undefined +libprotobuf_la_LDFLAGS = -version-info 13:0: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 @@ -314,7 +320,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 12:0:0 -export-dynamic -no-undefined +libprotoc_la_LDFLAGS = -version-info 13:0: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 @@ -324,6 +330,7 @@ libprotoc_la_SOURCES = \ google/protobuf/compiler/command_line_interface.cc \ google/protobuf/compiler/plugin.cc \ google/protobuf/compiler/plugin.pb.cc \ + google/protobuf/compiler/profile.pb.cc \ google/protobuf/compiler/subprocess.cc \ google/protobuf/compiler/subprocess.h \ google/protobuf/compiler/zip_writer.cc \ @@ -535,6 +542,9 @@ protoc_inputs = \ google/protobuf/unittest_import.proto \ google/protobuf/unittest_import_public_lite.proto \ google/protobuf/unittest_import_public.proto \ + google/protobuf/unittest_lazy_dependencies.proto \ + google/protobuf/unittest_lazy_dependencies_custom_option.proto \ + google/protobuf/unittest_lazy_dependencies_enum.proto \ google/protobuf/unittest_lite_imports_nonlite.proto \ google/protobuf/unittest_lite.proto \ google/protobuf/unittest_mset.proto \ @@ -639,6 +649,12 @@ protoc_outputs = \ google/protobuf/unittest_import.pb.h \ google/protobuf/unittest_import_public.pb.cc \ google/protobuf/unittest_import_public.pb.h \ + google/protobuf/unittest_lazy_dependencies.pb.cc \ + google/protobuf/unittest_lazy_dependencies.pb.h \ + google/protobuf/unittest_lazy_dependencies_custom_option.pb.cc \ + google/protobuf/unittest_lazy_dependencies_custom_option.pb.h \ + google/protobuf/unittest_lazy_dependencies_enum.pb.cc \ + google/protobuf/unittest_lazy_dependencies_enum.pb.h \ google/protobuf/unittest_lite_imports_nonlite.pb.cc \ google/protobuf/unittest_lite_imports_nonlite.pb.h \ google/protobuf/unittest_mset.pb.cc \ @@ -747,6 +763,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 \ @@ -847,7 +864,12 @@ COMMON_LITE_TEST_SOURCES = \ # depend on gtest because our internal version of gtest depend on proto # full runtime and we want to make sure this test builds without full # runtime. -protobuf_lite_test_LDADD = $(PTHREAD_LIBS) libprotobuf-lite.la +protobuf_lite_test_LDADD = $(PTHREAD_LIBS) libprotobuf-lite.la \ + ../gmock/gtest/lib/libgtest.la \ + ../gmock/lib/libgmock.la \ + ../gmock/lib/libgmock_main.la +protobuf_lite_test_CPPFLAGS= -I$(srcdir)/../gmock/include \ + -I$(srcdir)/../gmock/gtest/include protobuf_lite_test_CXXFLAGS = $(NO_OPT_CXXFLAGS) protobuf_lite_test_SOURCES = \ google/protobuf/lite_unittest.cc \ diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/any.h b/third_party/protobuf/3.2.0/src/google/protobuf/any.h index 04e541667f..c2c27ec333 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/any.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/any.h @@ -63,7 +63,7 @@ class LIBPROTOBUF_EXPORT AnyMetadata { // Unpacks the payload into the given message. Returns false if the message's // type doesn't match the type specified in the type URL (i.e., the full - // name after the last "/" of the type URL doesn't match the message's actaul + // name after the last "/" of the type URL doesn't match the message's actual // full name) or parsing the payload has failed. bool UnpackTo(Message* message) const; @@ -90,8 +90,8 @@ extern const char kTypeGoogleProdComPrefix[]; // "type.googleprod.com/". // Get the proto type name from Any::type_url value. For example, passing // "type.googleapis.com/rpc.QueryOrigin" will return "rpc.QueryOrigin" in -// *full_type_name. Returns false if type_url does not start with -// "type.googleapis.com" or "type.googleprod.com". +// *full_type_name. Returns false if the type_url does not have a "/" +// in the type url separating the full type name. bool ParseAnyTypeUrl(const string& type_url, string* full_type_name); // See if message is of type google.protobuf.Any, if so, return the descriptors diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/any.pb.cc b/third_party/protobuf/3.2.0/src/google/protobuf/any.pb.cc index 94c9539f44..6c80aaa24e 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/any.pb.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/any.pb.cc @@ -31,11 +31,26 @@ namespace { } // namespace +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField + const TableStruct::entries[] = { + {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, +}; + +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField + const TableStruct::aux[] = { + ::google::protobuf::internal::AuxillaryParseTableField(), +}; +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const + TableStruct::schema[] = { + { NULL, NULL, 0, -1, -1, false }, +}; + const ::google::protobuf::uint32 TableStruct::offsets[] = { ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Any, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Any, type_url_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Any, value_), }; @@ -186,7 +201,7 @@ void Any::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* Any::descriptor() { protobuf_google_2fprotobuf_2fany_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fany_2eproto::file_level_metadata[0].descriptor; + return protobuf_google_2fprotobuf_2fany_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const Any& Any::default_instance() { @@ -270,6 +285,9 @@ failure: void Any::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.Any) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // string type_url = 1; if (this->type_url().size() > 0) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -291,8 +309,10 @@ 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; + // string type_url = 1; if (this->type_url().size() > 0) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -359,6 +379,9 @@ void Any::MergeFrom(const Any& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Any) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + if (from.type_url().size() > 0) { type_url_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.type_url_); @@ -399,7 +422,7 @@ void Any::InternalSwap(Any* other) { ::google::protobuf::Metadata Any::GetMetadata() const { protobuf_google_2fprotobuf_2fany_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fany_2eproto::file_level_metadata[0]; + return protobuf_google_2fprotobuf_2fany_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -427,6 +450,7 @@ void Any::set_type_url(::std::string&& value) { } #endif void Any::set_type_url(const char* value) { + GOOGLE_DCHECK(value != NULL); type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Any.type_url) @@ -479,6 +503,7 @@ void Any::set_value(::std::string&& value) { } #endif void Any::set_value(const char* value) { + GOOGLE_DCHECK(value != NULL); value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Any.value) diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/any.pb.h b/third_party/protobuf/3.2.0/src/google/protobuf/any.pb.h index 1a61d5afa2..bc05fb35c8 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/any.pb.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/any.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3002000 +#if GOOGLE_PROTOBUF_VERSION < 3003000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003000 < 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. @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,9 @@ namespace protobuf { namespace protobuf_google_2fprotobuf_2fany_2eproto { // Internal implementation detail -- do not call these. struct LIBPROTOBUF_EXPORT TableStruct { + static const ::google::protobuf::internal::ParseTableField entries[]; + static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; + static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; static void InitDefaultsImpl(); static void Shutdown(); @@ -73,6 +77,8 @@ class LIBPROTOBUF_EXPORT Any : public ::google::protobuf::Message /* @@protoc_in return reinterpret_cast( &_Any_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 0; // implements Any ----------------------------------------------- @@ -105,11 +111,6 @@ class LIBPROTOBUF_EXPORT Any : public ::google::protobuf::Message /* @@protoc_in ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -167,7 +168,7 @@ class LIBPROTOBUF_EXPORT Any : public ::google::protobuf::Message /* @@protoc_in ::google::protobuf::internal::ArenaStringPtr value_; mutable int _cached_size_; ::google::protobuf::internal::AnyMetadata _any_metadata_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fany_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2fany_2eproto::TableStruct; }; // =================================================================== @@ -199,6 +200,7 @@ inline void Any::set_type_url(::std::string&& value) { } #endif inline void Any::set_type_url(const char* value) { + GOOGLE_DCHECK(value != NULL); type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Any.type_url) @@ -251,6 +253,7 @@ inline void Any::set_value(::std::string&& value) { } #endif inline void Any::set_value(const char* value) { + GOOGLE_DCHECK(value != NULL); value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Any.value) diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/api.pb.cc b/third_party/protobuf/3.2.0/src/google/protobuf/api.pb.cc index 6518e51817..94c6685f57 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/api.pb.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/api.pb.cc @@ -35,11 +35,28 @@ namespace { } // namespace +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField + const TableStruct::entries[] = { + {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, +}; + +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField + const TableStruct::aux[] = { + ::google::protobuf::internal::AuxillaryParseTableField(), +}; +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const + TableStruct::schema[] = { + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, +}; + const ::google::protobuf::uint32 TableStruct::offsets[] = { ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, methods_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, options_), @@ -51,6 +68,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, request_type_url_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, request_streaming_), @@ -62,14 +80,15 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Mixin, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Mixin, name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Mixin, root_), }; static const ::google::protobuf::internal::MigrationSchema schemas[] = { { 0, -1, sizeof(Api)}, - { 11, -1, sizeof(Method)}, - { 22, -1, sizeof(Mixin)}, + { 12, -1, sizeof(Method)}, + { 24, -1, sizeof(Mixin)}, }; static ::google::protobuf::Message const * const file_default_instances[] = { @@ -246,7 +265,7 @@ void Api::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* Api::descriptor() { protobuf_google_2fprotobuf_2fapi_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fapi_2eproto::file_level_metadata[0].descriptor; + return protobuf_google_2fprotobuf_2fapi_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const Api& Api::default_instance() { @@ -306,13 +325,11 @@ bool Api::MergePartialFromCodedStream( case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(18u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_methods())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -320,13 +337,11 @@ bool Api::MergePartialFromCodedStream( case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(26u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_options())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -362,13 +377,11 @@ bool Api::MergePartialFromCodedStream( case 6: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(50u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_mixins())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -411,6 +424,9 @@ failure: void Api::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.Api) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // string name = 1; if (this->name().size() > 0) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -466,8 +482,10 @@ 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; + // string name = 1; if (this->name().size() > 0) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -483,14 +501,14 @@ void Api::SerializeWithCachedSizes( for (unsigned int i = 0, n = this->methods_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 2, this->methods(i), false, target); + 2, this->methods(i), deterministic, target); } // repeated .google.protobuf.Option options = 3; for (unsigned int i = 0, n = this->options_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 3, this->options(i), false, target); + 3, this->options(i), deterministic, target); } // string version = 4; @@ -508,14 +526,14 @@ void Api::SerializeWithCachedSizes( if (this->has_source_context()) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 5, *this->source_context_, false, target); + 5, *this->source_context_, deterministic, target); } // repeated .google.protobuf.Mixin mixins = 6; for (unsigned int i = 0, n = this->mixins_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 6, this->mixins(i), false, target); + 6, this->mixins(i), deterministic, target); } // .google.protobuf.Syntax syntax = 7; @@ -618,6 +636,9 @@ void Api::MergeFrom(const Api& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Api) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + methods_.MergeFrom(from.methods_); options_.MergeFrom(from.options_); mixins_.MergeFrom(from.mixins_); @@ -660,9 +681,9 @@ void Api::Swap(Api* other) { InternalSwap(other); } void Api::InternalSwap(Api* other) { - methods_.UnsafeArenaSwap(&other->methods_); - options_.UnsafeArenaSwap(&other->options_); - mixins_.UnsafeArenaSwap(&other->mixins_); + methods_.InternalSwap(&other->methods_); + options_.InternalSwap(&other->options_); + mixins_.InternalSwap(&other->mixins_); name_.Swap(&other->name_); version_.Swap(&other->version_); std::swap(source_context_, other->source_context_); @@ -672,7 +693,7 @@ void Api::InternalSwap(Api* other) { ::google::protobuf::Metadata Api::GetMetadata() const { protobuf_google_2fprotobuf_2fapi_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fapi_2eproto::file_level_metadata[0]; + return protobuf_google_2fprotobuf_2fapi_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -700,6 +721,7 @@ void Api::set_name(::std::string&& value) { } #endif void Api::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Api.name) @@ -812,6 +834,7 @@ void Api::set_version(::std::string&& value) { } #endif void Api::set_version(const char* value) { + GOOGLE_DCHECK(value != NULL); version_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Api.version) @@ -998,7 +1021,7 @@ void Method::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* Method::descriptor() { protobuf_google_2fprotobuf_2fapi_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fapi_2eproto::file_level_metadata[1].descriptor; + return protobuf_google_2fprotobuf_2fapi_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const Method& Method::default_instance() { @@ -1114,13 +1137,11 @@ bool Method::MergePartialFromCodedStream( case 6: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(50u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_options())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -1163,6 +1184,9 @@ failure: void Method::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.Method) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // string name = 1; if (this->name().size() > 0) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -1220,8 +1244,10 @@ 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; + // string name = 1; if (this->name().size() > 0) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -1269,7 +1295,7 @@ void Method::SerializeWithCachedSizes( for (unsigned int i = 0, n = this->options_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 6, this->options(i), false, target); + 6, this->options(i), deterministic, target); } // .google.protobuf.Syntax syntax = 7; @@ -1360,6 +1386,9 @@ void Method::MergeFrom(const Method& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Method) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + options_.MergeFrom(from.options_); if (from.name().size() > 0) { @@ -1407,7 +1436,7 @@ void Method::Swap(Method* other) { InternalSwap(other); } void Method::InternalSwap(Method* other) { - options_.UnsafeArenaSwap(&other->options_); + options_.InternalSwap(&other->options_); name_.Swap(&other->name_); request_type_url_.Swap(&other->request_type_url_); response_type_url_.Swap(&other->response_type_url_); @@ -1419,7 +1448,7 @@ void Method::InternalSwap(Method* other) { ::google::protobuf::Metadata Method::GetMetadata() const { protobuf_google_2fprotobuf_2fapi_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fapi_2eproto::file_level_metadata[1]; + return protobuf_google_2fprotobuf_2fapi_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -1447,6 +1476,7 @@ void Method::set_name(::std::string&& value) { } #endif void Method::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Method.name) @@ -1499,6 +1529,7 @@ void Method::set_request_type_url(::std::string&& value) { } #endif void Method::set_request_type_url(const char* value) { + GOOGLE_DCHECK(value != NULL); request_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Method.request_type_url) @@ -1565,6 +1596,7 @@ void Method::set_response_type_url(::std::string&& value) { } #endif void Method::set_response_type_url(const char* value) { + GOOGLE_DCHECK(value != NULL); response_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Method.response_type_url) @@ -1709,7 +1741,7 @@ void Mixin::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* Mixin::descriptor() { protobuf_google_2fprotobuf_2fapi_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fapi_2eproto::file_level_metadata[2].descriptor; + return protobuf_google_2fprotobuf_2fapi_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const Mixin& Mixin::default_instance() { @@ -1797,6 +1829,9 @@ failure: void Mixin::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.Mixin) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // string name = 1; if (this->name().size() > 0) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -1822,8 +1857,10 @@ 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; + // string name = 1; if (this->name().size() > 0) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -1894,6 +1931,9 @@ void Mixin::MergeFrom(const Mixin& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Mixin) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + if (from.name().size() > 0) { name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); @@ -1934,7 +1974,7 @@ void Mixin::InternalSwap(Mixin* other) { ::google::protobuf::Metadata Mixin::GetMetadata() const { protobuf_google_2fprotobuf_2fapi_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fapi_2eproto::file_level_metadata[2]; + return protobuf_google_2fprotobuf_2fapi_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -1962,6 +2002,7 @@ void Mixin::set_name(::std::string&& value) { } #endif void Mixin::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Mixin.name) @@ -2014,6 +2055,7 @@ void Mixin::set_root(::std::string&& value) { } #endif void Mixin::set_root(const char* value) { + GOOGLE_DCHECK(value != NULL); root_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Mixin.root) diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/api.pb.h b/third_party/protobuf/3.2.0/src/google/protobuf/api.pb.h index 2eb571e613..108c63a424 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/api.pb.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/api.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3002000 +#if GOOGLE_PROTOBUF_VERSION < 3003000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003000 < 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. @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -69,6 +70,9 @@ namespace protobuf { namespace protobuf_google_2fprotobuf_2fapi_2eproto { // Internal implementation detail -- do not call these. struct LIBPROTOBUF_EXPORT TableStruct { + static const ::google::protobuf::internal::ParseTableField entries[]; + static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; + static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; static void InitDefaultsImpl(); static void Shutdown(); @@ -98,6 +102,8 @@ class LIBPROTOBUF_EXPORT Api : public ::google::protobuf::Message /* @@protoc_in return reinterpret_cast( &_Api_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 0; void Swap(Api* other); @@ -120,11 +126,6 @@ class LIBPROTOBUF_EXPORT Api : public ::google::protobuf::Message /* @@protoc_in ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -237,7 +238,7 @@ class LIBPROTOBUF_EXPORT Api : public ::google::protobuf::Message /* @@protoc_in ::google::protobuf::SourceContext* source_context_; int syntax_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fapi_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2fapi_2eproto::TableStruct; }; // ------------------------------------------------------------------- @@ -260,6 +261,8 @@ class LIBPROTOBUF_EXPORT Method : public ::google::protobuf::Message /* @@protoc return reinterpret_cast( &_Method_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 1; void Swap(Method* other); @@ -282,11 +285,6 @@ class LIBPROTOBUF_EXPORT Method : public ::google::protobuf::Message /* @@protoc ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -392,7 +390,7 @@ class LIBPROTOBUF_EXPORT Method : public ::google::protobuf::Message /* @@protoc bool response_streaming_; int syntax_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fapi_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2fapi_2eproto::TableStruct; }; // ------------------------------------------------------------------- @@ -415,6 +413,8 @@ class LIBPROTOBUF_EXPORT Mixin : public ::google::protobuf::Message /* @@protoc_ return reinterpret_cast( &_Mixin_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 2; void Swap(Mixin* other); @@ -437,11 +437,6 @@ class LIBPROTOBUF_EXPORT Mixin : public ::google::protobuf::Message /* @@protoc_ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -498,7 +493,7 @@ class LIBPROTOBUF_EXPORT Mixin : public ::google::protobuf::Message /* @@protoc_ ::google::protobuf::internal::ArenaStringPtr name_; ::google::protobuf::internal::ArenaStringPtr root_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fapi_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2fapi_2eproto::TableStruct; }; // =================================================================== @@ -530,6 +525,7 @@ inline void Api::set_name(::std::string&& value) { } #endif inline void Api::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Api.name) @@ -642,6 +638,7 @@ inline void Api::set_version(::std::string&& value) { } #endif inline void Api::set_version(const char* value) { + GOOGLE_DCHECK(value != NULL); version_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Api.version) @@ -781,6 +778,7 @@ inline void Method::set_name(::std::string&& value) { } #endif inline void Method::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Method.name) @@ -833,6 +831,7 @@ inline void Method::set_request_type_url(::std::string&& value) { } #endif inline void Method::set_request_type_url(const char* value) { + GOOGLE_DCHECK(value != NULL); request_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Method.request_type_url) @@ -899,6 +898,7 @@ inline void Method::set_response_type_url(::std::string&& value) { } #endif inline void Method::set_response_type_url(const char* value) { + GOOGLE_DCHECK(value != NULL); response_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Method.response_type_url) @@ -1013,6 +1013,7 @@ inline void Mixin::set_name(::std::string&& value) { } #endif inline void Mixin::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Mixin.name) @@ -1065,6 +1066,7 @@ inline void Mixin::set_root(::std::string&& value) { } #endif inline void Mixin::set_root(const char* value) { + GOOGLE_DCHECK(value != NULL); root_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Mixin.root) diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/arena.h b/third_party/protobuf/3.2.0/src/google/protobuf/arena.h index 05e05ebc19..b6a375ac56 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/arena.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/arena.h @@ -303,6 +303,17 @@ class LIBPROTOBUF_EXPORT Arena { // (unless the destructor is trivial). Hence, from T's point of view, it is as // if the object were allocated on the heap (except that the underlying memory // is obtained from the arena). +#if LANG_CXX11 + template GOOGLE_ATTRIBUTE_ALWAYS_INLINE + static T* Create(::google::protobuf::Arena* arena, Args&&... args) { + if (arena == NULL) { + return new T(std::forward(args)...); + } else { + return arena->CreateInternal(google::protobuf::internal::has_trivial_destructor::value, + std::forward(args)...); + } + } +#endif template GOOGLE_ATTRIBUTE_ALWAYS_INLINE static T* Create(::google::protobuf::Arena* arena) { if (arena == NULL) { @@ -322,17 +333,6 @@ class LIBPROTOBUF_EXPORT Arena { arg); } } -#if LANG_CXX11 - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - static T* Create(::google::protobuf::Arena* arena, Arg&& arg) { - if (arena == NULL) { - return new T(std::move(arg)); - } else { - return arena->CreateInternal(google::protobuf::internal::has_trivial_destructor::value, - std::move(arg)); - } - } -#endif // Version of the above with two constructor arguments for the created object. template GOOGLE_ATTRIBUTE_ALWAYS_INLINE @@ -655,35 +655,34 @@ class LIBPROTOBUF_EXPORT Arena { AllocateAligned(RTTI_TYPE_ID(T), sizeof(T) * num_elements)); } - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - T* CreateInternal(bool skip_explicit_ownership) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) T(); +#if LANG_CXX11 + template GOOGLE_ATTRIBUTE_ALWAYS_INLINE + T* CreateInternal(bool skip_explicit_ownership, Args&&... args) { + T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) + T(std::forward(args)...); if (!skip_explicit_ownership) { AddListNode(t, &internal::arena_destruct_object); } return t; } - - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - T* CreateInternal(bool skip_explicit_ownership, const Arg& arg) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) T(arg); +#endif + template GOOGLE_ATTRIBUTE_ALWAYS_INLINE + T* CreateInternal(bool skip_explicit_ownership) { + T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) T(); if (!skip_explicit_ownership) { AddListNode(t, &internal::arena_destruct_object); } return t; } -#if LANG_CXX11 template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - T* CreateInternal(bool skip_explicit_ownership, Arg&& arg) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) T( - std::move(arg)); + T* CreateInternal(bool skip_explicit_ownership, const Arg& arg) { + T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) T(arg); if (!skip_explicit_ownership) { AddListNode(t, &internal::arena_destruct_object); } return t; } -#endif template GOOGLE_ATTRIBUTE_ALWAYS_INLINE T* CreateInternal( @@ -796,22 +795,20 @@ class LIBPROTOBUF_EXPORT Arena { template GOOGLE_ATTRIBUTE_ALWAYS_INLINE T* CreateMessageInternal(typename T::InternalArenaConstructable_*) { - return CreateInternal(SkipDeleteList(static_cast(0)), - this); + return CreateInternal(SkipDeleteList(static_cast(0)), this); } template GOOGLE_ATTRIBUTE_ALWAYS_INLINE T* CreateMessageInternal(typename T::InternalArenaConstructable_*, const Arg& arg) { - return CreateInternal(SkipDeleteList(static_cast(0)), - this, arg); + return CreateInternal(SkipDeleteList(static_cast(0)), this, arg); } template GOOGLE_ATTRIBUTE_ALWAYS_INLINE T* CreateMessageInternal(typename T::InternalArenaConstructable_*, const Arg1& arg1, const Arg2& arg2) { - return CreateInternal(SkipDeleteList(static_cast(0)), - this, arg1, arg2); + return CreateInternal(SkipDeleteList(static_cast(0)), this, arg1, + arg2); } // CreateInArenaStorage is used to implement map field. Without it, diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/arena_unittest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/arena_unittest.cc index 4f9571dbff..6172cade09 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/arena_unittest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/arena_unittest.cc @@ -180,6 +180,35 @@ TEST(ArenaTest, BasicCreate) { EXPECT_EQ(2, notifier.GetCount()); } +TEST(ArenaTest, CreateAndConstCopy) { + Arena arena; + const string s("foo"); + const string* s_copy = Arena::Create(&arena, s); + EXPECT_TRUE(s_copy != NULL); + EXPECT_EQ("foo", s); + EXPECT_EQ("foo", *s_copy); +} + +TEST(ArenaTest, CreateAndNonConstCopy) { + Arena arena; + string s("foo"); + const string* s_copy = Arena::Create(&arena, s); + EXPECT_TRUE(s_copy != NULL); + EXPECT_EQ("foo", s); + EXPECT_EQ("foo", *s_copy); +} + +#if LANG_CXX11 +TEST(ArenaTest, CreateAndMove) { + Arena arena; + string s("foo"); + const string* s_move = Arena::Create(&arena, std::move(s)); + EXPECT_TRUE(s_move != NULL); + EXPECT_TRUE(s.empty()); // NOLINT + EXPECT_EQ("foo", *s_move); +} +#endif + TEST(ArenaTest, CreateWithFourConstructorArguments) { Arena arena; const string three("3"); @@ -214,6 +243,29 @@ TEST(ArenaTest, CreateWithEightConstructorArguments) { ASSERT_EQ("8", new_object->eight_); } +#if LANG_CXX11 +class PleaseMoveMe { + public: + explicit PleaseMoveMe(const string& value) : value_(value) {} + PleaseMoveMe(PleaseMoveMe&&) = default; + PleaseMoveMe(const PleaseMoveMe&) = delete; + + const string& value() const { return value_; } + + private: + string value_; +}; + +TEST(ArenaTest, CreateWithMoveArguments) { + Arena arena; + PleaseMoveMe one("1"); + const PleaseMoveMe* new_object = + Arena::Create(&arena, std::move(one)); + EXPECT_TRUE(new_object); + ASSERT_EQ("1", new_object->value()); +} +#endif + TEST(ArenaTest, InitialBlockTooSmall) { // Construct a small (64 byte) initial block of memory to be used by the // arena allocator; then, allocate an object which will not fit in the diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/arenastring.cc b/third_party/protobuf/3.2.0/src/google/protobuf/arenastring.cc index f10732c0c4..7f33a0c865 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/arenastring.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/arenastring.cc @@ -38,16 +38,6 @@ namespace protobuf { namespace internal { -void ArenaStringPtr::AssignWithDefault(const ::std::string* default_value, - ArenaStringPtr value) { - const ::std::string* me = *UnsafeRawStringPointer(); - const ::std::string* other = *value.UnsafeRawStringPointer(); - // If the pointers are the same then do nothing. - if (me != other) { - SetNoArena(default_value, value.GetNoArena()); - } -} - } // namespace internal } // namespace protobuf } // namespace google diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/arenastring.h b/third_party/protobuf/3.2.0/src/google/protobuf/arenastring.h index a7efb7529b..63fd00e567 100755 --- a/third_party/protobuf/3.2.0/src/google/protobuf/arenastring.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/arenastring.h @@ -310,5 +310,21 @@ struct LIBPROTOBUF_EXPORT ArenaStringPtr { +namespace protobuf { +namespace internal { + +inline void ArenaStringPtr::AssignWithDefault(const ::std::string* default_value, + ArenaStringPtr value) { + const ::std::string* me = *UnsafeRawStringPointer(); + const ::std::string* other = *value.UnsafeRawStringPointer(); + // If the pointers are the same then do nothing. + if (me != other) { + SetNoArena(default_value, value.GetNoArena()); + } +} + +} // namespace internal +} // namespace protobuf + } // namespace google #endif // GOOGLE_PROTOBUF_ARENASTRING_H__ diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/code_generator.h b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/code_generator.h index e2b2a66167..b917d37334 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/code_generator.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/code_generator.h @@ -162,7 +162,7 @@ typedef GeneratorContext OutputDirectory; // "foo=bar,baz,qux=corge" // parses to the pairs: // ("foo", "bar"), ("baz", ""), ("qux", "corge") -extern void LIBPROTOC_EXPORT ParseGeneratorParameter(const string&, +extern void ParseGeneratorParameter(const string&, std::vector >*); } // namespace compiler diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/command_line_interface.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/command_line_interface.cc index 5066989145..56b010f7bc 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/command_line_interface.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/command_line_interface.cc @@ -45,10 +45,7 @@ #endif #include #include -#ifdef _MSC_VER -#include -#include -#else +#ifndef _MSC_VER #include #endif #include @@ -103,6 +100,14 @@ namespace compiler { namespace { #if defined(_WIN32) && !defined(__CYGWIN__) static const char* kPathSeparator = ";"; +// DO NOT include , instead create functions in io_win32.{h,cc} and import +// them like we do below. +using google::protobuf::stubs::access; +using google::protobuf::stubs::close; +using google::protobuf::stubs::mkdir; +using google::protobuf::stubs::open; +using google::protobuf::stubs::setmode; +using google::protobuf::stubs::write; #else static const char* kPathSeparator = ":"; #endif @@ -126,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.) @@ -136,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.) @@ -789,8 +794,8 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) { // Enforce --disallow_services. if (disallow_services_ && parsed_file->service_count() > 0) { - cerr << parsed_file->name() << ": This file contains services, but " - "--disallow_services was used." << endl; + std::cerr << parsed_file->name() << ": This file contains services, but " + "--disallow_services was used." << std::endl; return 1; } @@ -801,11 +806,11 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) { if (direct_dependencies_.find(parsed_file->dependency(i)->name()) == direct_dependencies_.end()) { indirect_imports = true; - cerr << parsed_file->name() << ": " - << StringReplace(direct_dependencies_violation_msg_, "%s", - parsed_file->dependency(i)->name(), - true /* replace_all */) - << std::endl; + std::cerr << parsed_file->name() << ": " + << StringReplace(direct_dependencies_violation_msg_, "%s", + parsed_file->dependency(i)->name(), + true /* replace_all */) + << std::endl; } } if (indirect_imports) { @@ -1023,7 +1028,7 @@ CommandLineInterface::ParseArguments(int argc, const char* const argv[]) { // Make sure each plugin option has a matching plugin output. bool foundUnknownPluginOption = false; - for (map::const_iterator i = plugin_parameters_.begin(); + for (std::map::const_iterator i = plugin_parameters_.begin(); i != plugin_parameters_.end(); ++i) { if (plugins_.find(i->first) != plugins_.end()) { continue; @@ -1206,7 +1211,8 @@ CommandLineInterface::InterpretArgument(const string& name, if (access(disk_path.c_str(), F_OK) < 0) { // Try the original path; it may have just happed to have a '=' in it. if (access(parts[i].c_str(), F_OK) < 0) { - cerr << disk_path << ": warning: directory does not exist." << endl; + std::cerr << disk_path << ": warning: directory does not exist." + << std::endl; } else { virtual_path = ""; disk_path = parts[i]; @@ -1287,9 +1293,9 @@ CommandLineInterface::InterpretArgument(const string& name, if (!version_info_.empty()) { std::cout << version_info_ << std::endl; } - cout << "libprotoc " + std::cout << "libprotoc " << protobuf::internal::VersionString(GOOGLE_PROTOBUF_VERSION) - << endl; + << std::endl; return PARSE_ARGUMENT_DONE_AND_EXIT; // Exit without running compiler. } else if (name == "--disallow_services") { @@ -1376,6 +1382,7 @@ CommandLineInterface::InterpretArgument(const string& name, } mode_ = MODE_PRINT; print_mode_ = PRINT_FREE_FIELDS; + } else if (name == "--profile_path") { } else { // Some other flag. Look it up in the generators list. const GeneratorInfo* generator_info = @@ -1775,31 +1782,34 @@ bool CommandLineInterface::EncodeOrDecode(const DescriptorPool* pool) { } bool CommandLineInterface::WriteDescriptorSet( - const std::vector parsed_files) { + const std::vector& parsed_files) { FileDescriptorSet file_set; - if (imports_in_descriptor_set_) { - std::set already_seen; - for (int i = 0; i < parsed_files.size(); i++) { - GetTransitiveDependencies(parsed_files[i], - true, // Include json_name - source_info_in_descriptor_set_, - &already_seen, file_set.mutable_file()); - } - } else { - std::set already_seen; + std::set already_seen; + if (!imports_in_descriptor_set_) { + // Since we don't want to output transitive dependencies, but we do want + // things to be in dependency order, add all dependencies that aren't in + // parsed_files to already_seen. This will short circuit the recursion + // in GetTransitiveDependencies. + std::set to_output; + to_output.insert(parsed_files.begin(), parsed_files.end()); for (int i = 0; i < parsed_files.size(); i++) { - if (!already_seen.insert(parsed_files[i]).second) { - continue; - } - FileDescriptorProto* file_proto = file_set.add_file(); - parsed_files[i]->CopyTo(file_proto); - parsed_files[i]->CopyJsonNameTo(file_proto); - if (source_info_in_descriptor_set_) { - parsed_files[i]->CopySourceCodeInfoTo(file_proto); + const FileDescriptor* file = parsed_files[i]; + for (int i = 0; i < file->dependency_count(); i++) { + const FileDescriptor* dependency = file->dependency(i); + // if the dependency isn't in parsed files, mark it as already seen + if (to_output.find(dependency) == to_output.end()) { + already_seen.insert(dependency); + } } } } + for (int i = 0; i < parsed_files.size(); i++) { + GetTransitiveDependencies(parsed_files[i], + true, // Include json_name + source_info_in_descriptor_set_, + &already_seen, file_set.mutable_file()); + } int fd; do { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/command_line_interface.h b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/command_line_interface.h index 8f8c2682fd..997c17482d 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/command_line_interface.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/command_line_interface.h @@ -258,7 +258,7 @@ class LIBPROTOC_EXPORT CommandLineInterface { // Implements the --descriptor_set_out option. bool WriteDescriptorSet( - const std::vector parsed_files); + const std::vector& parsed_files); // Implements the --dependency_out option bool GenerateDependencyManifestFile( @@ -391,6 +391,11 @@ class LIBPROTOC_EXPORT CommandLineInterface { // dependency file will be written. Otherwise, empty. string dependency_out_name_; + // Path to a file that contains serialized AccessInfo which provides + // relative hotness of fields per message. This helps protoc to generate + // better code. + string profile_path_; + // True if --include_imports was given, meaning that we should // write all transitive dependencies to the DescriptorSet. Otherwise, only // the .proto files listed on the command-line are added. diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/command_line_interface_unittest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/command_line_interface_unittest.cc index eab14f6001..178999ddae 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -32,12 +32,10 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include -#include #include -#ifdef _MSC_VER -#include -#else +#include +#include +#ifndef _MSC_VER #include #endif #include @@ -46,46 +44,46 @@ #endif #include -#include -#include -#include -#include -#include +#include +#include #include #include #include -#include +#include +#include #include -#include -#include -#include +#include +#include +#include +#include #include #include #include #include +#include +#include namespace google { namespace protobuf { namespace compiler { +#if defined(_WIN32) +// DO NOT include , instead create functions in io_win32.{h,cc} and import +// them like we do below. +using google::protobuf::stubs::access; +using google::protobuf::stubs::dup; +using google::protobuf::stubs::dup2; +using google::protobuf::stubs::close; +using google::protobuf::stubs::open; +using google::protobuf::stubs::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) { @@ -101,7 +99,7 @@ class CommandLineInterfaceTest : public testing::Test { // command is automatically split on spaces, and the string "$tmpdir" // is replaced with TestTempDir(). void Run(const string& command); - void RunWithArgs(vector args); + void RunWithArgs(std::vector args); // ----------------------------------------------------------------- // Methods to set up the test (called before Run()). @@ -301,7 +299,7 @@ void CommandLineInterfaceTest::Run(const string& command) { RunWithArgs(Split(command, " ", true)); } -void CommandLineInterfaceTest::RunWithArgs(vector args) { +void CommandLineInterfaceTest::RunWithArgs(std::vector args) { if (!disallow_plugins_) { cli_.AllowPlugins("prefix-"); #ifndef GOOGLE_THIRD_PARTY_PROTOBUF @@ -1044,7 +1042,7 @@ TEST_F(CommandLineInterfaceTest, DirectDependencies_CustomErrorMessage) { "syntax = \"proto2\";\n" "message Bar { optional string text = 1; }"); - vector commands; + std::vector commands; commands.push_back("protocol_compiler"); commands.push_back("--test_out=$tmpdir"); commands.push_back("--proto_path=$tmpdir"); @@ -1127,15 +1125,17 @@ TEST_F(CommandLineInterfaceTest, WriteDescriptorSetWithDuplicates) { ReadDescriptorSet("descriptor_set", &descriptor_set); if (HasFatalFailure()) return; EXPECT_EQ(3, descriptor_set.file_size()); - EXPECT_EQ("bar.proto", descriptor_set.file(0).name()); - EXPECT_EQ("foo.proto", descriptor_set.file(1).name()); + // foo should come first since the output is in dependency order. + // since bar and baz are unordered, they should be in command line order. + EXPECT_EQ("foo.proto", descriptor_set.file(0).name()); + EXPECT_EQ("bar.proto", descriptor_set.file(1).name()); EXPECT_EQ("baz.proto", descriptor_set.file(2).name()); // Descriptor set should not have source code info. EXPECT_FALSE(descriptor_set.file(0).has_source_code_info()); // Descriptor set should have json_name. - EXPECT_EQ("Bar", descriptor_set.file(0).message_type(0).name()); - EXPECT_EQ("foo", descriptor_set.file(0).message_type(0).field(0).name()); - EXPECT_TRUE(descriptor_set.file(0).message_type(0).field(0).has_json_name()); + EXPECT_EQ("Bar", descriptor_set.file(1).message_type(0).name()); + EXPECT_EQ("foo", descriptor_set.file(1).message_type(0).field(0).name()); + EXPECT_TRUE(descriptor_set.file(1).message_type(0).field(0).has_json_name()); } TEST_F(CommandLineInterfaceTest, WriteDescriptorSetWithSourceInfo) { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc index bf4e58319c..fce58c0292 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc @@ -46,12 +46,11 @@ #include #include -#include #include +#include +#include #include #include -#include -#include #include #include @@ -126,9 +125,12 @@ TEST(BootstrapTest, GeneratedDescriptorMatches) { importer.Import("google/protobuf/descriptor.proto"); const FileDescriptor* plugin_proto_file = importer.Import("google/protobuf/compiler/plugin.proto"); + const FileDescriptor* profile_proto_file = + importer.Import("google/protobuf/compiler/profile.proto"); EXPECT_EQ("", error_collector.text_); ASSERT_TRUE(proto_file != NULL); ASSERT_TRUE(plugin_proto_file != NULL); + ASSERT_TRUE(profile_proto_file != NULL); CppGenerator generator; MockGeneratorContext context; @@ -139,6 +141,8 @@ TEST(BootstrapTest, GeneratedDescriptorMatches) { parameter = "dllexport_decl=LIBPROTOC_EXPORT"; ASSERT_TRUE(generator.Generate(plugin_proto_file, parameter, &context, &error)); + ASSERT_TRUE(generator.Generate(profile_proto_file, parameter, + &context, &error)); context.ExpectFileMatches("google/protobuf/descriptor.pb.h", "google/protobuf/descriptor.pb.h"); @@ -148,6 +152,10 @@ TEST(BootstrapTest, GeneratedDescriptorMatches) { "google/protobuf/compiler/plugin.pb.h"); context.ExpectFileMatches("google/protobuf/compiler/plugin.pb.cc", "google/protobuf/compiler/plugin.pb.cc"); + context.ExpectFileMatches("google/protobuf/compiler/profile.pb.h", + "google/protobuf/compiler/profile.pb.h"); + context.ExpectFileMatches("google/protobuf/compiler/profile.pb.cc", + "google/protobuf/compiler/profile.pb.cc"); } } // namespace diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_enum_field.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_enum_field.cc index e4b17a98e4..c15be9427f 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_enum_field.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_enum_field.cc @@ -318,7 +318,7 @@ GenerateMergingCode(io::Printer* printer) const { void RepeatedEnumFieldGenerator:: GenerateSwappingCode(io::Printer* printer) const { - printer->Print(variables_, "$name$_.UnsafeArenaSwap(&other->$name$_);\n"); + printer->Print(variables_, "$name$_.InternalSwap(&other->$name$_);\n"); } void RepeatedEnumFieldGenerator:: @@ -461,20 +461,14 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { " target);\n" " target = ::google::protobuf::io::CodedOutputStream::WriteVarint32ToArray(" " _$name$_cached_byte_size_, target);\n" - "}\n"); - } - printer->Print(variables_, - "for (int i = 0, n = this->$name$_size(); i < n; i++) {\n"); - if (descriptor_->is_packed()) { - printer->Print(variables_, " target = ::google::protobuf::internal::WireFormatLite::WriteEnumNoTagToArray(\n" - " this->$name$(i), target);\n"); + " this->$name$_, target);\n" + "}\n"); } else { printer->Print(variables_, - " target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray(\n" - " $number$, this->$name$(i), target);\n"); + "target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray(\n" + " $number$, this->$name$_, target);\n"); } - printer->Print("}\n"); } void RepeatedEnumFieldGenerator:: diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_file.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_file.cc index f2e013c05e..e0542ae86d 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_file.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_file.cc @@ -39,6 +39,7 @@ #include #endif #include +#include #include #include @@ -67,7 +68,7 @@ bool IsMacroName(const string& name) { return false; } -void CollectMacroNames(const Descriptor* message, vector* names) { +void CollectMacroNames(const Descriptor* message, std::vector* names) { for (int i = 0; i < message->field_count(); ++i) { const FieldDescriptor* field = message->field(i); if (IsMacroName(field->name())) { @@ -79,7 +80,13 @@ void CollectMacroNames(const Descriptor* message, vector* names) { } } -void CollectMacroNames(const FileDescriptor* file, vector* names) { +void CollectMacroNames(const FileDescriptor* file, std::vector* names) { + // Only do this for protobuf's own types. There are some google3 protos using + // macros as field names and the generated code compiles after the macro + // expansion. Undefing these macros actually breaks such code. + if (file->name() != "google/protobuf/compiler/plugin.proto") { + return; + } for (int i = 0; i < file->message_type_count(); ++i) { CollectMacroNames(file->message_type(i), names); } @@ -93,18 +100,19 @@ void CollectMacroNames(const FileDescriptor* file, vector* names) { FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options) : file_(file), options_(options), + scc_analyzer_(options), message_generators_owner_( - new google::protobuf::scoped_ptr[ file->message_type_count() ]), + new google::protobuf::scoped_ptr[file->message_type_count()]), enum_generators_owner_( - new google::protobuf::scoped_ptr[ file->enum_type_count() ]), + new google::protobuf::scoped_ptr[file->enum_type_count()]), service_generators_owner_( - new google::protobuf::scoped_ptr[ file->service_count() ]), + new google::protobuf::scoped_ptr[file->service_count()]), extension_generators_owner_( - new google::protobuf::scoped_ptr[ file->extension_count() ]) { + new google::protobuf::scoped_ptr[file->extension_count()]) { for (int i = 0; i < file->message_type_count(); i++) { message_generators_owner_[i].reset( - new MessageGenerator(file->message_type(i), options)); + new MessageGenerator(file->message_type(i), options, &scc_analyzer_)); message_generators_owner_[i]->Flatten(&message_generators_); } @@ -137,7 +145,7 @@ FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options) FileGenerator::~FileGenerator() {} void FileGenerator::GenerateMacroUndefs(io::Printer* printer) { - vector names_to_undef; + std::vector names_to_undef; CollectMacroNames(file_, &names_to_undef); for (int i = 0; i < names_to_undef.size(); ++i) { printer->Print( @@ -241,6 +249,7 @@ void FileGenerator::GeneratePBHeader(io::Printer* printer, } else { GenerateLibraryIncludes(printer); } + GenerateDependencyIncludes(printer); GenerateMetadataPragma(printer, info_path); @@ -327,11 +336,17 @@ void FileGenerator::GenerateSource(io::Printer* printer) { GenerateNamespaceOpeners(printer); for (int i = 0; i < message_generators_.size(); i++) { - if (IsMapEntryMessage(message_generators_[i]->descriptor_)) continue; + string parent; + if (IsMapEntryMessage(message_generators_[i]->descriptor_)) { + parent = ClassName(message_generators_[i]->descriptor_->containing_type(), + false) + + "::"; + } printer->Print( "class $classname$DefaultTypeInternal : " - "public ::google::protobuf::internal::ExplicitlyConstructed<$classname$> {\n", - "classname", message_generators_[i]->classname_); + "public ::google::protobuf::internal::ExplicitlyConstructed<$parent$$classname$> " + "{\n", + "parent", parent, "classname", message_generators_[i]->classname_); printer->Indent(); message_generators_[i]->GenerateExtraDefaultFields(printer); printer->Outdent(); @@ -340,9 +355,6 @@ void FileGenerator::GenerateSource(io::Printer* printer) { "classname", message_generators_[i]->classname_); } - for (int i = 0; i < message_generators_.size(); i++) { - message_generators_[i]->index_in_metadata_ = i; - } for (int i = 0; i < enum_generators_.size(); i++) { enum_generators_[i]->index_in_metadata_ = i; } @@ -530,6 +542,70 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { // In optimize_for = LITE_RUNTIME mode, we don't generate AssignDescriptors() // and we only use AddDescriptors() to allocate default instances. + // TODO(ckennelly): Gate this with the same options flag to enable + // table-driven parsing. + + printer->Print("PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField\n" + " const TableStruct::entries[] = {\n"); + printer->Indent(); + + std::vector entries; + size_t count = 0; + for (int i = 0; i < message_generators_.size(); i++) { + size_t value = message_generators_[i]->GenerateParseOffsets(printer); + entries.push_back(value); + count += value; + } + + // We need these arrays to exist, and MSVC does not like empty arrays. + if (count == 0) { + printer->Print("{0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0},\n"); + } + + printer->Outdent(); + printer->Print( + "};\n" + "\n" + "PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField\n" + " const TableStruct::aux[] = {\n"); + printer->Indent(); + + std::vector aux_entries; + count = 0; + for (int i = 0; i < message_generators_.size(); i++) { + size_t value = message_generators_[i]->GenerateParseAuxTable(printer); + aux_entries.push_back(value); + count += value; + } + + if (count == 0) { + printer->Print("::google::protobuf::internal::AuxillaryParseTableField(),\n"); + } + + printer->Outdent(); + printer->Print( + "};\n" + "PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const\n" + " TableStruct::schema[] = {\n"); + printer->Indent(); + + size_t offset = 0; + size_t aux_offset = 0; + for (int i = 0; i < message_generators_.size(); i++) { + message_generators_[i]->GenerateParseTable(printer, offset, aux_offset); + offset += entries[i]; + aux_offset += aux_entries[i]; + } + + if (message_generators_.empty()) { + printer->Print("{ NULL, NULL, 0, -1, -1, false },\n"); + } + + printer->Outdent(); + printer->Print( + "};\n" + "\n"); + if (HasDescriptorMethods(file_, options_)) { if (!message_generators_.empty()) { printer->Print("const ::google::protobuf::uint32 TableStruct::offsets[] = {\n"); @@ -560,8 +636,6 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { printer->Indent(); for (int i = 0; i < message_generators_.size(); i++) { const Descriptor* descriptor = message_generators_[i]->descriptor_; - if (IsMapEntryMessage(descriptor)) continue; - printer->Print( "reinterpret_cast(&_$classname$_default_instance_),\n", @@ -600,7 +674,31 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { " AssignDescriptors(\n" " \"$filename$\", schemas, file_default_instances, " "TableStruct::offsets, factory,\n" - " $metadata$, $enum_descriptors$, $service_descriptors$);\n" + " $metadata$, $enum_descriptors$, $service_descriptors$);\n", + "filename", file_->name(), "metadata", + !message_generators_.empty() ? "file_level_metadata" : "NULL", + "enum_descriptors", + !enum_generators_.empty() ? "file_level_enum_descriptors" : "NULL", + "service_descriptors", + HasGenericServices(file_, options_) && file_->service_count() > 0 + ? "file_level_service_descriptors" + : "NULL", + "factory", message_factory); + // TODO(gerbens) have the compiler include the schemas for map types + // so that this can go away, and we can potentially use table driven + // serialization for map types as well. + for (int i = 0; i < message_generators_.size(); i++) { + if (!IsMapEntryMessage(message_generators_[i]->descriptor_)) continue; + printer->Print( + "file_level_metadata[$index$].reflection = " + "$parent$::$classname$::CreateReflection(file_level_metadata[$index$]" + ".descriptor, _$classname$_default_instance_.get_mutable());\n", + "index", SimpleItoa(i), "parent", + ClassName(message_generators_[i]->descriptor_->containing_type(), + false), + "classname", ClassName(message_generators_[i]->descriptor_, false)); + } + printer->Print( "}\n" "\n" "void protobuf_AssignDescriptorsOnce() {\n" @@ -634,12 +732,6 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { "size", SimpleItoa(message_generators_.size())); } - // Map types are treated special - // TODO(gerbens) find a way to treat maps more like normal messages. - for (int i = 0; i < message_generators_.size(); i++) { - message_generators_[i]->GenerateTypeRegistrations(printer); - } - printer->Outdent(); printer->Print( "}\n" @@ -659,6 +751,15 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { message_generators_[i]->GenerateShutdownCode(printer); } + if (HasDescriptorMethods(file_, options_)) { + for (int i = 0; i < message_generators_.size(); i++) { + if (!IsMapEntryMessage(message_generators_[i]->descriptor_)) continue; + printer->Print( + "delete file_level_metadata[$index$].reflection;\n", + "index", SimpleItoa(i)); + } + } + printer->Outdent(); printer->Print( "}\n\n"); @@ -902,8 +1003,16 @@ void FileGenerator::GenerateLibraryIncludes(io::Printer* printer) { "#include \n" "#include \n" "#include \n" - "#include \n" + "#include \n" + "#include \n"); + + if (HasDescriptorMethods(file_, options_)) { + printer->Print( "#include \n"); + } else { + printer->Print( + "#include \n"); + } if (!message_generators_.empty()) { if (HasDescriptorMethods(file_, options_)) { @@ -921,7 +1030,8 @@ void FileGenerator::GenerateLibraryIncludes(io::Printer* printer) { " // IWYU pragma: export\n"); if (HasMapFields(file_)) { printer->Print( - "#include \n"); + "#include " + " // IWYU pragma: export\n"); if (HasDescriptorMethods(file_, options_)) { printer->Print( "#include \n"); @@ -1001,6 +1111,9 @@ void FileGenerator::GenerateGlobalStateFunctionDeclarations( "namespace $file_namespace$ {\n" "// Internal implementation detail -- do not call these.\n" "struct $dllexport_decl$TableStruct {\n" + " static const ::google::protobuf::internal::ParseTableField entries[];\n" + " static const ::google::protobuf::internal::AuxillaryParseTableField aux[];\n" + " static const ::google::protobuf::internal::ParseTable schema[];\n" " static const ::google::protobuf::uint32 offsets[];\n" // The following function(s) need to be able to access private members of // the messages defined in the file. So we make them static members. diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_file.h b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_file.h index e3fbb96d23..e10fe2f3d0 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_file.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_file.h @@ -43,6 +43,7 @@ #include #include #include +#include #include namespace google { @@ -145,6 +146,8 @@ class FileGenerator { const FileDescriptor* file_; const Options options_; + SCCAnalyzer scc_analyzer_; + // Contains the post-order walk of all the messages (and child messages) in // this file. If you need a pre-order walk just reverse iterate. std::vector message_generators_; diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_generator.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_generator.cc index 648ab28a51..cee31224fc 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_generator.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_generator.cc @@ -98,6 +98,8 @@ bool CppGenerator::Generate(const FileDescriptor* file, file_options.annotation_guard_name = options[i].second; } else if (options[i].first == "lite") { file_options.enforce_lite = true; + } else if (options[i].first == "table_driven_parsing") { + file_options.table_driven_parsing = true; } else { *error = "Unknown generator option: " + options[i].first; return false; diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_helpers.cc index 3c4dddc590..9cddba5c20 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_helpers.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_helpers.cc @@ -654,6 +654,109 @@ void GenerateUtf8CheckCodeForCord(const FieldDescriptor* field, "VerifyUtf8Cord", "VerifyUTF8CordNamedField", printer); } +bool HasWeakFields(const Descriptor* descriptor) { + return false; +} + +bool HasWeakFields(const FileDescriptor* file) { + return false; +} + +SCCAnalyzer::NodeData SCCAnalyzer::DFS(const Descriptor* descriptor) { + // Must not have visited already. + GOOGLE_DCHECK_EQ(cache_.count(descriptor), 0); + + // Mark visited by inserting in map. + NodeData& result = cache_[descriptor]; + // Initialize data structures. + result.index = result.lowlink = index_++; + stack_.push_back(descriptor); + + // Recurse the fields / nodes in graph + for (int i = 0; i < descriptor->field_count(); i++) { + const Descriptor* child = descriptor->field(i)->message_type(); + if (child) { + if (cache_.count(child) == 0) { + // unexplored node + NodeData child_data = DFS(child); + result.lowlink = std::min(result.lowlink, child_data.lowlink); + } else { + NodeData child_data = cache_[child]; + if (child_data.scc == NULL) { + // Still in the stack_ so we found a back edge + result.lowlink = std::min(result.lowlink, child_data.index); + } + } + } + } + if (result.index == result.lowlink) { + // This is the root of a strongly connected component + SCC* scc = CreateSCC(); + while (true) { + const Descriptor* scc_desc = stack_.back(); + scc->descriptors.push_back(scc_desc); + // Remove from stack + stack_.pop_back(); + cache_[scc_desc].scc = scc; + + if (scc_desc == descriptor) break; + } + } + return result; +} + +MessageAnalysis SCCAnalyzer::GetSCCAnalysis(const SCC* scc) { + if (analysis_cache_.count(scc)) return analysis_cache_[scc]; + MessageAnalysis result = MessageAnalysis(); + for (int i = 0; i < scc->descriptors.size(); i++) { + const Descriptor* descriptor = scc->descriptors[i]; + if (descriptor->extension_range_count() > 0) { + result.contains_extension = true; + } + for (int i = 0; i < descriptor->field_count(); i++) { + const FieldDescriptor* field = descriptor->field(i); + if (field->is_required()) { + result.contains_required = true; + } + switch (field->type()) { + case FieldDescriptor::TYPE_STRING: + case FieldDescriptor::TYPE_BYTES: { + if (field->options().ctype() == FieldOptions::CORD) { + result.contains_cord = true; + } + break; + } + case FieldDescriptor::TYPE_GROUP: + case FieldDescriptor::TYPE_MESSAGE: { + const SCC* child = GetSCC(field->message_type()); + if (child != scc) { + MessageAnalysis analysis = GetSCCAnalysis(child); + result.contains_cord |= analysis.contains_cord; + result.contains_extension |= analysis.contains_extension; + if (!ShouldIgnoreRequiredFieldCheck(field, options_)) { + result.contains_required |= analysis.contains_required; + } + } else { + // This field points back into the same SCC hence the messages + // in the SCC are recursive. Note if SCC contains more than two + // nodes it has to be recursive, however this test also works for + // a single node that is recursive. + result.is_recursive = true; + } + break; + } + default: + break; + } + } + } + // We deliberately only insert the result here. After we contracted the SCC + // in the graph, the graph should be a DAG. Hence we shouldn't need to mark + // nodes visited as we can never return to them. By inserting them here + // we will go in an infinite loop if the SCC is not correct. + return analysis_cache_[scc] = result; +} + } // namespace cpp } // namespace compiler } // namespace protobuf diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_helpers.h b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_helpers.h index 0f297ec8b1..a744a8650e 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_helpers.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_helpers.h @@ -277,6 +277,73 @@ inline ::google::protobuf::FileOptions_OptimizeMode GetOptimizeFor( : file->options().optimize_for(); } +bool HasWeakFields(const Descriptor* desc); +bool HasWeakFields(const FileDescriptor* desc); + +// Returns true if the "required" restriction check should be ignored for the +// given field. +inline static bool ShouldIgnoreRequiredFieldCheck(const FieldDescriptor* field, + const Options& options) { + return false; +} + +struct SCC { + std::vector descriptors; +}; + +struct MessageAnalysis { + bool is_recursive; + bool contains_cord; + bool contains_extension; + bool contains_required; +}; + +// This class is used in FileGenerator, to ensure linear instead of +// quadratic performance, if we do this per message we would get O(V*(V+E)). +// Logically this is just only used in message.cc, but in the header for +// FileGenerator to help share it. +class LIBPROTOC_EXPORT SCCAnalyzer { + public: + explicit SCCAnalyzer(const Options& options) : options_(options), index_(0) {} + ~SCCAnalyzer() { + for (int i = 0; i < garbage_bin_.size(); i++) delete garbage_bin_[i]; + } + + const SCC* GetSCC(const Descriptor* descriptor) { + if (cache_.count(descriptor)) return cache_[descriptor].scc; + return DFS(descriptor).scc; + } + + MessageAnalysis GetSCCAnalysis(const SCC* scc); + + bool HasRequiredFields(const Descriptor* descriptor) { + MessageAnalysis result = GetSCCAnalysis(GetSCC(descriptor)); + return result.contains_required || result.contains_extension; + } + + private: + struct NodeData { + const SCC* scc; // if null it means its still on the stack + int index; + int lowlink; + }; + + Options options_; + std::map cache_; + std::map analysis_cache_; + std::vector stack_; + int index_; + std::vector garbage_bin_; + + SCC* CreateSCC() { + garbage_bin_.push_back(new SCC()); + return garbage_bin_.back(); + } + + // Tarjan's Strongly Connected Components algo + NodeData DFS(const Descriptor* descriptor); +}; + } // namespace cpp } // namespace compiler } // namespace protobuf diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_map_field.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_map_field.cc index b4eaf485d0..52a3b8b0df 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_map_field.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_map_field.cc @@ -32,6 +32,7 @@ #include #include #include + #include namespace google { @@ -113,18 +114,49 @@ MapFieldGenerator::~MapFieldGenerator() {} void MapFieldGenerator:: GeneratePrivateMembers(io::Printer* printer) const { + if (HasDescriptorMethods(descriptor_->file(), options_)) { + printer->Print( + variables_, + "public:\n" + "class $map_classname$ : public " + "::google::protobuf::internal::MapEntry<$map_classname$, \n" + " $key_cpp$, $val_cpp$,\n" + " $key_wire_type$,\n" + " $val_wire_type$,\n" + " $default_enum_value$ > {\n" + "public:\n" + " typedef ::google::protobuf::internal::MapEntry<$map_classname$, \n" + " $key_cpp$, $val_cpp$,\n" + " $key_wire_type$,\n" + " $val_wire_type$,\n" + " $default_enum_value$ > SuperType;\n" + " $map_classname$();\n" + " $map_classname$(::google::protobuf::Arena* arena);\n" + " void MergeFrom(const ::google::protobuf::Message& other) PROTOBUF_FINAL;\n" + " void MergeFrom(const $map_classname$& other);\n" + " static const Message* internal_default_instance() { return " + "reinterpret_cast(&_$map_classname$_default_instance_); }\n" + " ::google::protobuf::Metadata GetMetadata() const;\n" + "};\n"); + } else { + printer->Print(variables_, + "public:\n" + "typedef ::google::protobuf::internal::MapEntryLite<\n" + " $key_cpp$, $val_cpp$,\n" + " $key_wire_type$,\n" + " $val_wire_type$,\n" + " $default_enum_value$ >\n" + " $map_classname$;\n"); + } printer->Print(variables_, - "typedef ::google::protobuf::internal::MapEntryLite<\n" - " $key_cpp$, $val_cpp$,\n" - " $key_wire_type$,\n" - " $val_wire_type$,\n" - " $default_enum_value$ >\n" - " $map_classname$;\n" - "::google::protobuf::internal::MapField$lite$<\n" - " $key_cpp$, $val_cpp$,\n" - " $key_wire_type$,\n" - " $val_wire_type$,\n" - " $default_enum_value$ > $name$_;\n"); + "::google::protobuf::internal::MapField$lite$<\n" + " $map_classname$,\n" + " $key_cpp$, $val_cpp$,\n" + " $key_wire_type$,\n" + " $val_wire_type$,\n" + " $default_enum_value$ > $name$_;\n" + "private:\n"); } void MapFieldGenerator:: @@ -171,17 +203,6 @@ GenerateSwappingCode(io::Printer* printer) const { printer->Print(variables_, "$name$_.Swap(&other->$name$_);\n"); } -void MapFieldGenerator:: -GenerateConstructorCode(io::Printer* printer) const { - if (HasDescriptorMethods(descriptor_->file(), options_)) { - printer->Print(variables_, - "$name$_.SetAssignDescriptorCallback(\n" - " $file_namespace$::protobuf_AssignDescriptorsOnce);\n" - "$name$_.SetEntryDescriptor(\n" - " &$type$_descriptor);\n"); - } -} - void MapFieldGenerator:: GenerateCopyConstructorCode(io::Printer* printer) const { GenerateConstructorCode(printer); @@ -199,13 +220,15 @@ GenerateMergeFromCodedStream(io::Printer* printer) const { string value; if (IsProto3Field(descriptor_) || value_field->type() != FieldDescriptor::TYPE_ENUM) { - printer->Print(variables_, + printer->Print( + variables_, "$map_classname$::Parser< ::google::protobuf::internal::MapField$lite$<\n" - " $key_cpp$, $val_cpp$,\n" - " $key_wire_type$,\n" - " $val_wire_type$,\n" - " $default_enum_value$ >,\n" - " ::google::protobuf::Map< $key_cpp$, $val_cpp$ > >" + " $map_classname$,\n" + " $key_cpp$, $val_cpp$,\n" + " $key_wire_type$,\n" + " $val_wire_type$,\n" + " $default_enum_value$ >,\n" + " ::google::protobuf::Map< $key_cpp$, $val_cpp$ > >" " parser(&$name$_);\n" "DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(\n" " input, &parser));\n"); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_map_field.h b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_map_field.h index 816687b3a9..02e6649766 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_map_field.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_map_field.h @@ -54,7 +54,7 @@ class MapFieldGenerator : public FieldGenerator { void GenerateClearingCode(io::Printer* printer) const; void GenerateMergingCode(io::Printer* printer) const; void GenerateSwappingCode(io::Printer* printer) const; - void GenerateConstructorCode(io::Printer* printer) const; + void GenerateConstructorCode(io::Printer* printer) const {} void GenerateCopyConstructorCode(io::Printer* printer) const; void GenerateMergeFromCodedStream(io::Printer* printer) const; void GenerateSerializeWithCachedSizes(io::Printer* printer) const; diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_message.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_message.cc index 1373ffc2c1..d9524f649c 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_message.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_message.cc @@ -32,6 +32,8 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. +#include + #include #include #include @@ -41,16 +43,18 @@ #endif #include #include -#include -#include + #include #include +#include #include -#include -#include #include -#include +#include #include +#include +#include +#include +#include namespace google { @@ -103,54 +107,6 @@ struct ExtensionRangeSorter { } }; -// Returns true if the "required" restriction check should be ignored for the -// given field. -inline static bool ShouldIgnoreRequiredFieldCheck(const FieldDescriptor* field, - const Options& options) { - return false; -} - -// Returns true if the message type has any required fields. If it doesn't, -// we can optimize out calls to its IsInitialized() method. -// -// already_seen is used to avoid checking the same type multiple times -// (and also to protect against recursion). -static bool HasRequiredFields(const Descriptor* type, const Options& options, - hash_set* already_seen) { - if (already_seen->count(type) > 0) { - // Since the first occurrence of a required field causes the whole - // function to return true, we can assume that if the type is already - // in the cache it didn't have any required fields. - return false; - } - already_seen->insert(type); - - // If the type has extensions, an extension with message type could contain - // required fields, so we have to be conservative and assume such an - // extension exists. - if (type->extension_range_count() > 0) return true; - - for (int i = 0; i < type->field_count(); i++) { - const FieldDescriptor* field = type->field(i); - if (field->is_required()) { - return true; - } - if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && - !ShouldIgnoreRequiredFieldCheck(field, options)) { - if (HasRequiredFields(field->message_type(), options, already_seen)) { - return true; - } - } - } - - return false; -} - -static bool HasRequiredFields(const Descriptor* type, const Options& options) { - hash_set already_seen; - return HasRequiredFields(type, options, &already_seen); -} - // This returns an estimate of the compiler's alignment for the field. This // can't guarantee to be correct because the generated code could be compiled on // different systems with different alignment rules. The estimates below assume @@ -288,10 +244,13 @@ bool CanConstructByZeroing(const FieldDescriptor* field, // order, fields of similiar family (see below) are together and within each // family, alignment padding is minimized. // -// We try to do this while keeping each field as close as possible to its -// declaration order (from the .proto file) so that we don't reduce cache -// locality much for function that access each field in order. This is also the -// only (weak) signal we have for author intent concerning field layout. +// We try to do this while keeping each field as close as possible to its field +// number order so that we don't reduce cache locality much for function that +// access each field in order. Originally, OptimizePadding used declaration +// order for its decisions, but generated code minus the serializer/parsers uses +// the output of OptimizePadding as well (stored in +// MessageGenerator::optimized_order_). Since the serializers use field number +// order, we use that as a tie-breaker. // // TODO(ckennelly): If/when we have profiles available for the compiler, use // those rather than respect declaration order. @@ -346,10 +305,11 @@ void OptimizePadding(std::vector* fields, f = ZERO_INITIALIZABLE; } + const int j = field->number(); switch (EstimateAlignmentSize(field)) { - case 1: aligned_to_1[f].push_back(FieldGroup(i, field)); break; - case 4: aligned_to_4[f].push_back(FieldGroup(i, field)); break; - case 8: aligned_to_8[f].push_back(FieldGroup(i, field)); break; + case 1: aligned_to_1[f].push_back(FieldGroup(j, field)); break; + case 4: aligned_to_4[f].push_back(FieldGroup(j, field)); break; + case 8: aligned_to_8[f].push_back(FieldGroup(j, field)); break; default: GOOGLE_LOG(FATAL) << "Unknown alignment size."; } @@ -366,7 +326,7 @@ void OptimizePadding(std::vector* fields, } aligned_to_4[f].push_back(field_group); } - // Sort by preferred location to keep fields as close to their declaration + // Sort by preferred location to keep fields as close to their field number // order as possible. Using stable_sort ensures that the output is // consistent across runs. std::stable_sort(aligned_to_4[f].begin(), aligned_to_4[f].end()); @@ -406,9 +366,6 @@ void OptimizePadding(std::vector* fields, } } -string MessageTypeProtoName(const FieldDescriptor* field) { - return field->message_type()->full_name(); -} // Emits an if-statement with a condition that evaluates to true if |field| is // considered non-default (will be sent over the wire), for message types @@ -495,30 +452,99 @@ bool HasPrivateHasMethod(const FieldDescriptor* field) { } +bool TableDrivenEnabled(const Descriptor* descriptor, const Options& options) { + if (!options.table_driven_parsing) { + return false; + } + + // Consider table-driven parsing. We only do this if: + // - There are no extensions + if (descriptor->extension_range_count() != 0) { + return false; + } + + // - We are not using UnknownFieldSet (part of the non-lite library). + if (UseUnknownFieldSet(descriptor->file(), options)) { + return false; + } + + // - We have has_bits for fields. This avoids a check on every field we set + // when are present (the common case). + if (!HasFieldPresence(descriptor->file())) { + return false; + } + + const double table_sparseness = 0.5; + int max_field_number = 0; + for (int i = 0; i < descriptor->field_count(); i++) { + const FieldDescriptor* field = descriptor->field(i); + if (max_field_number < field->number()) { + max_field_number = field->number(); + } + + // - There are no map fields. + if (field->is_map()) { + return false; + } + + // - There are no oneof fields. + if (field->containing_oneof()) { + return false; + } + + // - There are no weak fields. + if (field->options().weak()) { + return false; + } + } + + // - There range of field numbers is "small" + if (max_field_number >= (2 << 14)) { + return false; + } + + // - Field numbers are relatively dense within the actual number of fields + if (max_field_number * table_sparseness >= descriptor->field_count()) { + return false; + } + + // - This is not a MapEntryMessage. + if (IsMapEntryMessage(descriptor)) { + return false; + } + + return true; +} + } // anonymous namespace // =================================================================== MessageGenerator::MessageGenerator(const Descriptor* descriptor, - const Options& options) + const Options& options, + SCCAnalyzer* scc_analyzer) : descriptor_(descriptor), classname_(ClassName(descriptor, false)), options_(options), field_generators_(descriptor, options), max_has_bit_index_(0), nested_generators_(new google::protobuf::scoped_ptr< - MessageGenerator>[descriptor->nested_type_count()]), + MessageGenerator>[descriptor->nested_type_count()]), enum_generators_( new google::protobuf::scoped_ptr[descriptor->enum_type_count()]), extension_generators_(new google::protobuf::scoped_ptr< - ExtensionGenerator>[descriptor->extension_count()]), - use_dependent_base_(false) { - + ExtensionGenerator>[descriptor->extension_count()]), + use_dependent_base_(false), + num_weak_fields_(0), + scc_analyzer_(scc_analyzer) { // Compute optimized field order to be used for layout and initialization // purposes. for (int i = 0; i < descriptor_->field_count(); i++) { - if (!descriptor_->field(i)->containing_oneof()) { - optimized_order_.push_back(descriptor_->field(i)); + const FieldDescriptor* field = descriptor_->field(i); + if (field->options().weak()) { + num_weak_fields_++; + } else if (!field->containing_oneof()) { + optimized_order_.push_back(field); } } OptimizePadding(&optimized_order_, options_); @@ -538,8 +564,8 @@ MessageGenerator::MessageGenerator(const Descriptor* descriptor, } for (int i = 0; i < descriptor->nested_type_count(); i++) { - nested_generators_[i].reset( - new MessageGenerator(descriptor->nested_type(i), options)); + nested_generators_[i].reset(new MessageGenerator(descriptor->nested_type(i), + options, scc_analyzer)); } for (int i = 0; i < descriptor->enum_type_count(); i++) { @@ -565,6 +591,8 @@ MessageGenerator::MessageGenerator(const Descriptor* descriptor, // Always make oneofs dependent. use_dependent_base_ = true; } + + table_driven_ = TableDrivenEnabled(descriptor_, options_); } MessageGenerator::~MessageGenerator() {} @@ -586,6 +614,7 @@ void MessageGenerator::Flatten(std::vector* list) { for (int i = 0; i < descriptor_->nested_type_count(); i++) { nested_generators_[i]->Flatten(list); } + index_in_file_messages_ = list->size(); list->push_back(this); } @@ -602,7 +631,6 @@ void MessageGenerator::AddGenerators( void MessageGenerator::FillMessageForwardDeclarations( std::map* class_names) { - if (IsMapEntryMessage(descriptor_)) return; (*class_names)[classname_] = descriptor_; } @@ -644,7 +672,7 @@ GenerateFieldAccessorDeclarations(io::Printer* printer) { ordered_fields.begin(), optimized_order_.begin(), optimized_order_.end()); for (int i = 0; i < descriptor_->field_count(); i++) { const FieldDescriptor* field = descriptor_->field(i); - if (field->containing_oneof() == NULL) { + if (field->containing_oneof() == NULL && !field->options().weak()) { continue; } ordered_fields.push_back(field); @@ -777,6 +805,15 @@ void MessageGenerator:: GenerateSingularFieldHasBits(const FieldDescriptor* field, std::map vars, io::Printer* printer) { + if (field->options().weak()) { + printer->Print( + vars, + "$inline$" + "bool $classname$::has_$name$() const {\n" + " return _weak_field_map_.Has($number$);\n" + "}\n"); + return; + } if (HasFieldPresence(descriptor_->file())) { // N.B.: without field presence, we do not use has-bits or generate // has_$name$() methods. @@ -896,7 +933,7 @@ GenerateFieldClear(const FieldDescriptor* field, field_generators_.get(field) .GenerateClearingCode(printer); if (HasFieldPresence(descriptor_->file())) { - if (!field->is_repeated()) { + if (!field->is_repeated() && !field->options().weak()) { printer->Print(vars, "$this_message$clear_has_$name$();\n"); } @@ -1049,6 +1086,29 @@ GenerateClassDefinition(io::Printer* printer) { "}\n" "\n"); + // Generate move constructor and move assignment operator for types other than + // Any. + #ifdef PROTO_EXPERIMENTAL_ENABLE_MOVE + if (!IsAnyMessage(descriptor_)) { + printer->Print(vars, + "#if LANG_CXX11\n" + "$classname$($classname$&& from)\n" + " : $classname$() {\n" + " *this = ::std::move(from);\n" + "}\n" + "\n" + "inline $classname$& operator=($classname$&& from) {\n" + " if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {\n" + " InternalSwap(&from);\n" + " } else {\n" + " CopyFrom(from);\n" + " }\n" + " return *this;\n" + "}\n" + "#endif\n"); + } + #endif + if (PreserveUnknownFields(descriptor_)) { string type = UseUnknownFieldSet(descriptor_->file(), options_) ? "::google::protobuf::UnknownFieldSet" @@ -1119,12 +1179,15 @@ GenerateClassDefinition(io::Printer* printer) { } // TODO(gerbens) make this private, while still granting other protos access. + vars["message_index"] = SimpleItoa(index_in_file_messages_); printer->Print( vars, "static inline const $classname$* internal_default_instance() {\n" " return reinterpret_cast(\n" " &_$classname$_default_instance_);\n" "}\n" + "static PROTOBUF_CONSTEXPR int const kIndexInFileMessages =\n" + " $message_index$;\n" "\n"); @@ -1199,14 +1262,8 @@ GenerateClassDefinition(io::Printer* printer) { } if (HasFastArraySerialization(descriptor_->file(), options_)) { printer->Print( - "::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(\n" - " bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;\n" - "::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)\n" - " const PROTOBUF_FINAL {\n" - " return InternalSerializeWithCachedSizesToArray(\n" - " ::google::protobuf::io::CodedOutputStream::" - "IsDefaultSerializationDeterministic(), output);\n" - "}\n"); + "::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(\n" + " bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;\n"); } } @@ -1312,7 +1369,8 @@ GenerateClassDefinition(io::Printer* printer) { for (int i = 0; i < descriptor_->field_count(); i++) { - if (!descriptor_->field(i)->is_repeated()) { + if (!descriptor_->field(i)->is_repeated() && + !descriptor_->field(i)->options().weak()) { // set_has_***() generated in all proto1/2 code and in oneofs (only) for // messages without true field presence. if (HasFieldPresence(descriptor_->file()) || @@ -1451,6 +1509,10 @@ GenerateClassDefinition(io::Printer* printer) { "\n"); } + if (num_weak_fields_) { + printer->Print( + "::google::protobuf::internal::WeakFieldMap _weak_field_map_;\n"); + } // Generate _any_metadata_ for the Any type. if (IsAnyMessage(descriptor_)) { printer->Print(vars, @@ -1459,6 +1521,7 @@ GenerateClassDefinition(io::Printer* printer) { // The TableStruct struct needs access to the private parts, in order to // construct the offsets of all members. + // // Some InitDefault and Shutdown are defined as static member functions of // TableStruct such that they are also allowed to access private members. printer->Print( @@ -1511,8 +1574,9 @@ GenerateInlineMethods(io::Printer* printer, bool is_inline) { void MessageGenerator:: GenerateExtraDefaultFields(io::Printer* printer) { - // Generate oneof default instance for reflection usage. - if (descriptor_->oneof_decl_count() > 0) { + // Generate oneof default instance and weak field instances for reflection + // usage. + if (descriptor_->oneof_decl_count() > 0 || num_weak_fields_ > 0) { printer->Print("public:\n"); for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) { @@ -1525,9 +1589,71 @@ GenerateExtraDefaultFields(io::Printer* printer) { field_generators_.get(field).GeneratePrivateMembers(printer); } } + for (int i = 0; i < descriptor_->field_count(); i++) { + const FieldDescriptor* field = descriptor_->field(i); + if (field->options().weak()) { + printer->Print( + " const ::google::protobuf::Message* $name$_;\n", "name", FieldName(field)); + } + } } } +bool MessageGenerator::GenerateParseTable(io::Printer* printer, size_t offset, + size_t aux_offset) { + if (!table_driven_) { + printer->Print("{ NULL, NULL, 0, -1, -1, false },\n"); + return false; + } + + std::map vars; + + vars["classname"] = classname_; + vars["offset"] = SimpleItoa(offset); + vars["aux_offset"] = SimpleItoa(aux_offset); + + int max_field_number = 0; + for (int i = 0; i < descriptor_->field_count(); i++) { + const FieldDescriptor* field = descriptor_->field(i); + if (max_field_number < field->number()) { + max_field_number = field->number(); + } + } + + vars["max_field_number"] = SimpleItoa(max_field_number); + + printer->Print("{\n"); + printer->Indent(); + + printer->Print(vars, + "TableStruct::entries + $offset$,\n" + "TableStruct::aux + $aux_offset$,\n" + "$max_field_number$,\n"); + + if (!HasFieldPresence(descriptor_->file())) { + // If we don't have field presence, then _has_bits_ does not exist. + printer->Print(vars, "-1,\n"); + } else { + printer->Print(vars, + "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(\n" + " $classname$, _has_bits_),\n"); + } + + printer->Print(vars, + "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(\n" + " $classname$, _internal_metadata_),\n"); + + if (UseUnknownFieldSet(descriptor_->file(), options_)) { + printer->Print(vars, "true,\n"); + } else { + printer->Print(vars, "false,\n"); + } + + printer->Outdent(); + printer->Print("},\n"); + return true; +} + void MessageGenerator::GenerateSchema(io::Printer* printer, int offset, int has_offset) { if (IsMapEntryMessage(descriptor_)) return; @@ -1544,47 +1670,8 @@ void MessageGenerator::GenerateSchema(io::Printer* printer, int offset, "{ $offset$, $has_bits_offsets$, sizeof($classname$)},\n"); } -void MessageGenerator:: -GenerateTypeRegistrations(io::Printer* printer) { - // Register this message type with the message factory. - if (IsMapEntryMessage(descriptor_)) { - std::map vars; - CollectMapInfo(descriptor_, &vars); - vars["classname"] = classname_; - vars["file_namespace"] = FileLevelNamespace(descriptor_->file()->name()); - - const FieldDescriptor* val = descriptor_->FindFieldByName("value"); - if (descriptor_->file()->syntax() == FileDescriptor::SYNTAX_PROTO2 && - val->type() == FieldDescriptor::TYPE_ENUM) { - const EnumValueDescriptor* default_value = val->default_value_enum(); - vars["default_enum_value"] = Int32ToString(default_value->number()); - } else { - vars["default_enum_value"] = "0"; - } - - vars["index_in_metadata"] = SimpleItoa(index_in_metadata_); - - printer->Print( - vars, - "const ::google::protobuf::Descriptor* $classname$_descriptor = " - "$file_namespace$::file_level_metadata[$index_in_metadata$].descriptor;" - "\n" - "::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(\n" - " $classname$_descriptor,\n" - " ::google::protobuf::internal::MapEntry<\n" - " $key$,\n" - " $val$,\n" - " $key_wire_type$,\n" - " $val_wire_type$,\n" - " $default_enum_value$>::CreateDefaultInstance(\n" - " $classname$_descriptor));\n"); - } -} - void MessageGenerator:: GenerateDefaultInstanceAllocator(io::Printer* printer) { - if (IsMapEntryMessage(descriptor_)) return; - // Construct the default instances of all fields, as they will be used // when creating the default instance of the entire message. for (int i = 0; i < descriptor_->field_count(); i++) { @@ -1601,7 +1688,15 @@ GenerateDefaultInstanceAllocator(io::Printer* printer) { void MessageGenerator:: GenerateDefaultInstanceInitializer(io::Printer* printer) { - if (IsMapEntryMessage(descriptor_)) return; + if (IsMapEntryMessage(descriptor_)) { + printer->Print( + "_$classname$_default_instance_.get_mutable()->set_default_instance(_$" + "classname$_default_instance_.get_mutable());\n" + "_$classname$_default_instance_.get_mutable()->InitAsDefaultInstance();" + "\n", + "classname", classname_); + return; + } // The default instance needs all of its embedded message pointers // cross-linked to other default instances. We can't do this initialization @@ -1617,7 +1712,7 @@ GenerateDefaultInstanceInitializer(io::Printer* printer) { (field->containing_oneof() == NULL || HasDescriptorMethods(descriptor_->file(), options_))) { string name; - if (field->containing_oneof()) { + if (field->containing_oneof() || field->options().weak()) { name = "_" + classname_ + "_default_instance_."; } else { name = "_" + classname_ + "_default_instance_.get_mutable()->"; @@ -1645,7 +1740,7 @@ GenerateShutdownCode(io::Printer* printer) { if (HasDescriptorMethods(descriptor_->file(), options_)) { printer->Print("delete file_level_metadata[$index$].reflection;\n", "index", - SimpleItoa(index_in_metadata_)); + SimpleItoa(index_in_file_messages_)); } // Handle default instances of fields. @@ -1657,7 +1752,31 @@ GenerateShutdownCode(io::Printer* printer) { void MessageGenerator:: GenerateClassMethods(io::Printer* printer) { - if (IsMapEntryMessage(descriptor_)) return; + if (IsMapEntryMessage(descriptor_)) { + if (HasDescriptorMethods(descriptor_->file(), options_)) { + printer->Print( + "$parent$::$classname$::$classname$() {}\n" + "$parent$::$classname$::$classname$(::google::protobuf::Arena* arena) : " + "SuperType(arena) {}\n" + "::google::protobuf::Metadata $parent$::$classname$::GetMetadata() const {\n" + " $file_namespace$::protobuf_AssignDescriptorsOnce();\n" + " return $file_namespace$::file_level_metadata[$index$];\n" + "}\n" + "void $parent$::$classname$::MergeFrom(\n" + " const ::google::protobuf::Message& other) {\n" + " ::google::protobuf::Message::MergeFrom(other);\n" + "}\n" + "void $parent$::$classname$::MergeFrom(const $classname$& other) {\n" + " MergeFromInternal(other);\n" + "}\n" + "\n", + "file_namespace", FileLevelNamespace(descriptor_->file()->name()), + "parent", ClassName(descriptor_->containing_type(), false), + "classname", classname_, "index", + SimpleItoa(index_in_file_messages_)); + } + return; + } if (IsAnyMessage(descriptor_)) { printer->Print( @@ -1739,11 +1858,12 @@ GenerateClassMethods(io::Printer* printer) { printer->Print( "::google::protobuf::Metadata $classname$::GetMetadata() const {\n" " $file_namespace$::protobuf_AssignDescriptorsOnce();\n" - " return $file_namespace$::file_level_metadata[$index$];\n" + " return " + "$file_namespace$::file_level_metadata[kIndexInFileMessages];\n" "}\n" "\n", - "classname", classname_, "index", SimpleItoa(index_in_metadata_), - "file_namespace", FileLevelNamespace(descriptor_->file()->name())); + "classname", classname_, "file_namespace", + FileLevelNamespace(descriptor_->file()->name())); } else { printer->Print( "::std::string $classname$::GetTypeName() const {\n" @@ -1756,6 +1876,185 @@ GenerateClassMethods(io::Printer* printer) { } +size_t MessageGenerator::GenerateParseOffsets(io::Printer* printer) { + if (!table_driven_) { + return 0; + } + + // Field "0" is special: We use it in our switch statement of processing + // types to handle the successful end tag case. + printer->Print("{0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0},\n"); + int last_field_number = 1; + + std::vector ordered_fields = + SortFieldsByNumber(descriptor_); + + for (int i = 0; i < descriptor_->field_count(); i++) { + const FieldDescriptor* field = ordered_fields[i]; + GOOGLE_CHECK_GE(field->number(), last_field_number); + + for (; last_field_number < field->number(); last_field_number++) { + printer->Print( + "{ 0, 0, ::google::protobuf::internal::kInvalidMask,\n" + " ::google::protobuf::internal::kInvalidMask, 0, 0 },\n"); + } + last_field_number++; + + unsigned char normal_wiretype, packed_wiretype, processing_type; + normal_wiretype = WireFormat::WireTypeForFieldType(field->type()); + + if (field->is_packable()) { + packed_wiretype = WireFormatLite::WIRETYPE_LENGTH_DELIMITED; + } else { + packed_wiretype = internal::kNotPackedMask; + } + + processing_type = static_cast(field->type()); + if (field->type() == FieldDescriptor::TYPE_STRING) { + switch (EffectiveStringCType(field)) { + case FieldOptions::STRING: + default: + break; + } + } else if (field->type() == FieldDescriptor::TYPE_BYTES) { + switch (EffectiveStringCType(field)) { + case FieldOptions::STRING: + default: + break; + } + } + + processing_type |= static_cast( + field->is_repeated() ? internal::kRepeatedMask : 0); + const unsigned char tag_size = + WireFormat::TagSize(field->number(), field->type()); + + std::map vars; + vars["classname"] = classname_; + vars["name"] = FieldName(field); + vars["has"] = SimpleItoa(has_bit_indices_[field->index()]); + vars["nwtype"] = SimpleItoa(normal_wiretype); + vars["pwtype"] = SimpleItoa(packed_wiretype); + vars["ptype"] = SimpleItoa(processing_type); + vars["tag_size"] = SimpleItoa(tag_size); + + printer->Print(vars, + "{\n" + " GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(\n" + " $classname$, $name$_),\n" + " static_cast< ::google::protobuf::uint32>($has$),\n" + " $nwtype$, $pwtype$, $ptype$, $tag_size$\n" + "},\n"); + } + + return last_field_number; +} + +size_t MessageGenerator::GenerateParseAuxTable(io::Printer* printer) { + if (!table_driven_) { + return 0; + } + + std::vector ordered_fields = + SortFieldsByNumber(descriptor_); + + printer->Print("::google::protobuf::internal::AuxillaryParseTableField(),\n"); + int last_field_number = 1; + for (int i = 0; i < descriptor_->field_count(); i++) { + const FieldDescriptor* field = ordered_fields[i]; + + GOOGLE_CHECK_GE(field->number(), last_field_number); + for (; last_field_number < field->number(); last_field_number++) { + printer->Print("::google::protobuf::internal::AuxillaryParseTableField(),\n"); + } + + std::map vars; + SetCommonFieldVariables(field, &vars, options_); + + switch (field->cpp_type()) { + case FieldDescriptor::CPPTYPE_ENUM: + vars["type"] = ClassName(field->enum_type(), true); + printer->Print( + vars, + "{::google::protobuf::internal::AuxillaryParseTableField::enum_aux{" + "$type$_IsValid, \"$type$\" }},\n"); + last_field_number++; + break; + case FieldDescriptor::CPPTYPE_MESSAGE: { + std::vector package_parts; + + const Descriptor* outer = field->message_type(); + while (outer->containing_type() != NULL) { + outer = outer->containing_type(); + } + + package_parts = Split( + outer->full_name(), ".", true); + // outer->full_name() contains the class itself. Remove it as it is + // used in the name of the default instance variable. + GOOGLE_DCHECK_NE(package_parts.size(), 0); + package_parts.back().clear(); + + vars["classname"] = ClassName(field->message_type(), false); + vars["ns"] = Join(package_parts, "::"); + vars["type"] = FieldMessageTypeName(field); + vars["file_namespace"] = FileLevelNamespace(outer->file()->name()); + + printer->Print(vars, + "{::google::protobuf::internal::AuxillaryParseTableField::message_aux{\n" + " &::$ns$_$classname$_default_instance_,\n"); + + bool dont_emit_table = + !TableDrivenEnabled(field->message_type(), options_); + + if (dont_emit_table) { + printer->Print(" NULL,\n"); + } else { + printer->Print(vars, + " ::$ns$$file_namespace$::TableStruct::schema +\n" + " ::$ns$$classname$::kIndexInFileMessages,\n"); + } + + printer->Print("}},\n"); + last_field_number++; + break; + } + case FieldDescriptor::CPPTYPE_STRING: + switch (EffectiveStringCType(field)) { + case FieldOptions::STRING: + vars["default"] = + field->default_value_string().empty() + ? "&::google::protobuf::internal::fixed_address_empty_string" + : "&" + classname_ + "::_default_" + FieldName(field) + "_"; + break; + case FieldOptions::CORD: + case FieldOptions::STRING_PIECE: + vars["default"] = + "\"" + CEscape(field->default_value_string()) + "\""; + break; + } + vars["full_name"] = field->full_name(); + vars["strict"] = + field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 + ? "true" : "false"; + vars["type"] = field->full_name(); + printer->Print(vars, + "{::google::protobuf::internal::AuxillaryParseTableField::string_aux{\n" + " $default$,\n" + " \"$full_name$\",\n" + " $strict$,\n" + " \"$type$\"\n" + "}},\n"); + last_field_number++; + break; + default: + break; + } + } + + return last_field_number; +} + std::pair MessageGenerator::GenerateOffsets( io::Printer* printer) { if (IsMapEntryMessage(descriptor_)) return std::make_pair(0, 0); @@ -1765,7 +2064,8 @@ std::pair MessageGenerator::GenerateOffsets( if (HasFieldPresence(descriptor_->file())) { printer->Print( variables, - "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, _has_bits_),\n"); + "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, " + "_has_bits_),\n"); } else { printer->Print("~0u, // no _has_bits_\n"); } @@ -1775,34 +2075,41 @@ std::pair MessageGenerator::GenerateOffsets( if (descriptor_->extension_range_count() > 0) { printer->Print( variables, - "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, _extensions_),\n"); + "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, " + "_extensions_),\n"); } else { printer->Print("~0u, // no _extensions_\n"); } if (descriptor_->oneof_decl_count() > 0) { printer->Print(variables, - "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, " - "_oneof_case_[0]),\n"); + "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(" + "$classname$, _oneof_case_[0]),\n"); } else { printer->Print("~0u, // no _oneof_case_\n"); } - - const int kNumGenericOffsets = 4; // the number of fixed offsets above + if (num_weak_fields_ > 0) { + printer->Print(variables, + "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$," + " _weak_field_map_),\n"); + } else { + printer->Print("~0u, // no _weak_field_map_\n"); + } + const int kNumGenericOffsets = 5; // the number of fixed offsets above const size_t offsets = kNumGenericOffsets + descriptor_->field_count() + descriptor_->oneof_decl_count(); size_t entries = offsets; for (int i = 0; i < descriptor_->field_count(); i++) { const FieldDescriptor* field = descriptor_->field(i); - if (field->containing_oneof()) { + if (field->containing_oneof() || field->options().weak()) { printer->Print( - "PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET(" + "GOOGLE_PROTOBUF_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET(" "(&_$classname$_default_instance_), $name$_),\n", "classname", classname_, "name", FieldName(field)); } else { printer->Print( "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, " - "$name$_),\n", + "$name$_),\n", "classname", classname_, "name", FieldName(field)); } @@ -1844,19 +2151,6 @@ GenerateSharedConstructorCode(io::Printer* printer) { need_to_clear_cached_size = false; } - // TODO(gerbens) Clean this hack, and why do i need a reference to a pointer?? - for (int i = 0; i < descriptor_->nested_type_count(); i++) { - if (HasDescriptorMethods(descriptor_->file(), options_) && - IsMapEntryMessage(descriptor_->nested_type(i))) { - printer->Print( - "const ::google::protobuf::Descriptor*& $type$_descriptor = " - "$file_namespace$::file_level_metadata[$index$].descriptor;\n", - "type", ClassName(descriptor_->nested_type(i), false), "index", - SimpleItoa(nested_generators_[i]->index_in_metadata_), - "file_namespace", FileLevelNamespace(descriptor_->file()->name())); - } - } - std::vector processed(optimized_order_.size(), false); GenerateConstructorBody(printer, processed, false); @@ -1906,6 +2200,9 @@ GenerateSharedDestructorCode(io::Printer* printer) { "oneof_name", descriptor_->oneof_decl(i)->name()); } + if (num_weak_fields_) { + printer->Print("_weak_field_map_.ClearAll();\n"); + } printer->Outdent(); printer->Print( "}\n" @@ -1956,6 +2253,12 @@ GenerateArenaDestructorCode(io::Printer* printer) { } } } + if (num_weak_fields_) { + // _this is the object being destructed (we are inside a static method + // here). + printer->Print("_this->_weak_field_map_.ClearAll();\n"); + need_registration = true; + } printer->Outdent(); printer->Print( @@ -2077,12 +2380,18 @@ GenerateStructors(io::Printer* printer) { if (IsAnyMessage(descriptor_)) { initializer_with_arena += ",\n _any_metadata_(&type_url_, &value_)"; } + if (num_weak_fields_ > 0) { + initializer_with_arena += ", _weak_field_map_(arena)"; + } string initializer_null; initializer_null = ", _internal_metadata_(NULL)"; if (IsAnyMessage(descriptor_)) { initializer_null += ", _any_metadata_(&type_url_, &value_)"; } + if (num_weak_fields_ > 0) { + initializer_null += ", _weak_field_map_(NULL)"; + } printer->Print( "$classname$::$classname$()\n" @@ -2165,6 +2474,9 @@ GenerateStructors(io::Printer* printer) { if (IsAnyMessage(descriptor_)) { printer->Print(",\n_any_metadata_(&type_url_, &value_)"); } + if (num_weak_fields_ > 0) { + printer->Print(",\n_weak_field_map_(from._weak_field_map_)"); + } printer->Outdent(); printer->Outdent(); @@ -2177,19 +2489,6 @@ GenerateStructors(io::Printer* printer) { printer->Print("_extensions_.MergeFrom(from._extensions_);\n"); } - // TODO(gerbens) Clean this hack, and why do i need a reference to a pointer?? - for (int i = 0; i < descriptor_->nested_type_count(); i++) { - if (HasDescriptorMethods(descriptor_->file(), options_) && - IsMapEntryMessage(descriptor_->nested_type(i))) { - printer->Print( - "const ::google::protobuf::Descriptor*& $type$_descriptor = " - "$file_namespace$::file_level_metadata[$index$].descriptor;\n", - "type", ClassName(descriptor_->nested_type(i), false), "index", - SimpleItoa(nested_generators_[i]->index_in_metadata_), - "file_namespace", FileLevelNamespace(descriptor_->file()->name())); - } - } - GenerateConstructorBody(printer, processed, true); // Copy oneof fields. Oneof field requires oneof case check. @@ -2268,11 +2567,13 @@ GenerateStructors(io::Printer* printer) { printer->Print( "const ::google::protobuf::Descriptor* $classname$::descriptor() {\n" " $file_namespace$::protobuf_AssignDescriptorsOnce();\n" - " return $file_namespace$::file_level_metadata[$index$].descriptor;\n" + " return " + "$file_namespace$::file_level_metadata[kIndexInFileMessages]." + "descriptor;\n" "}\n" "\n", - "index", SimpleItoa(index_in_metadata_), "classname", classname_, - "file_namespace", FileLevelNamespace(descriptor_->file()->name())); + "classname", classname_, "file_namespace", + FileLevelNamespace(descriptor_->file()->name())); } printer->Print( @@ -2504,6 +2805,10 @@ GenerateClear(io::Printer* printer) { "oneof_name", descriptor_->oneof_decl(i)->name()); } + if (num_weak_fields_) { + printer->Print("_weak_field_map_.ClearAll();\n"); + } + if (HasFieldPresence(descriptor_->file())) { // Step 5: Everything else. printer->Print("_has_bits_.Clear();\n"); @@ -2647,6 +2952,10 @@ GenerateSwap(io::Printer* printer) { if (descriptor_->extension_range_count() > 0) { printer->Print("_extensions_.Swap(&other->_extensions_);\n"); } + if (num_weak_fields_) { + printer->Print( + "_weak_field_map_.UnsafeArenaSwap(&other->_weak_field_map_);\n"); + } } else { printer->Print("GetReflection()->Swap(this, other);"); } @@ -2714,7 +3023,14 @@ GenerateMergeFrom(io::Printer* printer) { } printer->Print( - "_internal_metadata_.MergeFrom(from._internal_metadata_);\n"); + "_internal_metadata_.MergeFrom(from._internal_metadata_);\n" + "::google::protobuf::uint32 cached_has_bits = 0;\n" + "(void) cached_has_bits;\n\n"); + + // cached_has_bit_index maintains that: + // cached_has_bits = from._has_bits_[cached_has_bit_index] + // for cached_has_bit_index >= 0 + int cached_has_bit_index = -1; int last_i = -1; for (int i = 0; i < optimized_order_.size(); ) { @@ -2734,7 +3050,7 @@ GenerateMergeFrom(io::Printer* printer) { generator.GenerateMergingCode(printer); } - // Merge Optional and Required fields (after a _has_bit check). + // Merge Optional and Required fields (after a _has_bit_ check). int last_chunk = -1; int last_chunk_start = -1; int last_chunk_end = -1; @@ -2779,23 +3095,43 @@ GenerateMergeFrom(io::Printer* printer) { GOOGLE_DCHECK_LE(2, count); GOOGLE_DCHECK_GE(8, count); + if (cached_has_bit_index != last_chunk / 4) { + int new_index = last_chunk / 4; + printer->Print("cached_has_bits = from._has_bits_[$new_index$];\n", + "new_index", SimpleItoa(new_index)); + cached_has_bit_index = new_index; + } + printer->Print( - "if (from._has_bits_[$index$ / 32] & $mask$u) {\n", - "index", SimpleItoa(last_chunk * 8), + "if (cached_has_bits & $mask$u) {\n", "mask", SimpleItoa(last_chunk_mask)); printer->Indent(); } // Go back and emit clears for each of the fields we processed. + bool deferred_has_bit_changes = false; for (int j = last_chunk_start; j <= last_chunk_end; j++) { const FieldDescriptor* field = optimized_order_[j]; const FieldGenerator& generator = field_generators_.get(field); bool have_enclosing_if = false; if (HasFieldPresence(descriptor_->file())) { - printer->Print( - "if (from.has_$name$()) {\n", - "name", FieldName(field)); + // Attempt to use the state of cached_has_bits, if possible. + int has_bit_index = has_bit_indices_[field->index()]; + if (!field->options().weak() && + cached_has_bit_index == has_bit_index / 32) { + const string mask = StrCat( + strings::Hex(1u << (has_bit_index % 32), + strings::ZERO_PAD_8)); + + printer->Print( + "if (cached_has_bits & 0x$mask$u) {\n", "mask", mask); + } else { + printer->Print( + "if (from.has_$name$()) {\n", + "name", FieldName(field)); + } + printer->Indent(); have_enclosing_if = true; } else { @@ -2805,7 +3141,17 @@ GenerateMergeFrom(io::Printer* printer) { printer, "from.", field); } - generator.GenerateMergingCode(printer); + if (have_outer_if && IsPOD(field)) { + // GenerateCopyConstructorCode for enum and primitive scalar fields + // does not do _has_bits_ modifications. We defer _has_bits_ + // manipulation until the end of the outer if. + // + // This can reduce the number of loads/stores by up to 7 per 8 fields. + deferred_has_bit_changes = true; + generator.GenerateCopyConstructorCode(printer); + } else { + generator.GenerateMergingCode(printer); + } if (have_enclosing_if) { printer->Outdent(); @@ -2814,6 +3160,14 @@ GenerateMergeFrom(io::Printer* printer) { } if (have_outer_if) { + if (deferred_has_bit_changes) { + // Flush the has bits for the primitives we deferred. + GOOGLE_CHECK_LE(0, cached_has_bit_index); + printer->Print( + "_has_bits_[$index$] |= cached_has_bits;\n", + "index", SimpleItoa(cached_has_bit_index)); + } + printer->Outdent(); printer->Print("}\n"); } @@ -2849,6 +3203,9 @@ GenerateMergeFrom(io::Printer* printer) { printer->Print( "}\n"); } + if (num_weak_fields_) { + printer->Print("_weak_field_map_.MergeFrom(from._weak_field_map_);\n"); + } printer->Outdent(); printer->Print("}\n"); @@ -2913,13 +3270,36 @@ GenerateMergeFromCodedStream(io::Printer* printer) { return; } + std::vector ordered_fields = + SortFieldsByNumber(descriptor_); + printer->Print( "bool $classname$::MergePartialFromCodedStream(\n" - " ::google::protobuf::io::CodedInputStream* input) {\n" - "#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure\n" - " ::google::protobuf::uint32 tag;\n", + " ::google::protobuf::io::CodedInputStream* input) {\n", "classname", classname_); + if (table_driven_) { + printer->Indent(); + + printer->Print( + "return ::google::protobuf::internal::MergePartialFromCodedStream(\n" + " this,\n" + " $file_namespace$::TableStruct::schema[\n" + " $classname$::kIndexInFileMessages],\n" + " input);\n", + "classname", classname_, + "file_namespace", FileLevelNamespace(descriptor_->file()->name())); + + printer->Outdent(); + + printer->Print("}\n"); + return; + } + + printer->Print( + "#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure\n" + " ::google::protobuf::uint32 tag;\n"); + if (PreserveUnknownFields(descriptor_) && !UseUnknownFieldSet(descriptor_->file(), options_)) { // Use LazyStringOutputString to avoid initializing unknown fields string @@ -2928,7 +3308,8 @@ GenerateMergeFromCodedStream(io::Printer* printer) { printer->Print( " ::google::protobuf::io::LazyStringOutputStream unknown_fields_string(\n" " ::google::protobuf::NewPermanentCallback(&_internal_metadata_,\n" - " &::google::protobuf::internal::InternalMetadataWithArenaLite::mutable_unknown_fields));\n" + " &::google::protobuf::internal::InternalMetadataWithArenaLite::\n" + " mutable_unknown_fields));\n" " ::google::protobuf::io::CodedOutputStream unknown_fields_stream(\n" " &unknown_fields_string, false);\n", "classname", classname_); @@ -2942,8 +3323,6 @@ GenerateMergeFromCodedStream(io::Printer* printer) { printer->Print("for (;;) {\n"); printer->Indent(); - std::vector ordered_fields = - SortFieldsByNumber(descriptor_); uint32 maxtag = descriptor_->field_count() == 0 ? 0 : WireFormat::MakeTag(ordered_fields[descriptor_->field_count() - 1]); const int kCutoff0 = 127; // fits in 1-byte varint @@ -3004,20 +3383,8 @@ GenerateMergeFromCodedStream(io::Printer* printer) { printer->Indent(); - // Find repeated messages and groups now, to simplify what follows. - hash_set fields_with_parse_loop; - for (int i = 0; i < ordered_fields.size(); i++) { - const FieldDescriptor* field = ordered_fields[i]; - if (field->is_repeated() && - (field->type() == FieldDescriptor::TYPE_MESSAGE || - field->type() == FieldDescriptor::TYPE_GROUP)) { - fields_with_parse_loop.insert(i); - } - } - for (int i = 0; i < ordered_fields.size(); i++) { const FieldDescriptor* field = ordered_fields[i]; - const bool loops = fields_with_parse_loop.count(i) > 0; PrintFieldComment(printer, field); @@ -3030,11 +3397,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) { // Emit code to parse the common, expected case. printer->Print("if (static_cast< ::google::protobuf::uint8>(tag) ==\n" " static_cast< ::google::protobuf::uint8>($commontag$u)) {\n", - "commontag", SimpleItoa(WireFormat::MakeTag(field))); - - if (loops) { - printer->Print(" DO_(input->IncrementRecursionDepth());\n"); - } + "commontag", SimpleItoa(WireFormat::MakeTag(field))); printer->Indent(); if (field->is_packed()) { @@ -3074,12 +3437,6 @@ GenerateMergeFromCodedStream(io::Printer* printer) { " goto handle_unusual;\n" "}\n"); - // For repeated messages/groups, we need to decrement recursion depth. - if (loops) { - printer->Print( - "input->UnsafeDecrementRecursionDepth();\n"); - } - printer->Print( "break;\n"); @@ -3194,7 +3551,7 @@ void MessageGenerator::GenerateSerializeOneofFields( bool to_array) { GOOGLE_CHECK(!fields.empty()); if (fields.size() == 1) { - GenerateSerializeOneField(printer, fields[0], to_array); + GenerateSerializeOneField(printer, fields[0], to_array, -1); return; } // We have multiple mutually exclusive choices. Emit a switch statement. @@ -3227,14 +3584,31 @@ void MessageGenerator::GenerateSerializeOneofFields( } void MessageGenerator::GenerateSerializeOneField( - io::Printer* printer, const FieldDescriptor* field, bool to_array) { - PrintFieldComment(printer, field); + io::Printer* printer, const FieldDescriptor* field, bool to_array, + int cached_has_bits_index) { + if (!field->options().weak()) { + // For weakfields, PrintFieldComment is called during iteration. + PrintFieldComment(printer, field); + } bool have_enclosing_if = false; - if (!field->is_repeated() && HasFieldPresence(descriptor_->file())) { - printer->Print( - "if (has_$name$()) {\n", - "name", FieldName(field)); + if (field->options().weak()) { + } else if (!field->is_repeated() && HasFieldPresence(descriptor_->file())) { + // Attempt to use the state of cached_has_bits, if possible. + int has_bit_index = has_bit_indices_[field->index()]; + if (cached_has_bits_index == has_bit_index / 32) { + const string mask = StrCat( + strings::Hex(1u << (has_bit_index % 32), + strings::ZERO_PAD_8)); + + printer->Print( + "if (cached_has_bits & 0x$mask$u) {\n", "mask", mask); + } else { + printer->Print( + "if (has_$name$()) {\n", + "name", FieldName(field)); + } + printer->Indent(); have_enclosing_if = true; } else if (!HasFieldPresence(descriptor_->file())) { @@ -3341,7 +3715,6 @@ 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()); @@ -3372,7 +3745,8 @@ GenerateSerializeWithCachedSizesBody(io::Printer* printer, bool to_array) { : mg_(mg), printer_(printer), to_array_(to_array), - eager_(!HasFieldPresence(mg->descriptor_->file())) {} + eager_(!HasFieldPresence(mg->descriptor_->file())), + cached_has_bit_index_(-1) {} ~LazySerializerEmitter() { Flush(); } @@ -3383,7 +3757,27 @@ GenerateSerializeWithCachedSizesBody(io::Printer* printer, bool to_array) { Flush(); } if (field->containing_oneof() == NULL) { - mg_->GenerateSerializeOneField(printer_, field, to_array_); + // TODO(ckennelly): Defer non-oneof fields similarly to oneof fields. + + if (!field->options().weak() && !field->is_repeated() && !eager_) { + // We speculatively load the entire _has_bits_[index] contents, even + // if it is for only one field. Deferring non-oneof emitting would + // allow us to determine whether this is going to be useful. + int has_bit_index = mg_->has_bit_indices_[field->index()]; + if (cached_has_bit_index_ != has_bit_index / 32) { + // Reload. + int new_index = has_bit_index / 32; + + printer_->Print( + "cached_has_bits = _has_bits_[$new_index$];\n", + "new_index", SimpleItoa(new_index)); + + cached_has_bit_index_ = new_index; + } + } + + mg_->GenerateSerializeOneField( + printer_, field, to_array_, cached_has_bit_index_); } else { v_.push_back(field); } @@ -3409,6 +3803,11 @@ GenerateSerializeWithCachedSizesBody(io::Printer* printer, bool to_array) { const bool to_array_; const bool eager_; std::vector v_; + + // cached_has_bit_index_ maintains that: + // cached_has_bits = from._has_bits_[cached_has_bit_index_] + // for cached_has_bit_index_ >= 0 + int cached_has_bit_index_; }; std::vector ordered_fields = @@ -3420,29 +3819,51 @@ GenerateSerializeWithCachedSizesBody(io::Printer* printer, bool to_array) { } std::sort(sorted_extensions.begin(), sorted_extensions.end(), ExtensionRangeSorter()); + if (num_weak_fields_) { + printer->Print( + "::google::protobuf::internal::WeakFieldMap::FieldWriter field_writer(" + "_weak_field_map_);\n"); + } + + printer->Print( + "::google::protobuf::uint32 cached_has_bits = 0;\n" + "(void) cached_has_bits;\n\n"); // Merge the fields and the extension ranges, both sorted by field number. { LazySerializerEmitter e(this, printer, to_array); + const FieldDescriptor* last_weak_field = NULL; int i, j; for (i = 0, j = 0; i < ordered_fields.size() || j < sorted_extensions.size();) { - if (i == descriptor_->field_count()) { - e.Flush(); - GenerateSerializeOneExtensionRange(printer, - sorted_extensions[j++], - to_array); - } else if (j == sorted_extensions.size()) { - e.Emit(ordered_fields[i++]); - } else if (ordered_fields[i]->number() < sorted_extensions[j]->start) { - e.Emit(ordered_fields[i++]); - } else { + if ((j == sorted_extensions.size()) || + (i < descriptor_->field_count() && + ordered_fields[i]->number() < sorted_extensions[j]->start)) { + const FieldDescriptor* field = ordered_fields[i++]; + if (field->options().weak()) { + last_weak_field = field; + PrintFieldComment(printer, field); + } else { + if (last_weak_field != NULL) { + e.Emit(last_weak_field); + last_weak_field = NULL; + } + e.Emit(field); + } + } else { + if (last_weak_field != NULL) { + e.Emit(last_weak_field); + last_weak_field = NULL; + } e.Flush(); GenerateSerializeOneExtensionRange(printer, sorted_extensions[j++], to_array); } } + if (last_weak_field != NULL) { + e.Emit(last_weak_field); + } } if (PreserveUnknownFields(descriptor_)) { @@ -3783,6 +4204,11 @@ GenerateByteSize(io::Printer* printer) { "}\n"); } + if (num_weak_fields_) { + // TagSize + MessageSize + printer->Print("total_size += _weak_field_map_.ByteSizeLong();\n"); + } + // We update _cached_size_ even though this is a const method. In theory, // this is not thread-compatible, because concurrent writes have undefined // results. In practice, since any concurrent writes will be writing the @@ -3840,26 +4266,28 @@ GenerateIsInitialized(io::Printer* printer) { // TODO(ckennelly): Push this down into a generator? if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && !ShouldIgnoreRequiredFieldCheck(field, options_) && - HasRequiredFields(field->message_type(), options_)) { + scc_analyzer_->HasRequiredFields(field->message_type())) { if (field->is_repeated()) { printer->Print( "if (!::google::protobuf::internal::AllAreInitialized(this->$name$()))" " return false;\n", "name", FieldName(field)); + } else if (field->options().weak()) { + continue; } else { - GOOGLE_CHECK(field->options().weak() || !field->containing_oneof()); - // For weak fields, use the data member (::google::protobuf::Message*) instead - // of the getter to avoid a link dependency on the weak message type - // which is only forward declared. + GOOGLE_CHECK(!field->containing_oneof()); printer->Print( "if (has_$name$()) {\n" " if (!this->$name$_->IsInitialized()) return false;\n" "}\n", - "name", FieldName(field)); + "name", FieldName(field)); } } } - + if (num_weak_fields_) { + // For Weak fields. + printer->Print("if (!_weak_field_map_.IsInitialized()) return false;\n"); + } // Go through the oneof fields, emitting a switch if any might have required // fields. for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { @@ -3871,7 +4299,7 @@ GenerateIsInitialized(io::Printer* printer) { if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && !ShouldIgnoreRequiredFieldCheck(field, options_) && - HasRequiredFields(field->message_type(), options_)) { + scc_analyzer_->HasRequiredFields(field->message_type())) { has_required_fields = true; break; } @@ -3894,17 +4322,10 @@ GenerateIsInitialized(io::Printer* printer) { if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && !ShouldIgnoreRequiredFieldCheck(field, options_) && - HasRequiredFields(field->message_type(), options_)) { + scc_analyzer_->HasRequiredFields(field->message_type())) { GOOGLE_CHECK(!(field->options().weak() || !field->containing_oneof())); if (field->options().weak()) { - // For weak fields, use the data member (::google::protobuf::Message*) instead - // of the getter to avoid a link dependency on the weak message type - // which is only forward declared. - printer->Print( - "if (has_$name$()) {\n" - " if (!this->$name$_->IsInitialized()) return false;\n" - "}\n", - "name", FieldName(field)); + // Just skip. } else { printer->Print( "if (has_$name$()) {\n" diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_message.h b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_message.h index 1a804a16b3..23aaeeb0fe 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_message.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_message.h @@ -42,6 +42,7 @@ #include #include #include +#include #include namespace google { @@ -61,7 +62,8 @@ class ExtensionGenerator; // extension.h class MessageGenerator { public: // See generator.cc for the meaning of dllexport_decl. - MessageGenerator(const Descriptor* descriptor, const Options& options); + MessageGenerator(const Descriptor* descriptor, const Options& options, + SCCAnalyzer* scc_analyzer); ~MessageGenerator(); // Appends the pre-order walk of the nested generators to list. @@ -94,10 +96,6 @@ class MessageGenerator { // Generate extra fields void GenerateExtraDefaultFields(io::Printer* printer); - // Generate code that calls MessageFactory::InternalRegisterGeneratedMessage() - // for all types. - void GenerateTypeRegistrations(io::Printer* printer); - // Generates code that allocates the message's default instance. void GenerateDefaultInstanceAllocator(io::Printer* printer); @@ -121,6 +119,15 @@ class MessageGenerator { void GenerateDependentFieldAccessorDefinitions(io::Printer* printer); void GenerateFieldAccessorDefinitions(io::Printer* printer, bool is_inline); + // Generate the table-driven parsing array. Returns the number of entries + // generated. + size_t GenerateParseOffsets(io::Printer* printer); + size_t GenerateParseAuxTable(io::Printer* printer); + // Generates a ParseTable entry. Returns whether the proto uses table-driven + // parsing. + bool GenerateParseTable(io::Printer* printer, size_t offset, + size_t aux_offset); + // Generate the field offsets array. Returns the a pair of the total numer // of entries generated and the index of the first has_bit entry. std::pair GenerateOffsets(io::Printer* printer); @@ -155,9 +162,14 @@ class MessageGenerator { void GenerateIsInitialized(io::Printer* printer); // Helpers for GenerateSerializeWithCachedSizes(). + // + // cached_has_bit_index maintains that: + // cached_has_bits = _has_bits_[cached_has_bit_index] + // for cached_has_bit_index >= 0 void GenerateSerializeOneField(io::Printer* printer, const FieldDescriptor* field, - bool unbounded); + bool unbounded, + int cached_has_bits_index); // Generate a switch statement to serialize 2+ fields from the same oneof. // Or, if fields.size() == 1, just call GenerateSerializeOneField(). void GenerateSerializeOneofFields( @@ -197,7 +209,7 @@ class MessageGenerator { // optimized_order_ is the order we layout the message's fields in the class. // This is reused to initialize the fields in-order for cache efficiency. // - // optimized_order_ excludes oneof fields. + // optimized_order_ excludes oneof fields and weak fields. std::vector optimized_order_; std::vector has_bit_indices_; int max_has_bit_index_; @@ -206,8 +218,13 @@ class MessageGenerator { google::protobuf::scoped_array > extension_generators_; int num_required_fields_; bool use_dependent_base_; + int num_weak_fields_; + // table_driven_ indicates the generated message uses table-driven parsing. + bool table_driven_; + + int index_in_file_messages_; - int index_in_metadata_; + SCCAnalyzer* scc_analyzer_; friend class FileGenerator; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_message_field.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_message_field.cc index c3d1745c7c..fc3c456417 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_message_field.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_message_field.cc @@ -35,6 +35,7 @@ #include #include #include + #include namespace google { @@ -583,7 +584,7 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { printer->Print(variables_, "target = ::google::protobuf::internal::WireFormatLite::\n" " InternalWrite$declared_type$NoVirtualToArray(\n" - " $number$, *$non_null_ptr_to_name$, false, target);\n"); + " $number$, *$non_null_ptr_to_name$, deterministic, target);\n"); } void MessageFieldGenerator:: @@ -670,15 +671,6 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, InternalGenerateInlineAccessorDefinitions(variables, printer); } -void MessageOneofFieldGenerator:: -GenerateNonInlineAccessorDefinitions(io::Printer* printer) const { - std::map variables(variables_); - variables["field_member"] = - variables["oneof_prefix"] + variables["name"] + "_"; - - //printer->Print(variables, -} - void MessageOneofFieldGenerator::InternalGenerateInlineAccessorDefinitions( const std::map& variables, io::Printer* printer) const { printer->Print(variables, @@ -1066,7 +1058,7 @@ GenerateMergingCode(io::Printer* printer) const { void RepeatedMessageFieldGenerator:: GenerateSwappingCode(io::Printer* printer) const { - printer->Print(variables_, "$name$_.UnsafeArenaSwap(&other->$name$_);\n"); + printer->Print(variables_, "$name$_.InternalSwap(&other->$name$_);\n"); } void RepeatedMessageFieldGenerator:: @@ -1079,12 +1071,12 @@ GenerateMergeFromCodedStream(io::Printer* printer) const { if (descriptor_->type() == FieldDescriptor::TYPE_MESSAGE) { printer->Print(variables_, "DO_(::google::protobuf::internal::WireFormatLite::" - "ReadMessageNoVirtualNoRecursionDepth(\n" + "ReadMessageNoVirtual(\n" " input, add_$name$()));\n"); } else { printer->Print(variables_, "DO_(::google::protobuf::internal::WireFormatLite::" - "ReadGroupNoVirtualNoRecursionDepth(\n" + "ReadGroupNoVirtual(\n" " $number$, input, add_$name$()));\n"); } } @@ -1104,7 +1096,7 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { "for (unsigned int i = 0, n = this->$name$_size(); i < n; i++) {\n" " target = ::google::protobuf::internal::WireFormatLite::\n" " InternalWrite$declared_type$NoVirtualToArray(\n" - " $number$, this->$name$(i), false, target);\n" + " $number$, this->$name$(i), deterministic, target);\n" "}\n"); } diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_message_field.h b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_message_field.h index 9ca9115313..cd9737f0e3 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_message_field.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_message_field.h @@ -95,7 +95,7 @@ class MessageOneofFieldGenerator : public MessageFieldGenerator { void GenerateDependentInlineAccessorDefinitions(io::Printer* printer) const; void GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const; - void GenerateNonInlineAccessorDefinitions(io::Printer* printer) const; + void GenerateNonInlineAccessorDefinitions(io::Printer* printer) const { } void GenerateClearingCode(io::Printer* printer) const; // MessageFieldGenerator, from which we inherit, overrides this so we need to diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_options.h b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_options.h index ee44fb0abc..bdaa12a55d 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_options.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_options.h @@ -46,16 +46,18 @@ struct Options { Options() : safe_boundary_check(false), proto_h(false), - allow_import_public(true), + transitive_pb_h(true), annotate_headers(false), - enforce_lite(false) {} + enforce_lite(false), + table_driven_parsing(false) {} string dllexport_decl; bool safe_boundary_check; bool proto_h; - bool allow_import_public; + bool transitive_pb_h; bool annotate_headers; bool enforce_lite; + bool table_driven_parsing; string annotation_pragma_name; string annotation_guard_name; }; diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc index 4a0a23f60e..020c194120 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc @@ -342,7 +342,7 @@ GenerateMergingCode(io::Printer* printer) const { void RepeatedPrimitiveFieldGenerator:: GenerateSwappingCode(io::Printer* printer) const { - printer->Print(variables_, "$name$_.UnsafeArenaSwap(&other->$name$_);\n"); + printer->Print(variables_, "$name$_.InternalSwap(&other->$name$_);\n"); } void RepeatedPrimitiveFieldGenerator:: @@ -385,6 +385,9 @@ GenerateSerializeWithCachedSizes(io::Printer* printer) const { " output->WriteVarint32(_$name$_cached_byte_size_);\n"); if (FixedSize(descriptor_->type()) > 0) { + // TODO(ckennelly): Use RepeatedField::unsafe_data() via + // WireFormatLite to access the contents of this->$name$_ to save a branch + // here. printer->Print(variables_, " ::google::protobuf::internal::WireFormatLite::Write$declared_type$Array(\n" " this->$name$().data(), this->$name$_size(), output);\n"); @@ -420,20 +423,14 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { " target);\n" " target = ::google::protobuf::io::CodedOutputStream::WriteVarint32ToArray(\n" " _$name$_cached_byte_size_, target);\n" - "}\n"); - } - printer->Print(variables_, - "for (int i = 0, n = this->$name$_size(); i < n; i++) {\n"); - if (descriptor_->is_packed()) { - printer->Print(variables_, " target = ::google::protobuf::internal::WireFormatLite::\n" - " Write$declared_type$NoTagToArray(this->$name$(i), target);\n"); + " Write$declared_type$NoTagToArray(this->$name$_, target);\n" + "}\n"); } else { printer->Print(variables_, - " target = ::google::protobuf::internal::WireFormatLite::\n" - " Write$declared_type$ToArray($number$, this->$name$(i), target);\n"); + "target = ::google::protobuf::internal::WireFormatLite::\n" + " Write$declared_type$ToArray($number$, this->$name$_, target);\n"); } - printer->Print("}\n"); } void RepeatedPrimitiveFieldGenerator:: diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_string_field.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_string_field.cc index 664a277946..7a849e2e5e 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_string_field.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_string_field.cc @@ -36,6 +36,7 @@ #include #include #include + #include namespace google { @@ -61,6 +62,7 @@ void SetStringVariables(const FieldDescriptor* descriptor, ".get()"; (*variables)["pointer_type"] = descriptor->type() == FieldDescriptor::TYPE_BYTES ? "void" : "char"; + (*variables)["null_check"] = "GOOGLE_DCHECK(value != NULL);\n"; // NOTE: Escaped here to unblock proto1->proto2 migration. // TODO(liujisi): Extend this to apply for other conflicting methods. (*variables)["release_name"] = @@ -190,6 +192,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " // @@protoc_insertion_point(field_set:$full_name$)\n" "}\n" "$inline$void $classname$::set_$name$(const char* value) {\n" + " $null_check$" " $set_hasbit$\n" " $name$_.Set($default_variable$, $string_piece$(value),\n" " GetArenaNoVirtual());\n" @@ -267,6 +270,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, "}\n" "#endif\n" "$inline$void $classname$::set_$name$(const char* value) {\n" + " $null_check$" " $set_hasbit$\n" " $name$_.SetNoArena($default_variable$, $string_piece$(value));\n" " // @@protoc_insertion_point(field_set_char:$full_name$)\n" @@ -548,6 +552,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " // @@protoc_insertion_point(field_set:$full_name$)\n" "}\n" "$inline$void $classname$::set_$name$(const char* value) {\n" + " $null_check$" " if (!has_$name$()) {\n" " clear_$oneof_name$();\n" " set_has_$name$();\n" @@ -664,6 +669,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, "}\n" "#endif\n" "$inline$void $classname$::set_$name$(const char* value) {\n" + " $null_check$" " if (!has_$name$()) {\n" " clear_$oneof_name$();\n" " set_has_$name$();\n" @@ -882,6 +888,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, "}\n" "#endif\n" "$inline$void $classname$::set_$name$(int index, const char* value) {\n" + " $null_check$" " $name$_.Mutable(index)->assign(value);\n" " // @@protoc_insertion_point(field_set_char:$full_name$)\n" "}\n" @@ -902,11 +909,12 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, "}\n" "#if LANG_CXX11\n" "$inline$void $classname$::add_$name$(::std::string&& value) {\n" - " $name$_.Add()->assign(std::move(value));\n" + " $name$_.Add(std::move(value));\n" " // @@protoc_insertion_point(field_add:$full_name$)\n" "}\n" "#endif\n" "$inline$void $classname$::add_$name$(const char* value) {\n" + " $null_check$" " $name$_.Add()->assign(value);\n" " // @@protoc_insertion_point(field_add_char:$full_name$)\n" "}\n" @@ -939,7 +947,7 @@ GenerateMergingCode(io::Printer* printer) const { void RepeatedStringFieldGenerator:: GenerateSwappingCode(io::Printer* printer) const { - printer->Print(variables_, "$name$_.UnsafeArenaSwap(&other->$name$_);\n"); + printer->Print(variables_, "$name$_.InternalSwap(&other->$name$_);\n"); } void RepeatedStringFieldGenerator:: @@ -969,7 +977,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) const { void RepeatedStringFieldGenerator:: GenerateSerializeWithCachedSizes(io::Printer* printer) const { printer->Print(variables_, - "for (int i = 0, n = this->$name$_size(); i < n; i++) {\n"); + "for (int i = 0, n = this->$name$_size(); i < n; i++) {\n"); printer->Indent(); if (descriptor_->type() == FieldDescriptor::TYPE_STRING) { GenerateUtf8CheckCodeForString( diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_unittest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_unittest.cc index 6d68ec35a9..e56964c78f 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_unittest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/cpp/cpp_unittest.cc @@ -76,7 +76,6 @@ #include #include #include -#include #include #include #include @@ -2162,6 +2161,61 @@ TEST_F(OneofTest, MergeFrom) { } +TEST(HelpersTest, TestSCC) { + protobuf_unittest::TestMutualRecursionA a; + SCCAnalyzer scc_analyzer((Options())); + const SCC* scc = scc_analyzer.GetSCC(a.GetDescriptor()); + std::vector names; + for (int i = 0; i < scc->descriptors.size(); i++) { + names.push_back(scc->descriptors[i]->full_name()); + } + ASSERT_EQ(names.size(), 4); + std::sort(names.begin(), names.end()); + EXPECT_EQ(names[0], "protobuf_unittest.TestMutualRecursionA"); + EXPECT_EQ(names[1], "protobuf_unittest.TestMutualRecursionA.SubGroup"); + EXPECT_EQ(names[2], "protobuf_unittest.TestMutualRecursionA.SubMessage"); + EXPECT_EQ(names[3], "protobuf_unittest.TestMutualRecursionB"); + + MessageAnalysis result = scc_analyzer.GetSCCAnalysis(scc); + EXPECT_EQ(result.is_recursive, true); + EXPECT_EQ(result.contains_required, false); + EXPECT_EQ(result.contains_cord, true); // TestAllTypes + EXPECT_EQ(result.contains_extension, false); // TestAllTypes +} + +TEST(HelpersTest, TestSCCAnalysis) { + { + protobuf_unittest::TestRecursiveMessage msg; + SCCAnalyzer scc_analyzer((Options())); + const SCC* scc = scc_analyzer.GetSCC(msg.GetDescriptor()); + MessageAnalysis result = scc_analyzer.GetSCCAnalysis(scc); + EXPECT_EQ(result.is_recursive, true); + EXPECT_EQ(result.contains_required, false); + EXPECT_EQ(result.contains_cord, false); + EXPECT_EQ(result.contains_extension, false); + } + { + protobuf_unittest::TestAllExtensions msg; + SCCAnalyzer scc_analyzer((Options())); + const SCC* scc = scc_analyzer.GetSCC(msg.GetDescriptor()); + MessageAnalysis result = scc_analyzer.GetSCCAnalysis(scc); + EXPECT_EQ(result.is_recursive, false); + EXPECT_EQ(result.contains_required, false); + EXPECT_EQ(result.contains_cord, false); + EXPECT_EQ(result.contains_extension, true); + } + { + protobuf_unittest::TestRequired msg; + SCCAnalyzer scc_analyzer((Options())); + const SCC* scc = scc_analyzer.GetSCC(msg.GetDescriptor()); + MessageAnalysis result = scc_analyzer.GetSCCAnalysis(scc); + EXPECT_EQ(result.is_recursive, false); + EXPECT_EQ(result.contains_required, true); + EXPECT_EQ(result.contains_cord, false); + EXPECT_EQ(result.contains_extension, false); + } +} + } // namespace cpp_unittest } // namespace cpp } // namespace compiler diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/csharp/csharp_field_base.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/csharp/csharp_field_base.cc index 139cc75366..ebb8fbc26c 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/csharp/csharp_field_base.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/csharp/csharp_field_base.cc @@ -322,9 +322,9 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor) } case FieldDescriptor::TYPE_DOUBLE: { double value = descriptor->default_value_double(); - if (value == numeric_limits::infinity()) { + if (value == std::numeric_limits::infinity()) { return "double.PositiveInfinity"; - } else if (value == -numeric_limits::infinity()) { + } else if (value == -std::numeric_limits::infinity()) { return "double.NegativeInfinity"; } else if (MathLimits::IsNaN(value)) { return "double.NaN"; @@ -333,9 +333,9 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor) } case FieldDescriptor::TYPE_FLOAT: { float value = descriptor->default_value_float(); - if (value == numeric_limits::infinity()) { + if (value == std::numeric_limits::infinity()) { return "float.PositiveInfinity"; - } else if (value == -numeric_limits::infinity()) { + } else if (value == -std::numeric_limits::infinity()) { return "float.NegativeInfinity"; } else if (MathLimits::IsNaN(value)) { return "float.NaN"; diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/importer.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/importer.cc index bb168d5241..9b5e103ae8 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/importer.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/importer.cc @@ -32,7 +32,9 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#ifndef _MSC_VER +#ifdef _MSC_VER +#include +#else #include #endif #include @@ -54,14 +56,18 @@ #include #include -namespace google { -namespace protobuf { -namespace compiler { - #ifdef _WIN32 #include +// DO NOT include , instead create functions in io_win32.{h,cc} and import +// them like we do below. +using google::protobuf::stubs::access; +using google::protobuf::stubs::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? @@ -218,6 +224,7 @@ void Importer::ClearUnusedImportTrackFiles() { pool_.ClearUnusedImportTrackFiles(); } + // =================================================================== SourceTree::~SourceTree() {} diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/importer.h b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/importer.h index 759636e164..a4ffcf87de 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/importer.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/importer.h @@ -175,6 +175,7 @@ class LIBPROTOBUF_EXPORT Importer { void AddUnusedImportTrackFile(const string& file_name); void ClearUnusedImportTrackFiles(); + private: SourceTreeDescriptorDatabase database_; DescriptorPool pool_; diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/importer_unittest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/importer_unittest.cc index 00285bcc63..a96ac85339 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/importer_unittest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/importer_unittest.cc @@ -47,11 +47,11 @@ #include #include #include -#include #include #include #include #include +#include namespace google { namespace protobuf { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_enum_field_lite.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_enum_field_lite.cc index 50eed5da49..1eefdcfc12 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_enum_field_lite.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_enum_field_lite.cc @@ -314,6 +314,7 @@ GenerateParsingDoneCode(io::Printer* printer) const { // noop for enums } + void ImmutableEnumFieldLiteGenerator:: GenerateSerializationCode(io::Printer* printer) const { printer->Print(variables_, @@ -423,6 +424,7 @@ GenerateMembers(io::Printer* printer) const { "}\n"); } + void ImmutableEnumOneofFieldLiteGenerator:: GenerateBuilderMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { @@ -707,6 +709,7 @@ GenerateMembers(io::Printer* printer) const { } } + void RepeatedImmutableEnumFieldLiteGenerator:: GenerateBuilderMembers(io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_enum_lite.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_enum_lite.cc index 96815920a6..38b054e70a 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_enum_lite.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_enum_lite.cc @@ -49,17 +49,6 @@ namespace protobuf { namespace compiler { namespace java { -namespace { -bool EnumHasCustomOptions(const EnumDescriptor* descriptor) { - if (descriptor->options().unknown_fields().field_count() > 0) return true; - for (int i = 0; i < descriptor->value_count(); ++i) { - const EnumValueDescriptor* value = descriptor->value(i); - if (value->options().unknown_fields().field_count() > 0) return true; - } - return false; -} -} // namespace - EnumLiteGenerator::EnumLiteGenerator(const EnumDescriptor* descriptor, bool immutable_api, Context* context) : descriptor_(descriptor), @@ -139,22 +128,30 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { // ----------------------------------------------------------------- printer->Print( - "\n" - "public final int getNumber() {\n" - " return value;\n" - "}\n" - "\n" - "/**\n" - " * @deprecated Use {@link #forNumber(int)} instead.\n" - " */\n" - "@java.lang.Deprecated\n" - "public static $classname$ valueOf(int value) {\n" - " return forNumber(value);\n" - "}\n" - "\n" - "public static $classname$ forNumber(int value) {\n" - " switch (value) {\n", - "classname", descriptor_->name()); + "\n" + "public final int getNumber() {\n"); + if (SupportUnknownEnumValue(descriptor_->file())) { + printer->Print( + " if (this == UNRECOGNIZED) {\n" + " throw new java.lang.IllegalArgumentException(\n" + " \"Can't get the number of an unknown enum value.\");\n" + " }\n"); + } + printer->Print( + " return value;\n" + "}\n" + "\n" + "/**\n" + " * @deprecated Use {@link #forNumber(int)} instead.\n" + " */\n" + "@java.lang.Deprecated\n" + "public static $classname$ valueOf(int value) {\n" + " return forNumber(value);\n" + "}\n" + "\n" + "public static $classname$ forNumber(int value) {\n" + " switch (value) {\n", + "classname", descriptor_->name()); printer->Indent(); printer->Indent(); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_field.h b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_field.h index 434e610cc1..cc1d83d981 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_field.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_field.h @@ -119,6 +119,7 @@ class ImmutableFieldLiteGenerator { virtual void GenerateEqualsCode(io::Printer* printer) const = 0; virtual void GenerateHashCode(io::Printer* printer) const = 0; + virtual string GetBoxedType() const = 0; private: diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_file.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_file.cc index 86719f704c..0fda166d12 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_file.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_file.cc @@ -154,12 +154,6 @@ void CollectExtensions(const FileDescriptorProto& file_proto, } } -// Compare two field descriptors, returning true if the first should come -// before the second. -bool CompareFieldsByName(const FieldDescriptor *a, const FieldDescriptor *b) { - return a->full_name() < b->full_name(); -} - // Our static initialization methods can become very, very large. // So large that if we aren't careful we end up blowing the JVM's // 64K bytes of bytecode/method. Fortunately, since these static diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_generator.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_generator.cc index 2c02d996fe..0214121098 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_generator.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_generator.cc @@ -47,6 +47,7 @@ #include #include #include + #include namespace google { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_helpers.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_helpers.cc index efb5fd4565..8469740fba 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_helpers.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_helpers.cc @@ -43,6 +43,7 @@ #include #include #include +#include // for hash namespace google { namespace protobuf { @@ -245,6 +246,7 @@ string ClassName(const FileDescriptor* descriptor) { return name_resolver.GetClassName(descriptor, true); } + string ExtraMessageInterfaces(const Descriptor* descriptor) { string interfaces = "// @@protoc_insertion_point(message_implements:" + descriptor->full_name() + ")"; diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc index 49070ba0e1..51bb11f1c7 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc @@ -232,6 +232,7 @@ GenerateSerializedSizeCode(io::Printer* printer) const { "}\n"); } + // =================================================================== ImmutableLazyMessageOneofFieldLiteGenerator:: @@ -415,6 +416,7 @@ GenerateSerializedSizeCode(io::Printer* printer) const { "}\n"); } + // =================================================================== RepeatedImmutableLazyMessageFieldLiteGenerator:: @@ -716,6 +718,7 @@ GenerateSerializedSizeCode(io::Printer* printer) const { "}\n"); } + } // namespace java } // namespace compiler } // namespace protobuf diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_lazy_message_field_lite.h b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_lazy_message_field_lite.h index 47ebeb49a0..65b84fbcab 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_lazy_message_field_lite.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_lazy_message_field_lite.h @@ -68,6 +68,7 @@ class ImmutableLazyMessageFieldLiteGenerator void GenerateSerializationCode(io::Printer* printer) const; void GenerateSerializedSizeCode(io::Printer* printer) const; + private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableLazyMessageFieldLiteGenerator); }; @@ -87,6 +88,7 @@ class ImmutableLazyMessageOneofFieldLiteGenerator void GenerateSerializationCode(io::Printer* printer) const; void GenerateSerializedSizeCode(io::Printer* printer) const; + private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableLazyMessageOneofFieldLiteGenerator); }; @@ -106,6 +108,7 @@ class RepeatedImmutableLazyMessageFieldLiteGenerator void GenerateSerializationCode(io::Printer* printer) const; void GenerateSerializedSizeCode(io::Printer* printer) const; + private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableLazyMessageFieldLiteGenerator); }; diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_map_field.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_map_field.cc index 3fe68ae3d5..608b53786a 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_map_field.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_map_field.cc @@ -417,9 +417,6 @@ GenerateBuilderMembers(io::Printer* printer) const { " $key_type$ key,\n" " $value_type$ value) {\n" " $key_null_check$\n" - " if ($value_enum_type$.forNumber(value) == null) {\n" - " throw new java.lang.IllegalArgumentException();\n" - " }\n" " internalGetMutable$capitalized_name$().getMutableMap()\n" " .put(key, value);\n" " return this;\n" diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_map_field_lite.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_map_field_lite.cc index 523052cc9e..073d1cfc59 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_map_field_lite.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_map_field_lite.cc @@ -484,6 +484,7 @@ GenerateMembers(io::Printer* printer) const { } } + void ImmutableMapFieldLiteGenerator:: GenerateBuilderMembers(io::Printer* printer) const { printer->Print( @@ -642,9 +643,6 @@ GenerateBuilderMembers(io::Printer* printer) const { " $key_type$ key,\n" " $value_type$ value) {\n" " $key_null_check$\n" - " if ($value_enum_type$.forNumber(value) == null) {\n" - " throw new java.lang.IllegalArgumentException();\n" - " }\n" " copyOnWrite();\n" " instance.getMutable$capitalized_name$ValueMap().put(key, value);\n" " return this;\n" diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_map_field_lite.h b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_map_field_lite.h index 63dedbc2cf..94aa48136b 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_map_field_lite.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_map_field_lite.h @@ -62,6 +62,7 @@ class ImmutableMapFieldLiteGenerator : public ImmutableFieldLiteGenerator { void GenerateEqualsCode(io::Printer* printer) const; void GenerateHashCode(io::Printer* printer) const; + string GetBoxedType() const; private: diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_message.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_message.cc index 3b8d7ab8ec..6e3b4a758d 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_message.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_message.cc @@ -685,6 +685,17 @@ GenerateParseFromMethods(io::Printer* printer) { // because they need to be generated even for messages that are optimized // for code size. printer->Print( + "public static $classname$ parseFrom(\n" + " java.nio.ByteBuffer data)\n" + " throws com.google.protobuf.InvalidProtocolBufferException {\n" + " return PARSER.parseFrom(data);\n" + "}\n" + "public static $classname$ parseFrom(\n" + " java.nio.ByteBuffer data,\n" + " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n" + " throws com.google.protobuf.InvalidProtocolBufferException {\n" + " return PARSER.parseFrom(data, extensionRegistry);\n" + "}\n" "public static $classname$ parseFrom(\n" " com.google.protobuf.ByteString data)\n" " throws com.google.protobuf.InvalidProtocolBufferException {\n" diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_message_builder_lite.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_message_builder_lite.cc index 7e404ba167..1ad58c09ce 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_message_builder_lite.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_message_builder_lite.cc @@ -67,13 +67,6 @@ bool GenerateHasBits(const Descriptor* descriptor) { return SupportFieldPresence(descriptor->file()) || HasRepeatedFields(descriptor); } - -string MapValueImmutableClassdName(const Descriptor* descriptor, - ClassNameResolver* name_resolver) { - const FieldDescriptor* value_field = descriptor->FindFieldByName("value"); - GOOGLE_CHECK_EQ(FieldDescriptor::TYPE_MESSAGE, value_field->type()); - return name_resolver->GetImmutableClassName(value_field->message_type()); -} } // namespace MessageBuilderLiteGenerator::MessageBuilderLiteGenerator( diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_message_field_lite.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_message_field_lite.cc index 0957676cb0..c71e910128 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_message_field_lite.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_message_field_lite.cc @@ -451,6 +451,7 @@ GenerateMembers(io::Printer* printer) const { "}\n"); } + void ImmutableMessageOneofFieldLiteGenerator:: GenerateBuilderMembers(io::Printer* printer) const { // The comments above the methods below are based on a hypothetical @@ -856,6 +857,7 @@ GenerateFieldBuilderInitializationCode(io::Printer* printer) const { "get$capitalized_name$FieldBuilder();\n"); } + void RepeatedImmutableMessageFieldLiteGenerator:: GenerateInitializationCode(io::Printer* printer) const { printer->Print(variables_, "$name$_ = emptyProtobufList();\n"); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_message_field_lite.h b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_message_field_lite.h index dbb263de18..7c814c6d7e 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_message_field_lite.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_message_field_lite.h @@ -106,6 +106,7 @@ class ImmutableMessageOneofFieldLiteGenerator void GenerateSerializationCode(io::Printer* printer) const; void GenerateSerializedSizeCode(io::Printer* printer) const; + private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageOneofFieldLiteGenerator); }; @@ -135,6 +136,7 @@ class RepeatedImmutableMessageFieldLiteGenerator void GenerateEqualsCode(io::Printer* printer) const; void GenerateHashCode(io::Printer* printer) const; + string GetBoxedType() const; protected: diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_message_lite.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_message_lite.cc index e84321bb63..5007ecee8f 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_message_lite.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_message_lite.cc @@ -398,6 +398,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { printer->Print( "}\n" + "// fall through\n" "case GET_DEFAULT_INSTANCE: {\n" " return DEFAULT_INSTANCE;\n" "}\n" @@ -588,6 +589,19 @@ GenerateParseFromMethods(io::Printer* printer) { // because they need to be generated even for messages that are optimized // for code size. printer->Print( + "public static $classname$ parseFrom(\n" + " java.nio.ByteBuffer data)\n" + " throws com.google.protobuf.InvalidProtocolBufferException {\n" + " return com.google.protobuf.GeneratedMessageLite.parseFrom(\n" + " DEFAULT_INSTANCE, data);\n" + "}\n" + "public static $classname$ parseFrom(\n" + " java.nio.ByteBuffer data,\n" + " com.google.protobuf.ExtensionRegistryLite extensionRegistry)\n" + " throws com.google.protobuf.InvalidProtocolBufferException {\n" + " return com.google.protobuf.GeneratedMessageLite.parseFrom(\n" + " DEFAULT_INSTANCE, data, extensionRegistry);\n" + "}\n" "public static $classname$ parseFrom(\n" " com.google.protobuf.ByteString data)\n" " throws com.google.protobuf.InvalidProtocolBufferException {\n" @@ -1057,21 +1071,6 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodMergeFromStream( // =================================================================== -namespace { -bool CheckHasBitsForEqualsAndHashCode(const FieldDescriptor* field) { - if (field->is_repeated()) { - return false; - } - if (SupportFieldPresence(field->file())) { - return true; - } - return GetJavaType(field) == JAVATYPE_MESSAGE && - field->containing_oneof() == NULL; -} -} // namespace - -// =================================================================== - void ImmutableMessageLiteGenerator:: GenerateExtensionRegistrationCode(io::Printer* printer) { for (int i = 0; i < descriptor_->extension_count(); i++) { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_primitive_field_lite.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_primitive_field_lite.cc index b04bf1c22c..0e8e492f62 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_primitive_field_lite.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_primitive_field_lite.cc @@ -297,6 +297,7 @@ GenerateFieldBuilderInitializationCode(io::Printer* printer) const { // noop for primitives } + void ImmutablePrimitiveFieldLiteGenerator:: GenerateInitializationCode(io::Printer* printer) const { if (IsByteStringWithCustomDefaultValue(descriptor_)) { @@ -747,6 +748,7 @@ GenerateFieldBuilderInitializationCode(io::Printer* printer) const { // noop for primitives } + void RepeatedImmutablePrimitiveFieldLiteGenerator:: GenerateInitializationCode(io::Printer* printer) const { printer->Print(variables_, "$name$_ = $empty_list$;\n"); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_primitive_field_lite.h b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_primitive_field_lite.h index dc59f0cf9e..93416f0b68 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_primitive_field_lite.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_primitive_field_lite.h @@ -80,6 +80,7 @@ class ImmutablePrimitiveFieldLiteGenerator void GenerateEqualsCode(io::Printer* printer) const; void GenerateHashCode(io::Printer* printer) const; + string GetBoxedType() const; protected: @@ -110,6 +111,7 @@ class ImmutablePrimitiveOneofFieldLiteGenerator void GenerateSerializationCode(io::Printer* printer) const; void GenerateSerializedSizeCode(io::Printer* printer) const; + private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutablePrimitiveOneofFieldLiteGenerator); }; @@ -142,6 +144,7 @@ class RepeatedImmutablePrimitiveFieldLiteGenerator void GenerateEqualsCode(io::Printer* printer) const; void GenerateHashCode(io::Printer* printer) const; + string GetBoxedType() const; private: diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_string_field_lite.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_string_field_lite.cc index 138e59b693..7e3ad1d007 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_string_field_lite.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_string_field_lite.cc @@ -295,6 +295,7 @@ GenerateFieldBuilderInitializationCode(io::Printer* printer) const { // noop for strings } + void ImmutableStringFieldLiteGenerator:: GenerateInitializationCode(io::Printer* printer) const { printer->Print(variables_, "$name$_ = $default$;\n"); @@ -467,6 +468,7 @@ GenerateMembers(io::Printer* printer) const { "}\n"); } + void ImmutableStringOneofFieldLiteGenerator:: GenerateBuilderMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { @@ -763,6 +765,7 @@ GenerateFieldBuilderInitializationCode(io::Printer* printer) const { // noop for strings } + void RepeatedImmutableStringFieldLiteGenerator:: GenerateInitializationCode(io::Printer* printer) const { printer->Print(variables_, "$name$_ = $empty_list$;\n"); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_string_field_lite.h b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_string_field_lite.h index 80496c8744..b7fb640959 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_string_field_lite.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/java/java_string_field_lite.h @@ -78,6 +78,7 @@ class ImmutableStringFieldLiteGenerator : public ImmutableFieldLiteGenerator { void GenerateEqualsCode(io::Printer* printer) const; void GenerateHashCode(io::Printer* printer) const; + string GetBoxedType() const; protected: @@ -108,6 +109,7 @@ class ImmutableStringOneofFieldLiteGenerator void GenerateSerializationCode(io::Printer* printer) const; void GenerateSerializedSizeCode(io::Printer* printer) const; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringOneofFieldLiteGenerator); }; @@ -136,6 +138,7 @@ class RepeatedImmutableStringFieldLiteGenerator void GenerateEqualsCode(io::Printer* printer) const; void GenerateHashCode(io::Printer* printer) const; + string GetBoxedType() const; private: diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/javanano/javanano_file.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/javanano/javanano_file.cc index 3676ab9d19..17f7386e77 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/javanano/javanano_file.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/javanano/javanano_file.cc @@ -120,12 +120,12 @@ bool FileGenerator::Validate(string* error) { if (!params_.has_java_outer_classname(file_->name()) && file_->message_type_count() == 1 && file_->enum_type_count() == 0 && file_->extension_count() == 0) { - cout << "INFO: " << file_->name() << ":" << endl; - cout << "Javanano generator has changed to align with java generator. " + std::cout << "INFO: " << file_->name() << ":" << std::endl; + std::cout << "Javanano generator has changed to align with java generator. " "An outer class will be created for this file and the single message " "in the file will become a nested class. Use java_multiple_files to " "skip generating the outer class, or set an explicit " - "java_outer_classname to suppress this message." << endl; + "java_outer_classname to suppress this message." << std::endl; } // Check that no class name matches the file's class name. This is a common diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/javanano/javanano_helpers.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/javanano/javanano_helpers.cc index 02811a24dc..5018250cfc 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/javanano/javanano_helpers.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/javanano/javanano_helpers.cc @@ -428,9 +428,9 @@ string DefaultValue(const Params& params, const FieldDescriptor* field) { "L"; case FieldDescriptor::CPPTYPE_DOUBLE: { double value = field->default_value_double(); - if (value == numeric_limits::infinity()) { + if (value == std::numeric_limits::infinity()) { return "Double.POSITIVE_INFINITY"; - } else if (value == -numeric_limits::infinity()) { + } else if (value == -std::numeric_limits::infinity()) { return "Double.NEGATIVE_INFINITY"; } else if (value != value) { return "Double.NaN"; @@ -440,9 +440,9 @@ string DefaultValue(const Params& params, const FieldDescriptor* field) { } case FieldDescriptor::CPPTYPE_FLOAT: { float value = field->default_value_float(); - if (value == numeric_limits::infinity()) { + if (value == std::numeric_limits::infinity()) { return "Float.POSITIVE_INFINITY"; - } else if (value == -numeric_limits::infinity()) { + } else if (value == -std::numeric_limits::infinity()) { return "Float.NEGATIVE_INFINITY"; } else if (value != value) { return "Float.NaN"; diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/javanano/javanano_message.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/javanano/javanano_message.cc index a41da5ae33..f81f7f9aa0 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/javanano/javanano_message.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/javanano/javanano_message.cc @@ -69,7 +69,7 @@ const FieldDescriptor** SortFieldsByNumber(const Descriptor* descriptor) { for (int i = 0; i < descriptor->field_count(); i++) { fields[i] = descriptor->field(i); } - sort(fields, fields + descriptor->field_count(), + std::sort(fields, fields + descriptor->field_count(), FieldOrderingByNumber()); return fields; } diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/js/embed.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/js/embed.cc index 57d38237b3..a725b62eb8 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/js/embed.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/js/embed.cc @@ -98,7 +98,7 @@ static void AddFile(const char* name, std::basic_ostream* out) { int main(int argc, char *argv[]) { std::cout << "#include " - "\n"; + "\"google/protobuf/compiler/js/well_known_types_embed.h\"\n"; std::cout << "struct FileToc well_known_types_js[] = {\n"; for (int i = 1; i < argc; i++) { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/js/js_generator.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/js/js_generator.cc index 727ed09025..7c63e58f65 100755 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/js/js_generator.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/js/js_generator.cc @@ -198,8 +198,8 @@ string ModuleAlias(const string& filename) { // Returns the fully normalized JavaScript path for the given // file descriptor's package. -string GetPath(const GeneratorOptions& options, - const FileDescriptor* file) { +string GetFilePath(const GeneratorOptions& options, + const FileDescriptor* file) { if (!options.namespace_prefix.empty()) { return options.namespace_prefix; } else if (!file->package().empty()) { @@ -231,51 +231,32 @@ string GetNestedMessageName(const Descriptor* descriptor) { string GetPrefix(const GeneratorOptions& options, const FileDescriptor* file_descriptor, const Descriptor* containing_type) { - string prefix = - GetPath(options, file_descriptor) + GetNestedMessageName(containing_type); + string prefix = GetFilePath(options, file_descriptor) + + GetNestedMessageName(containing_type); if (!prefix.empty()) { prefix += "."; } return prefix; } - // Returns the fully normalized JavaScript path for the given // message descriptor. -string GetPath(const GeneratorOptions& options, - const Descriptor* descriptor) { +string GetMessagePath(const GeneratorOptions& options, + const Descriptor* descriptor) { return GetPrefix( options, descriptor->file(), descriptor->containing_type()) + descriptor->name(); } - -// Returns the fully normalized JavaScript path for the given -// field's containing message descriptor. -string GetPath(const GeneratorOptions& options, - const FieldDescriptor* descriptor) { - return GetPath(options, descriptor->containing_type()); -} - // Returns the fully normalized JavaScript path for the given // enumeration descriptor. -string GetPath(const GeneratorOptions& options, - const EnumDescriptor* enum_descriptor) { +string GetEnumPath(const GeneratorOptions& options, + const EnumDescriptor* enum_descriptor) { return GetPrefix( options, enum_descriptor->file(), enum_descriptor->containing_type()) + enum_descriptor->name(); } - -// Returns the fully normalized JavaScript path for the given -// enumeration value descriptor. -string GetPath(const GeneratorOptions& options, - const EnumValueDescriptor* value_descriptor) { - return GetPath( - options, - value_descriptor->type()) + "." + value_descriptor->name(); -} - string MaybeCrossFileRef(const GeneratorOptions& options, const FileDescriptor* from_file, const Descriptor* to_message) { @@ -288,7 +269,7 @@ string MaybeCrossFileRef(const GeneratorOptions& options, to_message->name(); } else { // Within a single file we use a full name. - return GetPath(options, to_message); + return GetMessagePath(options, to_message); } } @@ -413,7 +394,7 @@ string ToFileName(const string& input) { // that top-level extensions should go in. string GetExtensionFileName(const GeneratorOptions& options, const FileDescriptor* file) { - return options.output_dir + "/" + ToFileName(GetPath(options, file)) + + return options.output_dir + "/" + ToFileName(GetFilePath(options, file)) + options.GetFileNameExtension(); } @@ -550,14 +531,6 @@ string JSGetterName(const GeneratorOptions& options, return name; } -string JSMapGetterName(const GeneratorOptions& options, - const FieldDescriptor* field) { - return JSIdent(options, field, - /* is_upper_camel = */ true, - /* is_map = */ true, - /* drop_list = */ false); -} - string JSOneofName(const OneofDescriptor* oneof) { @@ -872,11 +845,11 @@ string ProtoTypeName(const GeneratorOptions& options, case FieldDescriptor::TYPE_BYTES: return "bytes"; case FieldDescriptor::TYPE_GROUP: - return GetPath(options, field->message_type()); + return GetMessagePath(options, field->message_type()); case FieldDescriptor::TYPE_ENUM: - return GetPath(options, field->enum_type()); + return GetEnumPath(options, field->enum_type()); case FieldDescriptor::TYPE_MESSAGE: - return GetPath(options, field->message_type()); + return GetMessagePath(options, field->message_type()); default: return ""; } @@ -925,9 +898,9 @@ string JSTypeName(const GeneratorOptions& options, case FieldDescriptor::CPPTYPE_STRING: return JSStringTypeName(options, field, bytes_mode); case FieldDescriptor::CPPTYPE_ENUM: - return GetPath(options, field->enum_type()); + return GetEnumPath(options, field->enum_type()); case FieldDescriptor::CPPTYPE_MESSAGE: - return GetPath(options, field->message_type()); + return GetMessagePath(options, field->message_type()); default: return ""; } @@ -1111,7 +1084,7 @@ static const char* kRepeatedFieldArrayName = ".repeatedFields_"; string RepeatedFieldsArrayName(const GeneratorOptions& options, const Descriptor* desc) { return HasRepeatedFields(options, desc) - ? (GetPath(options, desc) + kRepeatedFieldArrayName) + ? (GetMessagePath(options, desc) + kRepeatedFieldArrayName) : "null"; } @@ -1128,8 +1101,9 @@ static const char* kOneofGroupArrayName = ".oneofGroups_"; string OneofFieldsArrayName(const GeneratorOptions& options, const Descriptor* desc) { - return HasOneofFields(desc) ? - (GetPath(options, desc) + kOneofGroupArrayName) : "null"; + return HasOneofFields(desc) + ? (GetMessagePath(options, desc) + kOneofGroupArrayName) + : "null"; } string RepeatedFieldNumberList(const GeneratorOptions& options, @@ -1571,7 +1545,7 @@ void Generator::FindProvidesForMessage( return; } - string name = GetPath(options, desc); + string name = GetMessagePath(options, desc); provided->insert(name); for (int i = 0; i < desc->enum_type_count(); i++) { @@ -1588,7 +1562,7 @@ void Generator::FindProvidesForEnum(const GeneratorOptions& options, io::Printer* printer, const EnumDescriptor* enumdesc, std::set* provided) const { - string name = GetPath(options, enumdesc); + string name = GetEnumPath(options, enumdesc); provided->insert(name); } @@ -1604,9 +1578,8 @@ void Generator::FindProvidesForFields( continue; } - string name = - GetPath(options, field->file()) + "." + - JSObjectFieldName(options, field); + string name = GetFilePath(options, field->file()) + "." + + JSObjectFieldName(options, field); provided->insert(name); } } @@ -1684,7 +1657,7 @@ void Generator::GenerateRequiresForLibrary( } if (extension->containing_type()->full_name() != "google.protobuf.bridge.MessageSet") { - required.insert(GetPath(options, extension->containing_type())); + required.insert(GetMessagePath(options, extension->containing_type())); } FindRequiresForField(options, extension, &required, &forwards); have_extensions = true; @@ -1805,13 +1778,13 @@ void Generator::FindRequiresForField(const GeneratorOptions& options, // dependencies, as per original codegen. !(field->is_extension() && field->extension_scope() == NULL)) { if (options.add_require_for_enums) { - required->insert(GetPath(options, field->enum_type())); + required->insert(GetEnumPath(options, field->enum_type())); } else { - forwards->insert(GetPath(options, field->enum_type())); + forwards->insert(GetEnumPath(options, field->enum_type())); } } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { if (!IgnoreMessage(options, field->message_type())) { - required->insert(GetPath(options, field->message_type())); + required->insert(GetMessagePath(options, field->message_type())); } } } @@ -1821,7 +1794,7 @@ void Generator::FindRequiresForExtension(const GeneratorOptions& options, std::set* required, std::set* forwards) const { if (field->containing_type()->full_name() != "google.protobuf.bridge.MessageSet") { - required->insert(GetPath(options, field->containing_type())); + required->insert(GetMessagePath(options, field->containing_type())); } FindRequiresForField(options, field, required, forwards); } @@ -1868,7 +1841,7 @@ void Generator::GenerateClass(const GeneratorOptions& options, } // Recurse on nested types. These must come *before* the extension-field - // info generation in GenerateClassRegistration so that extensions that + // info generation in GenerateClassRegistration so that extensions that // reference nested types proceed the definitions of the nested types. for (int i = 0; i < desc->enum_type_count(); i++) { GenerateEnum(options, printer, desc->enum_type(i)); @@ -1890,7 +1863,6 @@ void Generator::GenerateClass(const GeneratorOptions& options, } } } - } void Generator::GenerateClassConstructor(const GeneratorOptions& options, @@ -1912,7 +1884,7 @@ void Generator::GenerateClassConstructor(const GeneratorOptions& options, " * @constructor\n" " */\n" "$classname$ = function(opt_data) {\n", - "classname", GetPath(options, desc)); + "classname", GetMessagePath(options, desc)); string message_id = GetMessageId(desc); printer->Print( " jspb.Message.initialize(this, opt_data, $messageId$, $pivot$, " @@ -1929,7 +1901,7 @@ void Generator::GenerateClassConstructor(const GeneratorOptions& options, "if (goog.DEBUG && !COMPILED) {\n" " $classname$.displayName = '$classname$';\n" "}\n", - "classname", GetPath(options, desc)); + "classname", GetMessagePath(options, desc)); } void Generator::GenerateClassFieldInfo(const GeneratorOptions& options, @@ -1944,7 +1916,7 @@ void Generator::GenerateClassFieldInfo(const GeneratorOptions& options, " */\n" "$classname$$rptfieldarray$ = $rptfields$;\n" "\n", - "classname", GetPath(options, desc), + "classname", GetMessagePath(options, desc), "rptfieldarray", kRepeatedFieldArrayName, "rptfields", RepeatedFieldNumberList(options, desc)); } @@ -1965,7 +1937,7 @@ void Generator::GenerateClassFieldInfo(const GeneratorOptions& options, " */\n" "$classname$$oneofgrouparray$ = $oneofgroups$;\n" "\n", - "classname", GetPath(options, desc), + "classname", GetMessagePath(options, desc), "oneofgrouparray", kOneofGroupArrayName, "oneofgroups", OneofGroupList(desc)); @@ -1985,7 +1957,7 @@ void Generator::GenerateClassXid(const GeneratorOptions& options, "\n" "\n" "$class$.prototype.messageXid = xid('$class$');\n", - "class", GetPath(options, desc)); + "class", GetMessagePath(options, desc)); } void Generator::GenerateOneofCaseDefinition( @@ -1998,7 +1970,7 @@ void Generator::GenerateOneofCaseDefinition( " */\n" "$classname$.$oneof$Case = {\n" " $upcase$_NOT_SET: 0", - "classname", GetPath(options, oneof->containing_type()), + "classname", GetMessagePath(options, oneof->containing_type()), "oneof", JSOneofName(oneof), "upcase", ToEnumCase(oneof->name())); @@ -2026,7 +1998,7 @@ void Generator::GenerateOneofCaseDefinition( "computeOneofCase(this, $class$.oneofGroups_[$oneofindex$]));\n" "};\n" "\n", - "class", GetPath(options, oneof->containing_type()), + "class", GetMessagePath(options, oneof->containing_type()), "oneof", JSOneofName(oneof), "oneofindex", JSOneofIndex(oneof)); } @@ -2068,7 +2040,7 @@ void Generator::GenerateClassToObject(const GeneratorOptions& options, " */\n" "$classname$.toObject = function(includeInstance, msg) {\n" " var f, obj = {", - "classname", GetPath(options, desc)); + "classname", GetMessagePath(options, desc)); bool first = true; for (int i = 0; i < desc->field_count(); i++) { @@ -2100,7 +2072,7 @@ void Generator::GenerateClassToObject(const GeneratorOptions& options, " $extObject$, $class$.prototype.getExtension,\n" " includeInstance);\n", "extObject", JSExtensionsObjectName(options, desc->file(), desc), - "class", GetPath(options, desc)); + "class", GetMessagePath(options, desc)); } printer->Print( @@ -2112,7 +2084,7 @@ void Generator::GenerateClassToObject(const GeneratorOptions& options, "}\n" "\n" "\n", - "classname", GetPath(options, desc)); + "classname", GetMessagePath(options, desc)); } void Generator::GenerateFieldValueExpression(io::Printer* printer, @@ -2173,7 +2145,7 @@ void Generator::GenerateClassFieldToObject(const GeneratorOptions& options, string value_to_object; if (value_field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { value_to_object = - GetPath(options, value_field->message_type()) + ".toObject"; + GetMessagePath(options, value_field->message_type()) + ".toObject"; } else { value_to_object = "undefined"; } @@ -2235,7 +2207,7 @@ void Generator::GenerateClassFromObject(const GeneratorOptions& options, " */\n" "$classname$.fromObject = function(obj) {\n" " var f, msg = new $classname$();\n", - "classname", GetPath(options, desc)); + "classname", GetMessagePath(options, desc)); for (int i = 0; i < desc->field_count(); i++) { const FieldDescriptor* field = desc->field(i); @@ -2263,7 +2235,7 @@ void Generator::GenerateClassFieldFromObject( "$fieldclass$.fromObject));\n", "name", JSObjectFieldName(options, field), "index", JSFieldIndex(field), - "fieldclass", GetPath(options, value_field->message_type())); + "fieldclass", GetMessagePath(options, value_field->message_type())); } else { // `msg` is a newly-constructed message object that has not yet built any // map containers wrapping underlying arrays, so we can simply directly @@ -2354,7 +2326,7 @@ void GenerateBytesWrapper(const GeneratorOptions& options, "fielddef", FieldDefinition(options, field), "comment", FieldComments(field, bytes_mode), "type", type, - "class", GetPath(options, field->containing_type()), + "class", GetMessagePath(options, field->containing_type()), "name", JSGetterName(options, field, bytes_mode), "list", field->is_repeated() ? "List" : "", "suffix", JSByteGetterSuffix(bytes_mode), @@ -2395,7 +2367,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options, printer->Print( "$class$.prototype.get$name$ = function(opt_noLazyCreate) {\n" " return /** @type {!jspb.Map<$keytype$,$valuetype$>} */ (\n", - "class", GetPath(options, field->containing_type()), + "class", GetMessagePath(options, field->containing_type()), "name", JSGetterName(options, field), "keytype", key_type, "valuetype", value_type); @@ -2404,9 +2376,10 @@ void Generator::GenerateClassField(const GeneratorOptions& options, "index", JSFieldIndex(field)); if (value_field->type() == FieldDescriptor::TYPE_MESSAGE) { - printer->Print(",\n" + printer->Print( + ",\n" " $messageType$", - "messageType", GetPath(options, value_field->message_type())); + "messageType", GetMessagePath(options, value_field->message_type())); } else { printer->Print(",\n" " null"); @@ -2443,7 +2416,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options, "};\n" "\n" "\n", - "class", GetPath(options, field->containing_type()), + "class", GetMessagePath(options, field->containing_type()), "name", JSGetterName(options, field), "type", JSFieldTypeAnnotation(options, field, /* is_setter_argument = */ false, @@ -2464,7 +2437,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options, /* force_present = */ false, /* singular_if_not_packed = */ false), "returndoc", JSReturnDoc(options, field), - "class", GetPath(options, field->containing_type()), + "class", GetMessagePath(options, field->containing_type()), "name", JSGetterName(options, field), "oneoftag", (field->containing_oneof() ? "Oneof" : ""), "repeatedtag", (field->is_repeated() ? "Repeated" : "")); @@ -2520,7 +2493,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options, printer->Print( "$class$.prototype.get$name$ = function() {\n", - "class", GetPath(options, field->containing_type()), + "class", GetMessagePath(options, field->containing_type()), "name", JSGetterName(options, field)); if (untyped) { @@ -2585,7 +2558,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options, printer->Print( "$class$.prototype.set$name$ = function(value) {\n" " jspb.Message.set$oneoftag$Field(this, $index$", - "class", GetPath(options, field->containing_type()), + "class", GetMessagePath(options, field->containing_type()), "name", JSGetterName(options, field), "oneoftag", (field->containing_oneof() ? "Oneof" : ""), "index", JSFieldIndex(field)); @@ -2626,7 +2599,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options, "};\n" "\n" "\n", - "class", GetPath(options, field->containing_type()), + "class", GetMessagePath(options, field->containing_type()), "name", JSGetterName(options, field), "returnvalue", JSReturnClause(field)); } else if (field->is_repeated() || @@ -2639,7 +2612,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options, "};\n" "\n" "\n", - "class", GetPath(options, field->containing_type()), + "class", GetMessagePath(options, field->containing_type()), "name", JSGetterName(options, field), "clearedvalue", (field->is_repeated() ? "[]" : "undefined"), "returnvalue", JSReturnClause(field)); @@ -2650,7 +2623,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options, "$class$.prototype.clear$name$ = function() {\n" " jspb.Message.set$maybeoneof$Field(this, " "$index$$maybeoneofgroup$, ", - "class", GetPath(options, field->containing_type()), + "class", GetMessagePath(options, field->containing_type()), "name", JSGetterName(options, field), "maybeoneof", (field->containing_oneof() ? "Oneof" : ""), "maybeoneofgroup", (field->containing_oneof() ? @@ -2676,7 +2649,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options, "};\n" "\n" "\n", - "class", GetPath(options, field->containing_type()), + "class", GetMessagePath(options, field->containing_type()), "name", JSGetterName(options, field), "index", JSFieldIndex(field)); } @@ -2692,8 +2665,8 @@ void Generator::GenerateRepeatedPrimitiveHelperMethods( " */\n" "$class$.prototype.add$name$ = function(value, opt_index) {\n" " jspb.Message.addToRepeatedField(this, $index$", - "class", GetPath(options, field->containing_type()), "name", - JSGetterName(options, field, BYTES_DEFAULT, + "class", GetMessagePath(options, field->containing_type()), + "name", JSGetterName(options, field, BYTES_DEFAULT, /* drop_list = */ true), "optionaltype", JSTypeName(options, field, BYTES_DEFAULT), "index", JSFieldIndex(field)); @@ -2719,9 +2692,9 @@ void Generator::GenerateRepeatedMessageHelperMethods( " */\n" "$class$.prototype.add$name$ = function(opt_value, opt_index) {\n" " return jspb.Message.addTo$repeatedtag$WrapperField(", - "optionaltype", JSTypeName(options, field, BYTES_DEFAULT), "class", - GetPath(options, field->containing_type()), "name", - JSGetterName(options, field, BYTES_DEFAULT, + "optionaltype", JSTypeName(options, field, BYTES_DEFAULT), + "class", GetMessagePath(options, field->containing_type()), + "name", JSGetterName(options, field, BYTES_DEFAULT, /* drop_list = */ true), "repeatedtag", (field->is_repeated() ? "Repeated" : "")); @@ -2732,7 +2705,7 @@ void Generator::GenerateRepeatedMessageHelperMethods( "\n", "index", JSFieldIndex(field), "oneofgroup", (field->containing_oneof() ? (", " + JSOneofArray(options, field)) : ""), - "ctor", GetPath(options, field->message_type())); + "ctor", GetMessagePath(options, field->message_type())); } void Generator::GenerateClassExtensionFieldInfo(const GeneratorOptions& options, @@ -2758,7 +2731,7 @@ void Generator::GenerateClassExtensionFieldInfo(const GeneratorOptions& options, " */\n" "$class$.extensions = {};\n" "\n", - "class", GetPath(options, desc)); + "class", GetMessagePath(options, desc)); printer->Print( "\n" @@ -2779,7 +2752,7 @@ void Generator::GenerateClassExtensionFieldInfo(const GeneratorOptions& options, " */\n" "$class$.extensionsBinary = {};\n" "\n", - "class", GetPath(options, desc)); + "class", GetMessagePath(options, desc)); } } @@ -2817,7 +2790,7 @@ void Generator::GenerateClassDeserializeBinary(const GeneratorOptions& options, " }\n" " var field = reader.getFieldNumber();\n" " switch (field) {\n", - "class", GetPath(options, desc)); + "class", GetMessagePath(options, desc)); for (int i = 0; i < desc->field_count(); i++) { if (!IgnoreField(desc->field(i))) { @@ -2834,7 +2807,7 @@ void Generator::GenerateClassDeserializeBinary(const GeneratorOptions& options, " $class$.prototype.setExtension);\n" " break;\n", "extobj", JSExtensionsObjectName(options, desc->file(), desc), - "class", GetPath(options, desc)); + "class", GetMessagePath(options, desc)); } else { printer->Print( " reader.skipField();\n" @@ -2873,7 +2846,7 @@ void Generator::GenerateClassDeserializeBinaryField( if (value_field->type() == FieldDescriptor::TYPE_MESSAGE) { printer->Print(", $messageType$.deserializeBinaryFromReader", - "messageType", GetPath(options, value_field->message_type())); + "messageType", GetMessagePath(options, value_field->message_type())); } printer->Print(");\n"); @@ -2941,7 +2914,7 @@ void Generator::GenerateClassSerializeBinary(const GeneratorOptions& options, "$class$.serializeBinaryToWriter = function(message, " "writer) {\n" " var f = undefined;\n", - "class", GetPath(options, desc)); + "class", GetMessagePath(options, desc)); for (int i = 0; i < desc->field_count(); i++) { if (!IgnoreField(desc->field(i))) { @@ -2954,7 +2927,7 @@ void Generator::GenerateClassSerializeBinary(const GeneratorOptions& options, " jspb.Message.serializeBinaryExtensions(message, writer,\n" " $extobj$Binary, $class$.prototype.getExtension);\n", "extobj", JSExtensionsObjectName(options, desc->file(), desc), - "class", GetPath(options, desc)); + "class", GetMessagePath(options, desc)); } printer->Print( @@ -3049,7 +3022,7 @@ void Generator::GenerateClassSerializeBinaryField( if (value_field->type() == FieldDescriptor::TYPE_MESSAGE) { printer->Print(", $messageType$.serializeBinaryToWriter", - "messageType", GetPath(options, value_field->message_type())); + "messageType", GetMessagePath(options, value_field->message_type())); } printer->Print(");\n"); @@ -3088,7 +3061,7 @@ void Generator::GenerateEnum(const GeneratorOptions& options, " * @enum {number}\n" " */\n" "$name$ = {\n", - "name", GetPath(options, enumdesc)); + "name", GetEnumPath(options, enumdesc)); for (int i = 0; i < enumdesc->value_count(); i++) { const EnumValueDescriptor* value = enumdesc->value(i); @@ -3108,9 +3081,9 @@ void Generator::GenerateExtension(const GeneratorOptions& options, io::Printer* printer, const FieldDescriptor* field) const { string extension_scope = - (field->extension_scope() ? - GetPath(options, field->extension_scope()) : - GetPath(options, field->file())); + (field->extension_scope() + ? GetMessagePath(options, field->extension_scope()) + : GetFilePath(options, field->file())); printer->Print( "\n" @@ -3347,7 +3320,7 @@ void Generator::GenerateFile(const GeneratorOptions& options, IgnoreField(file->extension(i))) { continue; } - provided.insert(GetPath(options, file) + "." + + provided.insert(GetFilePath(options, file) + "." + JSObjectFieldName(options, file->extension(i))); extensions.insert(file->extension(i)); } @@ -3371,7 +3344,7 @@ void Generator::GenerateFile(const GeneratorOptions& options, if (options.import_style == GeneratorOptions::kImportCommonJs) { printer->Print("goog.object.extend(exports, $package$);\n", - "package", GetPath(options, file)); + "package", GetFilePath(options, file)); } // Emit well-known type methods. diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/js/well_known_types/timestamp.js b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/js/well_known_types/timestamp.js index 77c07bb4e1..b7e43f1967 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/js/well_known_types/timestamp.js +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/js/well_known_types/timestamp.js @@ -48,7 +48,6 @@ proto.google.protobuf.Timestamp.prototype.toDate = function() { * @param {!Date} value The value to set. */ proto.google.protobuf.Timestamp.prototype.fromDate = function(value) { - var millis = value.getTime(); this.setSeconds(Math.floor(value.getTime() / 1000)); this.setNanos(value.getMilliseconds() * 1000000); }; diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/mock_code_generator.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/mock_code_generator.cc index a4b522cec3..0ddb99e56e 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/mock_code_generator.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/mock_code_generator.cc @@ -40,27 +40,21 @@ #endif #include +#include + #include #include #include #include #include +#include #include #include #include #include -#include #include #include -#ifdef major -#undef major -#endif -#ifdef minor -#undef minor -#endif -#include - namespace google { namespace protobuf { namespace compiler { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/objectivec/objectivec_extension.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/objectivec/objectivec_extension.cc index 7073173c88..73e4b86e21 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/objectivec/objectivec_extension.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/objectivec/objectivec_extension.cc @@ -49,9 +49,9 @@ ExtensionGenerator::ExtensionGenerator(const string& root_class_name, if (descriptor->is_map()) { // 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. - cerr << "error: Extension is a map<>!" - << " That used to be blocked by the compiler." << endl; - cerr.flush(); + std::cerr << "error: Extension is a map<>!" + << " That used to be blocked by the compiler." << std::endl; + std::cerr.flush(); abort(); } } diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/objectivec/objectivec_field.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/objectivec/objectivec_field.cc index 527b7c0c70..9f7e84f288 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/objectivec/objectivec_field.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/objectivec/objectivec_field.cc @@ -228,8 +228,8 @@ int FieldGenerator::ExtraRuntimeHasBitsNeeded(void) const { void FieldGenerator::SetExtraRuntimeHasBitsBase(int index_base) { // 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. - cerr << "Error: should have overridden SetExtraRuntimeHasBitsBase()." << endl; - cerr.flush(); + std::cerr << "Error: should have overridden SetExtraRuntimeHasBitsBase()." << std::endl; + std::cerr.flush(); abort(); } diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 4bf17d7b6e..bd8fd7226e 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -50,6 +50,12 @@ #include #include +#if defined(_WIN32) +// DO NOT include , instead create functions in io_win32.{h,cc} and import +// them like we do below. +using google::protobuf::stubs::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. @@ -1062,21 +1068,21 @@ bool ValidateObjCClassPrefix( // to Apple's rules (the checks above implicitly whitelist anything that // doesn't meet these rules). if (!ascii_isupper(prefix[0])) { - cerr << endl + std::cerr << std::endl << "protoc:0: warning: Invalid 'option objc_class_prefix = \"" << prefix << "\";' in '" << file->name() << "';" - << " it should start with a capital letter." << endl; - cerr.flush(); + << " it should start with a capital letter." << std::endl; + std::cerr.flush(); } if (prefix.length() < 3) { // Apple reserves 2 character prefixes for themselves. They do use some // 3 character prefixes, but they haven't updated the rules/docs. - cerr << endl + std::cerr << std::endl << "protoc:0: warning: Invalid 'option objc_class_prefix = \"" << prefix << "\";' in '" << file->name() << "';" << " Apple recommends they should be at least 3 characters long." - << endl; - cerr.flush(); + << std::endl; + std::cerr.flush(); } // Look for any other package that uses the same prefix. @@ -1095,22 +1101,22 @@ bool ValidateObjCClassPrefix( // The file does not have a package and ... if (other_package_for_prefix.empty()) { // ... no other package has declared that prefix. - cerr << endl + std::cerr << std::endl << "protoc:0: warning: File '" << file->name() << "' has no " << "package. Consider adding a new package to the proto and adding '" << "new.package = " << prefix << "' to the expected prefixes file (" - << expected_prefixes_path << ")." << endl; - cerr.flush(); + << expected_prefixes_path << ")." << std::endl; + std::cerr.flush(); } else { // ... another package has declared the same prefix. - cerr << endl + std::cerr << std::endl << "protoc:0: warning: File '" << file->name() << "' has no package " << "and package '" << other_package_for_prefix << "' already uses '" << prefix << "' as its prefix. Consider either adding a new package " << "to the proto, or reusing one of the packages already using this " << "prefix in the expected prefixes file (" - << expected_prefixes_path << ")." << endl; - cerr.flush(); + << expected_prefixes_path << ")." << std::endl; + std::cerr.flush(); } return true; } @@ -1132,12 +1138,12 @@ bool ValidateObjCClassPrefix( // Check: Warning - If the given package/prefix pair wasn't expected, issue a // warning issue a warning suggesting it gets added to the file. if (!expected_package_prefixes.empty()) { - cerr << endl + std::cerr << std::endl << "protoc:0: warning: Found unexpected 'option objc_class_prefix = \"" << prefix << "\";' in '" << file->name() << "';" << " consider adding it to the expected prefixes file (" - << expected_prefixes_path << ")." << endl; - cerr.flush(); + << expected_prefixes_path << ")." << std::endl; + std::cerr.flush(); } return true; @@ -1179,10 +1185,10 @@ void TextFormatDecodeData::AddString(int32 key, for (vector::const_iterator i = entries_.begin(); i != entries_.end(); ++i) { if (i->first == key) { - cerr << "error: duplicate key (" << key + std::cerr << "error: duplicate key (" << key << ") making TextFormat data, input: \"" << input_for_decode - << "\", desired: \"" << desired_output << "\"." << endl; - cerr.flush(); + << "\", desired: \"" << desired_output << "\"." << std::endl; + std::cerr.flush(); abort(); } } @@ -1193,7 +1199,7 @@ void TextFormatDecodeData::AddString(int32 key, } string TextFormatDecodeData::Data() const { - ostringstream data_stringstream; + std::ostringstream data_stringstream; if (num_entries() > 0) { io::OstreamOutputStream data_outputstream(&data_stringstream); @@ -1334,18 +1340,18 @@ string DirectDecodeString(const string& str) { string TextFormatDecodeData::DecodeDataForString(const string& input_for_decode, const string& desired_output) { if ((input_for_decode.size() == 0) || (desired_output.size() == 0)) { - cerr << "error: got empty string for making TextFormat data, input: \"" + std::cerr << "error: got empty string for making TextFormat data, input: \"" << input_for_decode << "\", desired: \"" << desired_output << "\"." - << endl; - cerr.flush(); + << std::endl; + std::cerr.flush(); abort(); } if ((input_for_decode.find('\0') != string::npos) || (desired_output.find('\0') != string::npos)) { - cerr << "error: got a null char in a string for making TextFormat data," + std::cerr << "error: got a null char in a string for making TextFormat data," << " input: \"" << CEscape(input_for_decode) << "\", desired: \"" - << CEscape(desired_output) << "\"." << endl; - cerr.flush(); + << CEscape(desired_output) << "\"." << std::endl; + std::cerr.flush(); abort(); } @@ -1610,9 +1616,9 @@ void ImportWriter::ParseFrameworkMappings() { string parse_error; if (!ParseSimpleFile(named_framework_to_proto_path_mappings_path_, &collector, &parse_error)) { - cerr << "error parsing " << named_framework_to_proto_path_mappings_path_ - << " : " << parse_error << endl; - cerr.flush(); + std::cerr << "error parsing " << named_framework_to_proto_path_mappings_path_ + << " : " << parse_error << std::endl; + std::cerr.flush(); } } @@ -1642,16 +1648,16 @@ bool ImportWriter::ProtoFrameworkCollector::ConsumeLine( map::iterator existing_entry = map_->find(proto_file.ToString()); if (existing_entry != map_->end()) { - cerr << "warning: duplicate proto file reference, replacing framework entry for '" + std::cerr << "warning: duplicate proto file reference, replacing framework entry for '" << proto_file.ToString() << "' with '" << framework_name.ToString() - << "' (was '" << existing_entry->second << "')." << endl; - cerr.flush(); + << "' (was '" << existing_entry->second << "')." << std::endl; + std::cerr.flush(); } if (proto_file.find(' ') != StringPiece::npos) { - cerr << "note: framework mapping file had a proto file with a space in, hopefully that isn't a missing comma: '" - << proto_file.ToString() << "'" << endl; - cerr.flush(); + std::cerr << "note: framework mapping file had a proto file with a space in, hopefully that isn't a missing comma: '" + << proto_file.ToString() << "'" << std::endl; + std::cerr.flush(); } (*map_)[proto_file.ToString()] = framework_name.ToString(); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/objectivec/objectivec_message.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/objectivec/objectivec_message.cc index e0bd3dac04..0a554a8393 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/objectivec/objectivec_message.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/objectivec/objectivec_message.cc @@ -156,7 +156,7 @@ const FieldDescriptor** SortFieldsByNumber(const Descriptor* descriptor) { for (int i = 0; i < descriptor->field_count(); i++) { fields[i] = descriptor->field(i); } - sort(fields, fields + descriptor->field_count(), FieldOrderingByNumber()); + std::sort(fields, fields + descriptor->field_count(), FieldOrderingByNumber()); return fields; } @@ -168,7 +168,7 @@ const FieldDescriptor** SortFieldsByStorageSize(const Descriptor* descriptor) { for (int i = 0; i < descriptor->field_count(); i++) { fields[i] = descriptor->field(i); } - sort(fields, fields + descriptor->field_count(), + std::sort(fields, fields + descriptor->field_count(), FieldOrderingByStorageSize()); return fields; } @@ -430,7 +430,7 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { sorted_extensions.push_back(descriptor_->extension_range(i)); } - sort(sorted_extensions.begin(), sorted_extensions.end(), + std::sort(sorted_extensions.begin(), sorted_extensions.end(), ExtensionRangeOrdering()); // Assign has bits: diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/parser_unittest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/parser_unittest.cc index 20140f8e7b..d5e31325c9 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/parser_unittest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/parser_unittest.cc @@ -42,14 +42,13 @@ #include +#include +#include #include #include #include -#include #include -#include -#include -#include +#include #include #include diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/php/php_generator.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/php/php_generator.cc index db72ea1ad8..ea850c0f45 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/php/php_generator.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/php/php_generator.cc @@ -49,6 +49,8 @@ const std::string kDescriptorMetadataFile = "GPBMetadata/Google/Protobuf/Internal/Descriptor.php"; const std::string kDescriptorDirName = "Google/Protobuf/Internal"; const std::string kDescriptorPackageName = "Google\\Protobuf\\Internal"; +const char* const kReservedNames[] = {"Empty", "ECHO"}; +const int kReservedNamesSize = 2; namespace google { namespace protobuf { @@ -84,33 +86,6 @@ std::string RenameEmpty(const std::string& name) { } } -std::string MessagePrefix(const Descriptor* message) { - // Empty cannot be php class name. - if (message->name() == "Empty" && - message->file()->package() == "google.protobuf") { - return "GPB"; - } else { - return (message->file()->options()).php_class_prefix(); - } -} - -std::string MessageName(const Descriptor* message, bool is_descriptor) { - string message_name = message->name(); - const Descriptor* descriptor = message->containing_type(); - while (descriptor != NULL) { - message_name = descriptor->name() + '_' + message_name; - descriptor = descriptor->containing_type(); - } - message_name = MessagePrefix(message) + message_name; - - if (message->file()->package() == "") { - return message_name; - } else { - return PhpName(message->file()->package(), is_descriptor) + '\\' + - message_name; - } -} - std::string MessageFullName(const Descriptor* message, bool is_descriptor) { if (is_descriptor) { return StringReplace(message->full_name(), @@ -131,19 +106,51 @@ std::string EnumFullName(const EnumDescriptor* envm, bool is_descriptor) { } } -std::string EnumClassName(const EnumDescriptor* envm) { - string enum_class_name = envm->name(); - const Descriptor* descriptor = envm->containing_type(); - while (descriptor != NULL) { - enum_class_name = descriptor->name() + '_' + enum_class_name; - descriptor = descriptor->containing_type(); +template +std::string ClassNamePrefix(const string& classname, + const DescriptorType* desc) { + const string& prefix = (desc->file()->options()).php_class_prefix(); + if (prefix != "") { + return prefix; + } + + bool is_reserved = false; + + for (int i = 0; i < kReservedNamesSize; i++) { + if (classname == kReservedNames[i]) { + is_reserved = true; + break; + } + } + + if (is_reserved) { + if (desc->file()->package() == "google.protobuf") { + return "GPB"; + } else { + return "PB"; + } } - return enum_class_name; + + return ""; } -std::string EnumName(const EnumDescriptor* envm, bool is_descriptor) { - string enum_name = EnumClassName(envm); - return PhpName(envm->file()->package(), is_descriptor) + '\\' + enum_name; + +template +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; + + if (desc->file()->package() == "") { + return classname; + } else { + return PhpName(desc->file()->package(), is_descriptor) + '\\' + + classname; + } } std::string PhpName(const std::string& full_name, bool is_descriptor) { @@ -231,7 +238,7 @@ std::string GeneratedMetadataFileName(const std::string& proto_file, std::string GeneratedMessageFileName(const Descriptor* message, bool is_descriptor) { - std::string result = MessageName(message, is_descriptor); + std::string result = FullClassName(message, is_descriptor); for (int i = 0; i < result.size(); i++) { if (result[i] == '\\') { result[i] = '/'; @@ -242,7 +249,7 @@ std::string GeneratedMessageFileName(const Descriptor* message, std::string GeneratedEnumFileName(const EnumDescriptor* en, bool is_descriptor) { - std::string result = EnumName(en, is_descriptor); + std::string result = FullClassName(en, is_descriptor); for (int i = 0; i < result.size(); i++) { if (result[i] == '\\') { result[i] = '/'; @@ -456,12 +463,12 @@ void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor, printer->Print( ", \\^class_name^);\n", "class_name", - MessageName(value->message_type(), is_descriptor) + "::class"); + FullClassName(value->message_type(), is_descriptor) + "::class"); } else if (value->cpp_type() == FieldDescriptor::CPPTYPE_ENUM) { printer->Print( - ", ^class_name^);\n", + ", \\^class_name^);\n", "class_name", - EnumName(value->enum_type(), is_descriptor) + "::class"); + FullClassName(value->enum_type(), is_descriptor) + "::class"); } else { printer->Print(");\n"); } @@ -474,23 +481,23 @@ void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor, printer->Print( ", \\^class_name^);\n", "class_name", - MessageName(field->message_type(), is_descriptor) + "::class"); + FullClassName(field->message_type(), is_descriptor) + "::class"); } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_ENUM) { printer->Print( - ", ^class_name^);\n", + ", \\^class_name^);\n", "class_name", - EnumName(field->enum_type(), is_descriptor) + "::class"); + FullClassName(field->enum_type(), is_descriptor) + "::class"); } else { printer->Print(");\n"); } } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { printer->Print( "GPBUtil::checkMessage($var, \\^class_name^::class);\n", - "class_name", MessageName(field->message_type(), is_descriptor)); + "class_name", FullClassName(field->message_type(), is_descriptor)); } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_ENUM) { printer->Print( "GPBUtil::checkEnum($var, \\^class_name^::class);\n", - "class_name", EnumName(field->enum_type(), is_descriptor)); + "class_name", FullClassName(field->enum_type(), is_descriptor)); } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_STRING) { printer->Print( "GPBUtil::checkString($var, ^utf8^);\n", @@ -552,7 +559,7 @@ void GenerateEnumToPool(const EnumDescriptor* en, io::Printer* printer) { const EnumValueDescriptor* value = en->value(i); printer->Print( "->value(\"^name^\", ^number^)\n", - "name", value->name(), + "name", ClassNamePrefix(value->name(), en) + value->name(), "number", IntToString(value->number())); } printer->Print("->finalizeToPool();\n\n"); @@ -667,6 +674,12 @@ void GenerateAddFileToPool(const FileDescriptor* file, bool is_descriptor, } else { for (int i = 0; i < file->dependency_count(); i++) { const std::string& name = file->dependency(i)->name(); + // Currently, descriptor.proto is not ready for external usage. Skip to + // import it for now, so that its dependencies can still work as long as + // they don't use protos defined in descriptor.proto. + if (name == kDescriptorFile) { + continue; + } std::string dependency_filename = GeneratedMetadataFileName(name, is_descriptor); printer->Print( @@ -678,6 +691,26 @@ void GenerateAddFileToPool(const FileDescriptor* file, bool is_descriptor, FileDescriptorSet files; FileDescriptorProto* file_proto = files.add_file(); file->CopyTo(file_proto); + + // Filter out descriptor.proto as it cannot be depended on for now. + RepeatedPtrField* dependency = file_proto->mutable_dependency(); + for (RepeatedPtrField::iterator it = dependency->begin(); + it != dependency->end(); ++it) { + if (*it != kDescriptorFile) { + dependency->erase(it); + break; + } + } + + // Filter out all extensions, since we do not support extension yet. + file_proto->clear_extension(); + RepeatedPtrField* message_type = + file_proto->mutable_message_type(); + for (RepeatedPtrField::iterator it = message_type->begin(); + it != message_type->end(); ++it) { + it->clear_extension(); + } + string files_data; files.SerializeToString(&files_data); @@ -812,7 +845,7 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en, const EnumValueDescriptor* value = en->value(i); GenerateEnumValueDocComment(&printer, value); printer.Print("const ^name^ = ^number^;\n", - "name", value->name(), + "name", ClassNamePrefix(value->name(), en) + value->name(), "number", IntToString(value->number())); } diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/plugin.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/plugin.cc index 3848101d1f..7b9635f6ab 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/plugin.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/plugin.cc @@ -36,18 +36,12 @@ #include #ifdef _WIN32 -#include #include -#ifndef STDIN_FILENO -#define STDIN_FILENO 0 -#endif -#ifndef STDOUT_FILENO -#define STDOUT_FILENO 1 -#endif #else #include #endif +#include #include #include #include @@ -55,6 +49,11 @@ #include #include +#if defined(_WIN32) +// DO NOT include , instead create functions in io_win32.{h,cc} and import +// them like we do below. +using google::protobuf::stubs::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/third_party/protobuf/3.2.0/src/google/protobuf/compiler/plugin.pb.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/plugin.pb.cc index d044fbbebf..f7dc1b7086 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/plugin.pb.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/plugin.pb.cc @@ -38,11 +38,29 @@ namespace { } // namespace +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField + const TableStruct::entries[] = { + {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, +}; + +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField + const TableStruct::aux[] = { + ::google::protobuf::internal::AuxillaryParseTableField(), +}; +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const + TableStruct::schema[] = { + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, +}; + const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Version, _has_bits_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Version, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Version, major_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Version, minor_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Version, patch_), @@ -55,6 +73,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, file_to_generate_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, parameter_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, proto_file_), @@ -67,6 +86,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse_File, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse_File, name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse_File, insertion_point_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse_File, content_), @@ -77,6 +97,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse, error_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse, file_), 0, @@ -84,10 +105,10 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { }; static const ::google::protobuf::internal::MigrationSchema schemas[] = { - { 0, 8, sizeof(Version)}, - { 12, 20, sizeof(CodeGeneratorRequest)}, - { 24, 31, sizeof(CodeGeneratorResponse_File)}, - { 34, 40, sizeof(CodeGeneratorResponse)}, + { 0, 9, sizeof(Version)}, + { 13, 22, sizeof(CodeGeneratorRequest)}, + { 26, 34, sizeof(CodeGeneratorResponse_File)}, + { 37, 44, sizeof(CodeGeneratorResponse)}, }; static ::google::protobuf::Message const * const file_default_instances[] = { @@ -246,7 +267,7 @@ void Version::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* Version::descriptor() { protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[0].descriptor; + return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const Version& Version::default_instance() { @@ -369,23 +390,27 @@ failure: void Version::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.compiler.Version) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; // optional int32 major = 1; - if (has_major()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormatLite::WriteInt32(1, this->major(), output); } // optional int32 minor = 2; - if (has_minor()) { + if (cached_has_bits & 0x00000004u) { ::google::protobuf::internal::WireFormatLite::WriteInt32(2, this->minor(), output); } // optional int32 patch = 3; - if (has_patch()) { + if (cached_has_bits & 0x00000008u) { ::google::protobuf::internal::WireFormatLite::WriteInt32(3, this->patch(), output); } // optional string suffix = 4; - if (has_suffix()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->suffix().data(), this->suffix().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -403,25 +428,28 @@ 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; + + cached_has_bits = _has_bits_[0]; // optional int32 major = 1; - if (has_major()) { + if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(1, this->major(), target); } // optional int32 minor = 2; - if (has_minor()) { + if (cached_has_bits & 0x00000004u) { target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(2, this->minor(), target); } // optional int32 patch = 3; - if (has_patch()) { + if (cached_has_bits & 0x00000008u) { target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(3, this->patch(), target); } // optional string suffix = 4; - if (has_suffix()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->suffix().data(), this->suffix().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -504,20 +532,25 @@ void Version::MergeFrom(const Version& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.Version) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); - if (from._has_bits_[0 / 32] & 15u) { - if (from.has_suffix()) { + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 15u) { + if (cached_has_bits & 0x00000001u) { set_has_suffix(); suffix_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.suffix_); } - if (from.has_major()) { - set_major(from.major()); + if (cached_has_bits & 0x00000002u) { + major_ = from.major_; } - if (from.has_minor()) { - set_minor(from.minor()); + if (cached_has_bits & 0x00000004u) { + minor_ = from.minor_; } - if (from.has_patch()) { - set_patch(from.patch()); + if (cached_has_bits & 0x00000008u) { + patch_ = from.patch_; } + _has_bits_[0] |= cached_has_bits; } } @@ -555,7 +588,7 @@ void Version::InternalSwap(Version* other) { ::google::protobuf::Metadata Version::GetMetadata() const { protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[0]; + return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -665,6 +698,7 @@ void Version::set_suffix(::std::string&& value) { } #endif void Version::set_suffix(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_suffix(); suffix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.Version.suffix) @@ -759,7 +793,7 @@ void CodeGeneratorRequest::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* CodeGeneratorRequest::descriptor() { protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[1].descriptor; + return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const CodeGeneratorRequest& CodeGeneratorRequest::default_instance() { @@ -852,13 +886,11 @@ bool CodeGeneratorRequest::MergePartialFromCodedStream( case 15: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(122u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_proto_file())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -887,6 +919,9 @@ failure: void CodeGeneratorRequest::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.compiler.CodeGeneratorRequest) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // repeated string file_to_generate = 1; for (int i = 0, n = this->file_to_generate_size(); i < n; i++) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -897,8 +932,9 @@ void CodeGeneratorRequest::SerializeWithCachedSizes( 1, this->file_to_generate(i), output); } + cached_has_bits = _has_bits_[0]; // optional string parameter = 2; - if (has_parameter()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->parameter().data(), this->parameter().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -908,7 +944,7 @@ void CodeGeneratorRequest::SerializeWithCachedSizes( } // optional .google.protobuf.compiler.Version compiler_version = 3; - if (has_compiler_version()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( 3, *this->compiler_version_, output); } @@ -928,8 +964,10 @@ 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; + // repeated string file_to_generate = 1; for (int i = 0, n = this->file_to_generate_size(); i < n; i++) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -940,8 +978,9 @@ void CodeGeneratorRequest::SerializeWithCachedSizes( WriteStringToArray(1, this->file_to_generate(i), target); } + cached_has_bits = _has_bits_[0]; // optional string parameter = 2; - if (has_parameter()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->parameter().data(), this->parameter().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -952,17 +991,17 @@ void CodeGeneratorRequest::SerializeWithCachedSizes( } // optional .google.protobuf.compiler.Version compiler_version = 3; - if (has_compiler_version()) { + if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 3, *this->compiler_version_, false, target); + 3, *this->compiler_version_, deterministic, target); } // repeated .google.protobuf.FileDescriptorProto proto_file = 15; for (unsigned int i = 0, n = this->proto_file_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 15, this->proto_file(i), false, target); + 15, this->proto_file(i), deterministic, target); } if (_internal_metadata_.have_unknown_fields()) { @@ -1043,14 +1082,18 @@ void CodeGeneratorRequest::MergeFrom(const CodeGeneratorRequest& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorRequest) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + file_to_generate_.MergeFrom(from.file_to_generate_); proto_file_.MergeFrom(from.proto_file_); - if (from._has_bits_[0 / 32] & 3u) { - if (from.has_parameter()) { + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 3u) { + if (cached_has_bits & 0x00000001u) { set_has_parameter(); parameter_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.parameter_); } - if (from.has_compiler_version()) { + if (cached_has_bits & 0x00000002u) { mutable_compiler_version()->::google::protobuf::compiler::Version::MergeFrom(from.compiler_version()); } } @@ -1080,8 +1123,8 @@ void CodeGeneratorRequest::Swap(CodeGeneratorRequest* other) { InternalSwap(other); } void CodeGeneratorRequest::InternalSwap(CodeGeneratorRequest* other) { - file_to_generate_.UnsafeArenaSwap(&other->file_to_generate_); - proto_file_.UnsafeArenaSwap(&other->proto_file_); + file_to_generate_.InternalSwap(&other->file_to_generate_); + proto_file_.InternalSwap(&other->proto_file_); parameter_.Swap(&other->parameter_); std::swap(compiler_version_, other->compiler_version_); std::swap(_has_bits_[0], other->_has_bits_[0]); @@ -1091,7 +1134,7 @@ void CodeGeneratorRequest::InternalSwap(CodeGeneratorRequest* other) { ::google::protobuf::Metadata CodeGeneratorRequest::GetMetadata() const { protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[1]; + return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -1123,6 +1166,7 @@ void CodeGeneratorRequest::set_file_to_generate(int index, ::std::string&& value } #endif void CodeGeneratorRequest::set_file_to_generate(int index, const char* value) { + GOOGLE_DCHECK(value != NULL); file_to_generate_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } @@ -1141,11 +1185,12 @@ void CodeGeneratorRequest::add_file_to_generate(const ::std::string& value) { } #if LANG_CXX11 void CodeGeneratorRequest::add_file_to_generate(::std::string&& value) { - file_to_generate_.Add()->assign(std::move(value)); + file_to_generate_.Add(std::move(value)); // @@protoc_insertion_point(field_add:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } #endif void CodeGeneratorRequest::add_file_to_generate(const char* value) { + GOOGLE_DCHECK(value != NULL); file_to_generate_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } @@ -1196,6 +1241,7 @@ void CodeGeneratorRequest::set_parameter(::std::string&& value) { } #endif void CodeGeneratorRequest::set_parameter(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_parameter(); parameter_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorRequest.parameter) @@ -1365,7 +1411,7 @@ void CodeGeneratorResponse_File::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* CodeGeneratorResponse_File::descriptor() { protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[2].descriptor; + return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const CodeGeneratorResponse_File& CodeGeneratorResponse_File::default_instance() { @@ -1484,8 +1530,12 @@ failure: void CodeGeneratorResponse_File::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.compiler.CodeGeneratorResponse.File) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; // optional string name = 1; - if (has_name()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->name().data(), this->name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -1495,7 +1545,7 @@ void CodeGeneratorResponse_File::SerializeWithCachedSizes( } // optional string insertion_point = 2; - if (has_insertion_point()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->insertion_point().data(), this->insertion_point().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -1505,7 +1555,7 @@ void CodeGeneratorResponse_File::SerializeWithCachedSizes( } // optional string content = 15; - if (has_content()) { + if (cached_has_bits & 0x00000004u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->content().data(), this->content().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -1523,10 +1573,13 @@ 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; + + cached_has_bits = _has_bits_[0]; // optional string name = 1; - if (has_name()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->name().data(), this->name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -1537,7 +1590,7 @@ void CodeGeneratorResponse_File::SerializeWithCachedSizes( } // optional string insertion_point = 2; - if (has_insertion_point()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->insertion_point().data(), this->insertion_point().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -1548,7 +1601,7 @@ void CodeGeneratorResponse_File::SerializeWithCachedSizes( } // optional string content = 15; - if (has_content()) { + if (cached_has_bits & 0x00000004u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->content().data(), this->content().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -1624,16 +1677,20 @@ void CodeGeneratorResponse_File::MergeFrom(const CodeGeneratorResponse_File& fro // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorResponse.File) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); - if (from._has_bits_[0 / 32] & 7u) { - if (from.has_name()) { + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 7u) { + if (cached_has_bits & 0x00000001u) { set_has_name(); name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); } - if (from.has_insertion_point()) { + if (cached_has_bits & 0x00000002u) { set_has_insertion_point(); insertion_point_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.insertion_point_); } - if (from.has_content()) { + if (cached_has_bits & 0x00000004u) { set_has_content(); content_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.content_); } @@ -1673,7 +1730,7 @@ void CodeGeneratorResponse_File::InternalSwap(CodeGeneratorResponse_File* other) ::google::protobuf::Metadata CodeGeneratorResponse_File::GetMetadata() const { protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[2]; + return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -1711,6 +1768,7 @@ void CodeGeneratorResponse_File::set_name(::std::string&& value) { } #endif void CodeGeneratorResponse_File::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorResponse.File.name) @@ -1773,6 +1831,7 @@ void CodeGeneratorResponse_File::set_insertion_point(::std::string&& value) { } #endif void CodeGeneratorResponse_File::set_insertion_point(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_insertion_point(); insertion_point_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point) @@ -1835,6 +1894,7 @@ void CodeGeneratorResponse_File::set_content(::std::string&& value) { } #endif void CodeGeneratorResponse_File::set_content(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_content(); content_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorResponse.File.content) @@ -1917,7 +1977,7 @@ void CodeGeneratorResponse::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* CodeGeneratorResponse::descriptor() { protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[3].descriptor; + return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const CodeGeneratorResponse& CodeGeneratorResponse::default_instance() { @@ -1974,13 +2034,11 @@ bool CodeGeneratorResponse::MergePartialFromCodedStream( case 15: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(122u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_file())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -2009,8 +2067,12 @@ failure: void CodeGeneratorResponse::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.compiler.CodeGeneratorResponse) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; // optional string error = 1; - if (has_error()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->error().data(), this->error().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -2034,10 +2096,13 @@ 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; + + cached_has_bits = _has_bits_[0]; // optional string error = 1; - if (has_error()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->error().data(), this->error().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -2051,7 +2116,7 @@ void CodeGeneratorResponse::SerializeWithCachedSizes( for (unsigned int i = 0, n = this->file_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 15, this->file(i), false, target); + 15, this->file(i), deterministic, target); } if (_internal_metadata_.have_unknown_fields()) { @@ -2115,6 +2180,9 @@ void CodeGeneratorResponse::MergeFrom(const CodeGeneratorResponse& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorResponse) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + file_.MergeFrom(from.file_); if (from.has_error()) { set_has_error(); @@ -2145,7 +2213,7 @@ void CodeGeneratorResponse::Swap(CodeGeneratorResponse* other) { InternalSwap(other); } void CodeGeneratorResponse::InternalSwap(CodeGeneratorResponse* other) { - file_.UnsafeArenaSwap(&other->file_); + file_.InternalSwap(&other->file_); error_.Swap(&other->error_); std::swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); @@ -2154,7 +2222,7 @@ void CodeGeneratorResponse::InternalSwap(CodeGeneratorResponse* other) { ::google::protobuf::Metadata CodeGeneratorResponse::GetMetadata() const { protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[3]; + return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -2192,6 +2260,7 @@ void CodeGeneratorResponse::set_error(::std::string&& value) { } #endif void CodeGeneratorResponse::set_error(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_error(); error_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorResponse.error) diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/plugin.pb.h b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/plugin.pb.h index ff8b949f2c..4f8befb6ed 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/plugin.pb.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/plugin.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3002000 +#if GOOGLE_PROTOBUF_VERSION < 3003000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003000 < 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. @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -137,6 +138,9 @@ namespace compiler { namespace protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto { // Internal implementation detail -- do not call these. struct LIBPROTOC_EXPORT TableStruct { + static const ::google::protobuf::internal::ParseTableField entries[]; + static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; + static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; static void InitDefaultsImpl(); static void Shutdown(); @@ -174,6 +178,8 @@ class LIBPROTOC_EXPORT Version : public ::google::protobuf::Message /* @@protoc_ return reinterpret_cast( &_Version_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 0; void Swap(Version* other); @@ -196,11 +202,6 @@ class LIBPROTOC_EXPORT Version : public ::google::protobuf::Message /* @@protoc_ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -307,6 +308,8 @@ class LIBPROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message return reinterpret_cast( &_CodeGeneratorRequest_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 1; void Swap(CodeGeneratorRequest* other); @@ -329,11 +332,6 @@ class LIBPROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -458,6 +456,8 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::M return reinterpret_cast( &_CodeGeneratorResponse_File_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 2; void Swap(CodeGeneratorResponse_File* other); @@ -480,11 +480,6 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::M ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -597,6 +592,8 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Messag return reinterpret_cast( &_CodeGeneratorResponse_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 3; void Swap(CodeGeneratorResponse* other); @@ -619,11 +616,6 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Messag ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -798,6 +790,7 @@ inline void Version::set_suffix(::std::string&& value) { } #endif inline void Version::set_suffix(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_suffix(); suffix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.Version.suffix) @@ -858,6 +851,7 @@ inline void CodeGeneratorRequest::set_file_to_generate(int index, ::std::string& } #endif inline void CodeGeneratorRequest::set_file_to_generate(int index, const char* value) { + GOOGLE_DCHECK(value != NULL); file_to_generate_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } @@ -876,11 +870,12 @@ inline void CodeGeneratorRequest::add_file_to_generate(const ::std::string& valu } #if LANG_CXX11 inline void CodeGeneratorRequest::add_file_to_generate(::std::string&& value) { - file_to_generate_.Add()->assign(std::move(value)); + file_to_generate_.Add(std::move(value)); // @@protoc_insertion_point(field_add:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } #endif inline void CodeGeneratorRequest::add_file_to_generate(const char* value) { + GOOGLE_DCHECK(value != NULL); file_to_generate_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } @@ -931,6 +926,7 @@ inline void CodeGeneratorRequest::set_parameter(::std::string&& value) { } #endif inline void CodeGeneratorRequest::set_parameter(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_parameter(); parameter_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorRequest.parameter) @@ -1072,6 +1068,7 @@ inline void CodeGeneratorResponse_File::set_name(::std::string&& value) { } #endif inline void CodeGeneratorResponse_File::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorResponse.File.name) @@ -1134,6 +1131,7 @@ inline void CodeGeneratorResponse_File::set_insertion_point(::std::string&& valu } #endif inline void CodeGeneratorResponse_File::set_insertion_point(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_insertion_point(); insertion_point_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point) @@ -1196,6 +1194,7 @@ inline void CodeGeneratorResponse_File::set_content(::std::string&& value) { } #endif inline void CodeGeneratorResponse_File::set_content(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_content(); content_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorResponse.File.content) @@ -1262,6 +1261,7 @@ inline void CodeGeneratorResponse::set_error(::std::string&& value) { } #endif inline void CodeGeneratorResponse::set_error(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_error(); error_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorResponse.error) diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/plugin.proto b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/plugin.proto index bf91d76e0f..f04dc73c8c 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/plugin.proto +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/plugin.proto @@ -84,6 +84,9 @@ message CodeGeneratorRequest { // the entire set into memory at once. However, as of this writing, this // is not similarly optimized on protoc's end -- it will store all fields in // memory at once before sending them to the plugin. + // + // Type names of fields and extensions in the FileDescriptorProto are always + // fully qualified. repeated FileDescriptorProto proto_file = 15; // The version number of protocol compiler. diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/profile.pb.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/profile.pb.cc new file mode 100644 index 0000000000..c185e4f910 --- /dev/null +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/profile.pb.cc @@ -0,0 +1,1442 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/compiler/profile.proto + +#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +// @@protoc_insertion_point(includes) + +namespace google { +namespace protobuf { +namespace compiler { +class FieldAccessInfoDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed { +} _FieldAccessInfo_default_instance_; +class MessageAccessInfoDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed { +} _MessageAccessInfo_default_instance_; +class AccessInfoDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed { +} _AccessInfo_default_instance_; + +namespace protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto { + + +namespace { + +::google::protobuf::Metadata file_level_metadata[3]; + +} // namespace + +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField + const TableStruct::entries[] = { + {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, +}; + +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField + const TableStruct::aux[] = { + ::google::protobuf::internal::AuxillaryParseTableField(), +}; +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const + TableStruct::schema[] = { + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, +}; + +const ::google::protobuf::uint32 TableStruct::offsets[] = { + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldAccessInfo, _has_bits_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldAccessInfo, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldAccessInfo, name_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldAccessInfo, getters_count_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldAccessInfo, setters_count_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldAccessInfo, configs_count_), + 0, + 1, + 2, + 3, + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageAccessInfo, _has_bits_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageAccessInfo, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageAccessInfo, name_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageAccessInfo, count_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageAccessInfo, field_), + 0, + 1, + ~0u, + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AccessInfo, _has_bits_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AccessInfo, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AccessInfo, message_), + ~0u, +}; + +static const ::google::protobuf::internal::MigrationSchema schemas[] = { + { 0, 9, sizeof(FieldAccessInfo)}, + { 13, 21, sizeof(MessageAccessInfo)}, + { 24, 30, sizeof(AccessInfo)}, +}; + +static ::google::protobuf::Message const * const file_default_instances[] = { + reinterpret_cast(&_FieldAccessInfo_default_instance_), + reinterpret_cast(&_MessageAccessInfo_default_instance_), + reinterpret_cast(&_AccessInfo_default_instance_), +}; + +namespace { + +void protobuf_AssignDescriptors() { + AddDescriptors(); + ::google::protobuf::MessageFactory* factory = NULL; + AssignDescriptors( + "google/protobuf/compiler/profile.proto", schemas, file_default_instances, TableStruct::offsets, factory, + file_level_metadata, NULL, NULL); +} + +void protobuf_AssignDescriptorsOnce() { + static GOOGLE_PROTOBUF_DECLARE_ONCE(once); + ::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors); +} + +void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; +void protobuf_RegisterTypes(const ::std::string&) { + protobuf_AssignDescriptorsOnce(); + ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 3); +} + +} // namespace + +void TableStruct::Shutdown() { + _FieldAccessInfo_default_instance_.Shutdown(); + delete file_level_metadata[0].reflection; + _MessageAccessInfo_default_instance_.Shutdown(); + delete file_level_metadata[1].reflection; + _AccessInfo_default_instance_.Shutdown(); + delete file_level_metadata[2].reflection; +} + +void TableStruct::InitDefaultsImpl() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + + ::google::protobuf::internal::InitProtobufDefaults(); + _FieldAccessInfo_default_instance_.DefaultConstruct(); + _MessageAccessInfo_default_instance_.DefaultConstruct(); + _AccessInfo_default_instance_.DefaultConstruct(); +} + +void InitDefaults() { + static GOOGLE_PROTOBUF_DECLARE_ONCE(once); + ::google::protobuf::GoogleOnceInit(&once, &TableStruct::InitDefaultsImpl); +} +void AddDescriptorsImpl() { + InitDefaults(); + static const char descriptor[] = { + "\n&google/protobuf/compiler/profile.proto" + "\022\030google.protobuf.compiler\"d\n\017FieldAcces" + "sInfo\022\014\n\004name\030\001 \001(\t\022\025\n\rgetters_count\030\002 \001" + "(\004\022\025\n\rsetters_count\030\003 \001(\004\022\025\n\rconfigs_cou" + "nt\030\004 \001(\004\"j\n\021MessageAccessInfo\022\014\n\004name\030\001 " + "\001(\t\022\r\n\005count\030\002 \001(\004\0228\n\005field\030\003 \003(\0132).goog" + "le.protobuf.compiler.FieldAccessInfo\"J\n\n" + "AccessInfo\022<\n\007message\030\001 \003(\0132+.google.pro" + "tobuf.compiler.MessageAccessInfo" + }; + ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( + descriptor, 352); + ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( + "google/protobuf/compiler/profile.proto", &protobuf_RegisterTypes); + ::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown); +} + +void AddDescriptors() { + static GOOGLE_PROTOBUF_DECLARE_ONCE(once); + ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); +} +// Force AddDescriptors() to be called at static initialization time. +struct StaticDescriptorInitializer { + StaticDescriptorInitializer() { + AddDescriptors(); + } +} static_descriptor_initializer; + +} // namespace protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto + + +// =================================================================== + +#if !defined(_MSC_VER) || _MSC_VER >= 1900 +const int FieldAccessInfo::kNameFieldNumber; +const int FieldAccessInfo::kGettersCountFieldNumber; +const int FieldAccessInfo::kSettersCountFieldNumber; +const int FieldAccessInfo::kConfigsCountFieldNumber; +#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 + +FieldAccessInfo::FieldAccessInfo() + : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) { + protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::InitDefaults(); + } + SharedCtor(); + // @@protoc_insertion_point(constructor:google.protobuf.compiler.FieldAccessInfo) +} +FieldAccessInfo::FieldAccessInfo(const FieldAccessInfo& from) + : ::google::protobuf::Message(), + _internal_metadata_(NULL), + _has_bits_(from._has_bits_), + _cached_size_(0) { + _internal_metadata_.MergeFrom(from._internal_metadata_); + name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + if (from.has_name()) { + name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); + } + ::memcpy(&getters_count_, &from.getters_count_, + reinterpret_cast(&configs_count_) - + reinterpret_cast(&getters_count_) + sizeof(configs_count_)); + // @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.FieldAccessInfo) +} + +void FieldAccessInfo::SharedCtor() { + _cached_size_ = 0; + name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + ::memset(&getters_count_, 0, reinterpret_cast(&configs_count_) - + reinterpret_cast(&getters_count_) + sizeof(configs_count_)); +} + +FieldAccessInfo::~FieldAccessInfo() { + // @@protoc_insertion_point(destructor:google.protobuf.compiler.FieldAccessInfo) + SharedDtor(); +} + +void FieldAccessInfo::SharedDtor() { + name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} + +void FieldAccessInfo::SetCachedSize(int size) const { + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); +} +const ::google::protobuf::Descriptor* FieldAccessInfo::descriptor() { + protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::protobuf_AssignDescriptorsOnce(); + return protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; +} + +const FieldAccessInfo& FieldAccessInfo::default_instance() { + protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::InitDefaults(); + return *internal_default_instance(); +} + +FieldAccessInfo* FieldAccessInfo::New(::google::protobuf::Arena* arena) const { + FieldAccessInfo* n = new FieldAccessInfo; + if (arena != NULL) { + arena->Own(n); + } + return n; +} + +void FieldAccessInfo::Clear() { +// @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.FieldAccessInfo) + if (has_name()) { + GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); + (*name_.UnsafeRawStringPointer())->clear(); + } + if (_has_bits_[0 / 32] & 14u) { + ::memset(&getters_count_, 0, reinterpret_cast(&configs_count_) - + reinterpret_cast(&getters_count_) + sizeof(configs_count_)); + } + _has_bits_.Clear(); + _internal_metadata_.Clear(); +} + +bool FieldAccessInfo::MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) { +#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure + ::google::protobuf::uint32 tag; + // @@protoc_insertion_point(parse_start:google.protobuf.compiler.FieldAccessInfo) + for (;;) { + ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); + tag = p.first; + if (!p.second) goto handle_unusual; + switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { + // optional string name = 1; + case 1: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(10u)) { + DO_(::google::protobuf::internal::WireFormatLite::ReadString( + input, this->mutable_name())); + ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( + this->name().data(), this->name().length(), + ::google::protobuf::internal::WireFormat::PARSE, + "google.protobuf.compiler.FieldAccessInfo.name"); + } else { + goto handle_unusual; + } + break; + } + + // optional uint64 getters_count = 2; + case 2: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(16u)) { + set_has_getters_count(); + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_UINT64>( + input, &getters_count_))); + } else { + goto handle_unusual; + } + break; + } + + // optional uint64 setters_count = 3; + case 3: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(24u)) { + set_has_setters_count(); + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_UINT64>( + input, &setters_count_))); + } else { + goto handle_unusual; + } + break; + } + + // optional uint64 configs_count = 4; + case 4: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(32u)) { + set_has_configs_count(); + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_UINT64>( + input, &configs_count_))); + } else { + goto handle_unusual; + } + break; + } + + default: { + handle_unusual: + if (tag == 0 || + ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == + ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + goto success; + } + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, mutable_unknown_fields())); + break; + } + } + } +success: + // @@protoc_insertion_point(parse_success:google.protobuf.compiler.FieldAccessInfo) + return true; +failure: + // @@protoc_insertion_point(parse_failure:google.protobuf.compiler.FieldAccessInfo) + return false; +#undef DO_ +} + +void FieldAccessInfo::SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const { + // @@protoc_insertion_point(serialize_start:google.protobuf.compiler.FieldAccessInfo) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; + // optional string name = 1; + if (cached_has_bits & 0x00000001u) { + ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( + this->name().data(), this->name().length(), + ::google::protobuf::internal::WireFormat::SERIALIZE, + "google.protobuf.compiler.FieldAccessInfo.name"); + ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased( + 1, this->name(), output); + } + + // optional uint64 getters_count = 2; + if (cached_has_bits & 0x00000002u) { + ::google::protobuf::internal::WireFormatLite::WriteUInt64(2, this->getters_count(), output); + } + + // optional uint64 setters_count = 3; + if (cached_has_bits & 0x00000004u) { + ::google::protobuf::internal::WireFormatLite::WriteUInt64(3, this->setters_count(), output); + } + + // optional uint64 configs_count = 4; + if (cached_has_bits & 0x00000008u) { + ::google::protobuf::internal::WireFormatLite::WriteUInt64(4, this->configs_count(), output); + } + + if (_internal_metadata_.have_unknown_fields()) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + unknown_fields(), output); + } + // @@protoc_insertion_point(serialize_end:google.protobuf.compiler.FieldAccessInfo) +} + +::google::protobuf::uint8* FieldAccessInfo::InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const { + // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.FieldAccessInfo) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; + // optional string name = 1; + if (cached_has_bits & 0x00000001u) { + ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( + this->name().data(), this->name().length(), + ::google::protobuf::internal::WireFormat::SERIALIZE, + "google.protobuf.compiler.FieldAccessInfo.name"); + target = + ::google::protobuf::internal::WireFormatLite::WriteStringToArray( + 1, this->name(), target); + } + + // optional uint64 getters_count = 2; + if (cached_has_bits & 0x00000002u) { + target = ::google::protobuf::internal::WireFormatLite::WriteUInt64ToArray(2, this->getters_count(), target); + } + + // optional uint64 setters_count = 3; + if (cached_has_bits & 0x00000004u) { + target = ::google::protobuf::internal::WireFormatLite::WriteUInt64ToArray(3, this->setters_count(), target); + } + + // optional uint64 configs_count = 4; + if (cached_has_bits & 0x00000008u) { + target = ::google::protobuf::internal::WireFormatLite::WriteUInt64ToArray(4, this->configs_count(), target); + } + + if (_internal_metadata_.have_unknown_fields()) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + unknown_fields(), target); + } + // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.compiler.FieldAccessInfo) + return target; +} + +size_t FieldAccessInfo::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:google.protobuf.compiler.FieldAccessInfo) + size_t total_size = 0; + + if (_internal_metadata_.have_unknown_fields()) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + unknown_fields()); + } + if (_has_bits_[0 / 32] & 15u) { + // optional string name = 1; + if (has_name()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::StringSize( + this->name()); + } + + // optional uint64 getters_count = 2; + if (has_getters_count()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::UInt64Size( + this->getters_count()); + } + + // optional uint64 setters_count = 3; + if (has_setters_count()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::UInt64Size( + this->setters_count()); + } + + // optional uint64 configs_count = 4; + if (has_configs_count()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::UInt64Size( + this->configs_count()); + } + + } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = cached_size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); + return total_size; +} + +void FieldAccessInfo::MergeFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.compiler.FieldAccessInfo) + GOOGLE_DCHECK_NE(&from, this); + const FieldAccessInfo* source = + ::google::protobuf::internal::DynamicCastToGenerated( + &from); + if (source == NULL) { + // @@protoc_insertion_point(generalized_merge_from_cast_fail:google.protobuf.compiler.FieldAccessInfo) + ::google::protobuf::internal::ReflectionOps::Merge(from, this); + } else { + // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.compiler.FieldAccessInfo) + MergeFrom(*source); + } +} + +void FieldAccessInfo::MergeFrom(const FieldAccessInfo& from) { +// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.FieldAccessInfo) + GOOGLE_DCHECK_NE(&from, this); + _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 15u) { + if (cached_has_bits & 0x00000001u) { + set_has_name(); + name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); + } + if (cached_has_bits & 0x00000002u) { + getters_count_ = from.getters_count_; + } + if (cached_has_bits & 0x00000004u) { + setters_count_ = from.setters_count_; + } + if (cached_has_bits & 0x00000008u) { + configs_count_ = from.configs_count_; + } + _has_bits_[0] |= cached_has_bits; + } +} + +void FieldAccessInfo::CopyFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_copy_from_start:google.protobuf.compiler.FieldAccessInfo) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void FieldAccessInfo::CopyFrom(const FieldAccessInfo& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.compiler.FieldAccessInfo) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool FieldAccessInfo::IsInitialized() const { + return true; +} + +void FieldAccessInfo::Swap(FieldAccessInfo* other) { + if (other == this) return; + InternalSwap(other); +} +void FieldAccessInfo::InternalSwap(FieldAccessInfo* other) { + name_.Swap(&other->name_); + std::swap(getters_count_, other->getters_count_); + std::swap(setters_count_, other->setters_count_); + std::swap(configs_count_, other->configs_count_); + std::swap(_has_bits_[0], other->_has_bits_[0]); + _internal_metadata_.Swap(&other->_internal_metadata_); + std::swap(_cached_size_, other->_cached_size_); +} + +::google::protobuf::Metadata FieldAccessInfo::GetMetadata() const { + protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::protobuf_AssignDescriptorsOnce(); + return protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::file_level_metadata[kIndexInFileMessages]; +} + +#if PROTOBUF_INLINE_NOT_IN_HEADERS +// FieldAccessInfo + +// optional string name = 1; +bool FieldAccessInfo::has_name() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +void FieldAccessInfo::set_has_name() { + _has_bits_[0] |= 0x00000001u; +} +void FieldAccessInfo::clear_has_name() { + _has_bits_[0] &= ~0x00000001u; +} +void FieldAccessInfo::clear_name() { + name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + clear_has_name(); +} +const ::std::string& FieldAccessInfo::name() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.FieldAccessInfo.name) + return name_.GetNoArena(); +} +void FieldAccessInfo::set_name(const ::std::string& value) { + set_has_name(); + name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + // @@protoc_insertion_point(field_set:google.protobuf.compiler.FieldAccessInfo.name) +} +#if LANG_CXX11 +void FieldAccessInfo::set_name(::std::string&& value) { + set_has_name(); + name_.SetNoArena( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.compiler.FieldAccessInfo.name) +} +#endif +void FieldAccessInfo::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); + set_has_name(); + name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.FieldAccessInfo.name) +} +void FieldAccessInfo::set_name(const char* value, size_t size) { + set_has_name(); + name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast(value), size)); + // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.FieldAccessInfo.name) +} +::std::string* FieldAccessInfo::mutable_name() { + set_has_name(); + // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.FieldAccessInfo.name) + return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +::std::string* FieldAccessInfo::release_name() { + // @@protoc_insertion_point(field_release:google.protobuf.compiler.FieldAccessInfo.name) + clear_has_name(); + return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +void FieldAccessInfo::set_allocated_name(::std::string* name) { + if (name != NULL) { + set_has_name(); + } else { + clear_has_name(); + } + name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); + // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.FieldAccessInfo.name) +} + +// optional uint64 getters_count = 2; +bool FieldAccessInfo::has_getters_count() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +void FieldAccessInfo::set_has_getters_count() { + _has_bits_[0] |= 0x00000002u; +} +void FieldAccessInfo::clear_has_getters_count() { + _has_bits_[0] &= ~0x00000002u; +} +void FieldAccessInfo::clear_getters_count() { + getters_count_ = GOOGLE_ULONGLONG(0); + clear_has_getters_count(); +} +::google::protobuf::uint64 FieldAccessInfo::getters_count() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.FieldAccessInfo.getters_count) + return getters_count_; +} +void FieldAccessInfo::set_getters_count(::google::protobuf::uint64 value) { + set_has_getters_count(); + getters_count_ = value; + // @@protoc_insertion_point(field_set:google.protobuf.compiler.FieldAccessInfo.getters_count) +} + +// optional uint64 setters_count = 3; +bool FieldAccessInfo::has_setters_count() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +void FieldAccessInfo::set_has_setters_count() { + _has_bits_[0] |= 0x00000004u; +} +void FieldAccessInfo::clear_has_setters_count() { + _has_bits_[0] &= ~0x00000004u; +} +void FieldAccessInfo::clear_setters_count() { + setters_count_ = GOOGLE_ULONGLONG(0); + clear_has_setters_count(); +} +::google::protobuf::uint64 FieldAccessInfo::setters_count() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.FieldAccessInfo.setters_count) + return setters_count_; +} +void FieldAccessInfo::set_setters_count(::google::protobuf::uint64 value) { + set_has_setters_count(); + setters_count_ = value; + // @@protoc_insertion_point(field_set:google.protobuf.compiler.FieldAccessInfo.setters_count) +} + +// optional uint64 configs_count = 4; +bool FieldAccessInfo::has_configs_count() const { + return (_has_bits_[0] & 0x00000008u) != 0; +} +void FieldAccessInfo::set_has_configs_count() { + _has_bits_[0] |= 0x00000008u; +} +void FieldAccessInfo::clear_has_configs_count() { + _has_bits_[0] &= ~0x00000008u; +} +void FieldAccessInfo::clear_configs_count() { + configs_count_ = GOOGLE_ULONGLONG(0); + clear_has_configs_count(); +} +::google::protobuf::uint64 FieldAccessInfo::configs_count() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.FieldAccessInfo.configs_count) + return configs_count_; +} +void FieldAccessInfo::set_configs_count(::google::protobuf::uint64 value) { + set_has_configs_count(); + configs_count_ = value; + // @@protoc_insertion_point(field_set:google.protobuf.compiler.FieldAccessInfo.configs_count) +} + +#endif // PROTOBUF_INLINE_NOT_IN_HEADERS + +// =================================================================== + +#if !defined(_MSC_VER) || _MSC_VER >= 1900 +const int MessageAccessInfo::kNameFieldNumber; +const int MessageAccessInfo::kCountFieldNumber; +const int MessageAccessInfo::kFieldFieldNumber; +#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 + +MessageAccessInfo::MessageAccessInfo() + : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) { + protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::InitDefaults(); + } + SharedCtor(); + // @@protoc_insertion_point(constructor:google.protobuf.compiler.MessageAccessInfo) +} +MessageAccessInfo::MessageAccessInfo(const MessageAccessInfo& from) + : ::google::protobuf::Message(), + _internal_metadata_(NULL), + _has_bits_(from._has_bits_), + _cached_size_(0), + field_(from.field_) { + _internal_metadata_.MergeFrom(from._internal_metadata_); + name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + if (from.has_name()) { + name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); + } + count_ = from.count_; + // @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.MessageAccessInfo) +} + +void MessageAccessInfo::SharedCtor() { + _cached_size_ = 0; + name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + count_ = GOOGLE_ULONGLONG(0); +} + +MessageAccessInfo::~MessageAccessInfo() { + // @@protoc_insertion_point(destructor:google.protobuf.compiler.MessageAccessInfo) + SharedDtor(); +} + +void MessageAccessInfo::SharedDtor() { + name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} + +void MessageAccessInfo::SetCachedSize(int size) const { + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); +} +const ::google::protobuf::Descriptor* MessageAccessInfo::descriptor() { + protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::protobuf_AssignDescriptorsOnce(); + return protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; +} + +const MessageAccessInfo& MessageAccessInfo::default_instance() { + protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::InitDefaults(); + return *internal_default_instance(); +} + +MessageAccessInfo* MessageAccessInfo::New(::google::protobuf::Arena* arena) const { + MessageAccessInfo* n = new MessageAccessInfo; + if (arena != NULL) { + arena->Own(n); + } + return n; +} + +void MessageAccessInfo::Clear() { +// @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.MessageAccessInfo) + field_.Clear(); + if (has_name()) { + GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); + (*name_.UnsafeRawStringPointer())->clear(); + } + count_ = GOOGLE_ULONGLONG(0); + _has_bits_.Clear(); + _internal_metadata_.Clear(); +} + +bool MessageAccessInfo::MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) { +#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure + ::google::protobuf::uint32 tag; + // @@protoc_insertion_point(parse_start:google.protobuf.compiler.MessageAccessInfo) + for (;;) { + ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); + tag = p.first; + if (!p.second) goto handle_unusual; + switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { + // optional string name = 1; + case 1: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(10u)) { + DO_(::google::protobuf::internal::WireFormatLite::ReadString( + input, this->mutable_name())); + ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( + this->name().data(), this->name().length(), + ::google::protobuf::internal::WireFormat::PARSE, + "google.protobuf.compiler.MessageAccessInfo.name"); + } else { + goto handle_unusual; + } + break; + } + + // optional uint64 count = 2; + case 2: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(16u)) { + set_has_count(); + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_UINT64>( + input, &count_))); + } else { + goto handle_unusual; + } + break; + } + + // repeated .google.protobuf.compiler.FieldAccessInfo field = 3; + case 3: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(26u)) { + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + input, add_field())); + } else { + goto handle_unusual; + } + break; + } + + default: { + handle_unusual: + if (tag == 0 || + ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == + ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + goto success; + } + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, mutable_unknown_fields())); + break; + } + } + } +success: + // @@protoc_insertion_point(parse_success:google.protobuf.compiler.MessageAccessInfo) + return true; +failure: + // @@protoc_insertion_point(parse_failure:google.protobuf.compiler.MessageAccessInfo) + return false; +#undef DO_ +} + +void MessageAccessInfo::SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const { + // @@protoc_insertion_point(serialize_start:google.protobuf.compiler.MessageAccessInfo) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; + // optional string name = 1; + if (cached_has_bits & 0x00000001u) { + ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( + this->name().data(), this->name().length(), + ::google::protobuf::internal::WireFormat::SERIALIZE, + "google.protobuf.compiler.MessageAccessInfo.name"); + ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased( + 1, this->name(), output); + } + + // optional uint64 count = 2; + if (cached_has_bits & 0x00000002u) { + ::google::protobuf::internal::WireFormatLite::WriteUInt64(2, this->count(), output); + } + + // repeated .google.protobuf.compiler.FieldAccessInfo field = 3; + for (unsigned int i = 0, n = this->field_size(); i < n; i++) { + ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( + 3, this->field(i), output); + } + + if (_internal_metadata_.have_unknown_fields()) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + unknown_fields(), output); + } + // @@protoc_insertion_point(serialize_end:google.protobuf.compiler.MessageAccessInfo) +} + +::google::protobuf::uint8* MessageAccessInfo::InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const { + // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.MessageAccessInfo) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; + // optional string name = 1; + if (cached_has_bits & 0x00000001u) { + ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( + this->name().data(), this->name().length(), + ::google::protobuf::internal::WireFormat::SERIALIZE, + "google.protobuf.compiler.MessageAccessInfo.name"); + target = + ::google::protobuf::internal::WireFormatLite::WriteStringToArray( + 1, this->name(), target); + } + + // optional uint64 count = 2; + if (cached_has_bits & 0x00000002u) { + target = ::google::protobuf::internal::WireFormatLite::WriteUInt64ToArray(2, this->count(), target); + } + + // repeated .google.protobuf.compiler.FieldAccessInfo field = 3; + for (unsigned int i = 0, n = this->field_size(); i < n; i++) { + target = ::google::protobuf::internal::WireFormatLite:: + InternalWriteMessageNoVirtualToArray( + 3, this->field(i), deterministic, target); + } + + if (_internal_metadata_.have_unknown_fields()) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + unknown_fields(), target); + } + // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.compiler.MessageAccessInfo) + return target; +} + +size_t MessageAccessInfo::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:google.protobuf.compiler.MessageAccessInfo) + size_t total_size = 0; + + if (_internal_metadata_.have_unknown_fields()) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + unknown_fields()); + } + // repeated .google.protobuf.compiler.FieldAccessInfo field = 3; + { + unsigned int count = this->field_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->field(i)); + } + } + + if (_has_bits_[0 / 32] & 3u) { + // optional string name = 1; + if (has_name()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::StringSize( + this->name()); + } + + // optional uint64 count = 2; + if (has_count()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::UInt64Size( + this->count()); + } + + } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = cached_size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); + return total_size; +} + +void MessageAccessInfo::MergeFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.compiler.MessageAccessInfo) + GOOGLE_DCHECK_NE(&from, this); + const MessageAccessInfo* source = + ::google::protobuf::internal::DynamicCastToGenerated( + &from); + if (source == NULL) { + // @@protoc_insertion_point(generalized_merge_from_cast_fail:google.protobuf.compiler.MessageAccessInfo) + ::google::protobuf::internal::ReflectionOps::Merge(from, this); + } else { + // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.compiler.MessageAccessInfo) + MergeFrom(*source); + } +} + +void MessageAccessInfo::MergeFrom(const MessageAccessInfo& from) { +// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.MessageAccessInfo) + GOOGLE_DCHECK_NE(&from, this); + _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + field_.MergeFrom(from.field_); + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 3u) { + if (cached_has_bits & 0x00000001u) { + set_has_name(); + name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); + } + if (cached_has_bits & 0x00000002u) { + count_ = from.count_; + } + _has_bits_[0] |= cached_has_bits; + } +} + +void MessageAccessInfo::CopyFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_copy_from_start:google.protobuf.compiler.MessageAccessInfo) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void MessageAccessInfo::CopyFrom(const MessageAccessInfo& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.compiler.MessageAccessInfo) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool MessageAccessInfo::IsInitialized() const { + return true; +} + +void MessageAccessInfo::Swap(MessageAccessInfo* other) { + if (other == this) return; + InternalSwap(other); +} +void MessageAccessInfo::InternalSwap(MessageAccessInfo* other) { + field_.InternalSwap(&other->field_); + name_.Swap(&other->name_); + std::swap(count_, other->count_); + std::swap(_has_bits_[0], other->_has_bits_[0]); + _internal_metadata_.Swap(&other->_internal_metadata_); + std::swap(_cached_size_, other->_cached_size_); +} + +::google::protobuf::Metadata MessageAccessInfo::GetMetadata() const { + protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::protobuf_AssignDescriptorsOnce(); + return protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::file_level_metadata[kIndexInFileMessages]; +} + +#if PROTOBUF_INLINE_NOT_IN_HEADERS +// MessageAccessInfo + +// optional string name = 1; +bool MessageAccessInfo::has_name() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +void MessageAccessInfo::set_has_name() { + _has_bits_[0] |= 0x00000001u; +} +void MessageAccessInfo::clear_has_name() { + _has_bits_[0] &= ~0x00000001u; +} +void MessageAccessInfo::clear_name() { + name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + clear_has_name(); +} +const ::std::string& MessageAccessInfo::name() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.MessageAccessInfo.name) + return name_.GetNoArena(); +} +void MessageAccessInfo::set_name(const ::std::string& value) { + set_has_name(); + name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + // @@protoc_insertion_point(field_set:google.protobuf.compiler.MessageAccessInfo.name) +} +#if LANG_CXX11 +void MessageAccessInfo::set_name(::std::string&& value) { + set_has_name(); + name_.SetNoArena( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.compiler.MessageAccessInfo.name) +} +#endif +void MessageAccessInfo::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); + set_has_name(); + name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.MessageAccessInfo.name) +} +void MessageAccessInfo::set_name(const char* value, size_t size) { + set_has_name(); + name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast(value), size)); + // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.MessageAccessInfo.name) +} +::std::string* MessageAccessInfo::mutable_name() { + set_has_name(); + // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.MessageAccessInfo.name) + return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +::std::string* MessageAccessInfo::release_name() { + // @@protoc_insertion_point(field_release:google.protobuf.compiler.MessageAccessInfo.name) + clear_has_name(); + return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +void MessageAccessInfo::set_allocated_name(::std::string* name) { + if (name != NULL) { + set_has_name(); + } else { + clear_has_name(); + } + name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); + // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.MessageAccessInfo.name) +} + +// optional uint64 count = 2; +bool MessageAccessInfo::has_count() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +void MessageAccessInfo::set_has_count() { + _has_bits_[0] |= 0x00000002u; +} +void MessageAccessInfo::clear_has_count() { + _has_bits_[0] &= ~0x00000002u; +} +void MessageAccessInfo::clear_count() { + count_ = GOOGLE_ULONGLONG(0); + clear_has_count(); +} +::google::protobuf::uint64 MessageAccessInfo::count() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.MessageAccessInfo.count) + return count_; +} +void MessageAccessInfo::set_count(::google::protobuf::uint64 value) { + set_has_count(); + count_ = value; + // @@protoc_insertion_point(field_set:google.protobuf.compiler.MessageAccessInfo.count) +} + +// repeated .google.protobuf.compiler.FieldAccessInfo field = 3; +int MessageAccessInfo::field_size() const { + return field_.size(); +} +void MessageAccessInfo::clear_field() { + field_.Clear(); +} +const ::google::protobuf::compiler::FieldAccessInfo& MessageAccessInfo::field(int index) const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.MessageAccessInfo.field) + return field_.Get(index); +} +::google::protobuf::compiler::FieldAccessInfo* MessageAccessInfo::mutable_field(int index) { + // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.MessageAccessInfo.field) + return field_.Mutable(index); +} +::google::protobuf::compiler::FieldAccessInfo* MessageAccessInfo::add_field() { + // @@protoc_insertion_point(field_add:google.protobuf.compiler.MessageAccessInfo.field) + return field_.Add(); +} +::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::FieldAccessInfo >* +MessageAccessInfo::mutable_field() { + // @@protoc_insertion_point(field_mutable_list:google.protobuf.compiler.MessageAccessInfo.field) + return &field_; +} +const ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::FieldAccessInfo >& +MessageAccessInfo::field() const { + // @@protoc_insertion_point(field_list:google.protobuf.compiler.MessageAccessInfo.field) + return field_; +} + +#endif // PROTOBUF_INLINE_NOT_IN_HEADERS + +// =================================================================== + +#if !defined(_MSC_VER) || _MSC_VER >= 1900 +const int AccessInfo::kMessageFieldNumber; +#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 + +AccessInfo::AccessInfo() + : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) { + protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::InitDefaults(); + } + SharedCtor(); + // @@protoc_insertion_point(constructor:google.protobuf.compiler.AccessInfo) +} +AccessInfo::AccessInfo(const AccessInfo& from) + : ::google::protobuf::Message(), + _internal_metadata_(NULL), + _has_bits_(from._has_bits_), + _cached_size_(0), + message_(from.message_) { + _internal_metadata_.MergeFrom(from._internal_metadata_); + // @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.AccessInfo) +} + +void AccessInfo::SharedCtor() { + _cached_size_ = 0; +} + +AccessInfo::~AccessInfo() { + // @@protoc_insertion_point(destructor:google.protobuf.compiler.AccessInfo) + SharedDtor(); +} + +void AccessInfo::SharedDtor() { +} + +void AccessInfo::SetCachedSize(int size) const { + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); +} +const ::google::protobuf::Descriptor* AccessInfo::descriptor() { + protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::protobuf_AssignDescriptorsOnce(); + return protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; +} + +const AccessInfo& AccessInfo::default_instance() { + protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::InitDefaults(); + return *internal_default_instance(); +} + +AccessInfo* AccessInfo::New(::google::protobuf::Arena* arena) const { + AccessInfo* n = new AccessInfo; + if (arena != NULL) { + arena->Own(n); + } + return n; +} + +void AccessInfo::Clear() { +// @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.AccessInfo) + message_.Clear(); + _has_bits_.Clear(); + _internal_metadata_.Clear(); +} + +bool AccessInfo::MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) { +#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure + ::google::protobuf::uint32 tag; + // @@protoc_insertion_point(parse_start:google.protobuf.compiler.AccessInfo) + for (;;) { + ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); + tag = p.first; + if (!p.second) goto handle_unusual; + switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { + // repeated .google.protobuf.compiler.MessageAccessInfo message = 1; + case 1: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(10u)) { + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + input, add_message())); + } else { + goto handle_unusual; + } + break; + } + + default: { + handle_unusual: + if (tag == 0 || + ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == + ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + goto success; + } + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, mutable_unknown_fields())); + break; + } + } + } +success: + // @@protoc_insertion_point(parse_success:google.protobuf.compiler.AccessInfo) + return true; +failure: + // @@protoc_insertion_point(parse_failure:google.protobuf.compiler.AccessInfo) + return false; +#undef DO_ +} + +void AccessInfo::SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const { + // @@protoc_insertion_point(serialize_start:google.protobuf.compiler.AccessInfo) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // repeated .google.protobuf.compiler.MessageAccessInfo message = 1; + for (unsigned int i = 0, n = this->message_size(); i < n; i++) { + ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( + 1, this->message(i), output); + } + + if (_internal_metadata_.have_unknown_fields()) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + unknown_fields(), output); + } + // @@protoc_insertion_point(serialize_end:google.protobuf.compiler.AccessInfo) +} + +::google::protobuf::uint8* AccessInfo::InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const { + // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.AccessInfo) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // repeated .google.protobuf.compiler.MessageAccessInfo message = 1; + for (unsigned int i = 0, n = this->message_size(); i < n; i++) { + target = ::google::protobuf::internal::WireFormatLite:: + InternalWriteMessageNoVirtualToArray( + 1, this->message(i), deterministic, target); + } + + if (_internal_metadata_.have_unknown_fields()) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + unknown_fields(), target); + } + // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.compiler.AccessInfo) + return target; +} + +size_t AccessInfo::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:google.protobuf.compiler.AccessInfo) + size_t total_size = 0; + + if (_internal_metadata_.have_unknown_fields()) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + unknown_fields()); + } + // repeated .google.protobuf.compiler.MessageAccessInfo message = 1; + { + unsigned int count = this->message_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->message(i)); + } + } + + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = cached_size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); + return total_size; +} + +void AccessInfo::MergeFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.compiler.AccessInfo) + GOOGLE_DCHECK_NE(&from, this); + const AccessInfo* source = + ::google::protobuf::internal::DynamicCastToGenerated( + &from); + if (source == NULL) { + // @@protoc_insertion_point(generalized_merge_from_cast_fail:google.protobuf.compiler.AccessInfo) + ::google::protobuf::internal::ReflectionOps::Merge(from, this); + } else { + // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.compiler.AccessInfo) + MergeFrom(*source); + } +} + +void AccessInfo::MergeFrom(const AccessInfo& from) { +// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.AccessInfo) + GOOGLE_DCHECK_NE(&from, this); + _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + message_.MergeFrom(from.message_); +} + +void AccessInfo::CopyFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_copy_from_start:google.protobuf.compiler.AccessInfo) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void AccessInfo::CopyFrom(const AccessInfo& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.compiler.AccessInfo) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool AccessInfo::IsInitialized() const { + return true; +} + +void AccessInfo::Swap(AccessInfo* other) { + if (other == this) return; + InternalSwap(other); +} +void AccessInfo::InternalSwap(AccessInfo* other) { + message_.InternalSwap(&other->message_); + std::swap(_has_bits_[0], other->_has_bits_[0]); + _internal_metadata_.Swap(&other->_internal_metadata_); + std::swap(_cached_size_, other->_cached_size_); +} + +::google::protobuf::Metadata AccessInfo::GetMetadata() const { + protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::protobuf_AssignDescriptorsOnce(); + return protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::file_level_metadata[kIndexInFileMessages]; +} + +#if PROTOBUF_INLINE_NOT_IN_HEADERS +// AccessInfo + +// repeated .google.protobuf.compiler.MessageAccessInfo message = 1; +int AccessInfo::message_size() const { + return message_.size(); +} +void AccessInfo::clear_message() { + message_.Clear(); +} +const ::google::protobuf::compiler::MessageAccessInfo& AccessInfo::message(int index) const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.AccessInfo.message) + return message_.Get(index); +} +::google::protobuf::compiler::MessageAccessInfo* AccessInfo::mutable_message(int index) { + // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.AccessInfo.message) + return message_.Mutable(index); +} +::google::protobuf::compiler::MessageAccessInfo* AccessInfo::add_message() { + // @@protoc_insertion_point(field_add:google.protobuf.compiler.AccessInfo.message) + return message_.Add(); +} +::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::MessageAccessInfo >* +AccessInfo::mutable_message() { + // @@protoc_insertion_point(field_mutable_list:google.protobuf.compiler.AccessInfo.message) + return &message_; +} +const ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::MessageAccessInfo >& +AccessInfo::message() const { + // @@protoc_insertion_point(field_list:google.protobuf.compiler.AccessInfo.message) + return message_; +} + +#endif // PROTOBUF_INLINE_NOT_IN_HEADERS + +// @@protoc_insertion_point(namespace_scope) + +} // namespace compiler +} // namespace protobuf +} // namespace google + +// @@protoc_insertion_point(global_scope) diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/profile.pb.h b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/profile.pb.h new file mode 100644 index 0000000000..d20b87ed68 --- /dev/null +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/profile.pb.h @@ -0,0 +1,728 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: google/protobuf/compiler/profile.proto + +#ifndef PROTOBUF_google_2fprotobuf_2fcompiler_2fprofile_2eproto__INCLUDED +#define PROTOBUF_google_2fprotobuf_2fcompiler_2fprofile_2eproto__INCLUDED + +#include + +#include + +#if GOOGLE_PROTOBUF_VERSION < 3003000 +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3003000 < 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. +#endif + +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include +// @@protoc_insertion_point(includes) +namespace google { +namespace protobuf { +namespace compiler { +class AccessInfo; +class AccessInfoDefaultTypeInternal; +LIBPROTOC_EXPORT extern AccessInfoDefaultTypeInternal _AccessInfo_default_instance_; +class FieldAccessInfo; +class FieldAccessInfoDefaultTypeInternal; +LIBPROTOC_EXPORT extern FieldAccessInfoDefaultTypeInternal _FieldAccessInfo_default_instance_; +class MessageAccessInfo; +class MessageAccessInfoDefaultTypeInternal; +LIBPROTOC_EXPORT extern MessageAccessInfoDefaultTypeInternal _MessageAccessInfo_default_instance_; +} // namespace compiler +} // namespace protobuf +} // namespace google + +namespace google { +namespace protobuf { +namespace compiler { + +namespace protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto { +// Internal implementation detail -- do not call these. +struct LIBPROTOC_EXPORT TableStruct { + static const ::google::protobuf::internal::ParseTableField entries[]; + static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; + static const ::google::protobuf::internal::ParseTable schema[]; + static const ::google::protobuf::uint32 offsets[]; + static void InitDefaultsImpl(); + static void Shutdown(); +}; +void LIBPROTOC_EXPORT AddDescriptors(); +void LIBPROTOC_EXPORT InitDefaults(); +} // namespace protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto + +// =================================================================== + +class LIBPROTOC_EXPORT FieldAccessInfo : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.FieldAccessInfo) */ { + public: + FieldAccessInfo(); + virtual ~FieldAccessInfo(); + + FieldAccessInfo(const FieldAccessInfo& from); + + inline FieldAccessInfo& operator=(const FieldAccessInfo& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _internal_metadata_.unknown_fields(); + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return _internal_metadata_.mutable_unknown_fields(); + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const FieldAccessInfo& default_instance(); + + static inline const FieldAccessInfo* internal_default_instance() { + return reinterpret_cast( + &_FieldAccessInfo_default_instance_); + } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 0; + + void Swap(FieldAccessInfo* other); + + // implements Message ---------------------------------------------- + + inline FieldAccessInfo* New() const PROTOBUF_FINAL { return New(NULL); } + + FieldAccessInfo* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL; + void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void CopyFrom(const FieldAccessInfo& from); + void MergeFrom(const FieldAccessInfo& from); + void Clear() PROTOBUF_FINAL; + bool IsInitialized() const PROTOBUF_FINAL; + + size_t ByteSizeLong() const PROTOBUF_FINAL; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL; + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; + ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; + int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const PROTOBUF_FINAL; + void InternalSwap(FieldAccessInfo* other); + private: + inline ::google::protobuf::Arena* GetArenaNoVirtual() const { + return NULL; + } + inline void* MaybeArenaPtr() const { + return NULL; + } + public: + + ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional string name = 1; + bool has_name() const; + void clear_name(); + static const int kNameFieldNumber = 1; + const ::std::string& name() const; + void set_name(const ::std::string& value); + #if LANG_CXX11 + void set_name(::std::string&& value); + #endif + void set_name(const char* value); + void set_name(const char* value, size_t size); + ::std::string* mutable_name(); + ::std::string* release_name(); + void set_allocated_name(::std::string* name); + + // optional uint64 getters_count = 2; + bool has_getters_count() const; + void clear_getters_count(); + static const int kGettersCountFieldNumber = 2; + ::google::protobuf::uint64 getters_count() const; + void set_getters_count(::google::protobuf::uint64 value); + + // optional uint64 setters_count = 3; + bool has_setters_count() const; + void clear_setters_count(); + static const int kSettersCountFieldNumber = 3; + ::google::protobuf::uint64 setters_count() const; + void set_setters_count(::google::protobuf::uint64 value); + + // optional uint64 configs_count = 4; + bool has_configs_count() const; + void clear_configs_count(); + static const int kConfigsCountFieldNumber = 4; + ::google::protobuf::uint64 configs_count() const; + void set_configs_count(::google::protobuf::uint64 value); + + // @@protoc_insertion_point(class_scope:google.protobuf.compiler.FieldAccessInfo) + private: + void set_has_name(); + void clear_has_name(); + void set_has_getters_count(); + void clear_has_getters_count(); + void set_has_setters_count(); + void clear_has_setters_count(); + void set_has_configs_count(); + void clear_has_configs_count(); + + ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + ::google::protobuf::internal::HasBits<1> _has_bits_; + mutable int _cached_size_; + ::google::protobuf::internal::ArenaStringPtr name_; + ::google::protobuf::uint64 getters_count_; + ::google::protobuf::uint64 setters_count_; + ::google::protobuf::uint64 configs_count_; + friend struct protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::TableStruct; +}; +// ------------------------------------------------------------------- + +class LIBPROTOC_EXPORT MessageAccessInfo : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.MessageAccessInfo) */ { + public: + MessageAccessInfo(); + virtual ~MessageAccessInfo(); + + MessageAccessInfo(const MessageAccessInfo& from); + + inline MessageAccessInfo& operator=(const MessageAccessInfo& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _internal_metadata_.unknown_fields(); + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return _internal_metadata_.mutable_unknown_fields(); + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const MessageAccessInfo& default_instance(); + + static inline const MessageAccessInfo* internal_default_instance() { + return reinterpret_cast( + &_MessageAccessInfo_default_instance_); + } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 1; + + void Swap(MessageAccessInfo* other); + + // implements Message ---------------------------------------------- + + inline MessageAccessInfo* New() const PROTOBUF_FINAL { return New(NULL); } + + MessageAccessInfo* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL; + void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void CopyFrom(const MessageAccessInfo& from); + void MergeFrom(const MessageAccessInfo& from); + void Clear() PROTOBUF_FINAL; + bool IsInitialized() const PROTOBUF_FINAL; + + size_t ByteSizeLong() const PROTOBUF_FINAL; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL; + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; + ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; + int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const PROTOBUF_FINAL; + void InternalSwap(MessageAccessInfo* other); + private: + inline ::google::protobuf::Arena* GetArenaNoVirtual() const { + return NULL; + } + inline void* MaybeArenaPtr() const { + return NULL; + } + public: + + ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated .google.protobuf.compiler.FieldAccessInfo field = 3; + int field_size() const; + void clear_field(); + static const int kFieldFieldNumber = 3; + const ::google::protobuf::compiler::FieldAccessInfo& field(int index) const; + ::google::protobuf::compiler::FieldAccessInfo* mutable_field(int index); + ::google::protobuf::compiler::FieldAccessInfo* add_field(); + ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::FieldAccessInfo >* + mutable_field(); + const ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::FieldAccessInfo >& + field() const; + + // optional string name = 1; + bool has_name() const; + void clear_name(); + static const int kNameFieldNumber = 1; + const ::std::string& name() const; + void set_name(const ::std::string& value); + #if LANG_CXX11 + void set_name(::std::string&& value); + #endif + void set_name(const char* value); + void set_name(const char* value, size_t size); + ::std::string* mutable_name(); + ::std::string* release_name(); + void set_allocated_name(::std::string* name); + + // optional uint64 count = 2; + bool has_count() const; + void clear_count(); + static const int kCountFieldNumber = 2; + ::google::protobuf::uint64 count() const; + void set_count(::google::protobuf::uint64 value); + + // @@protoc_insertion_point(class_scope:google.protobuf.compiler.MessageAccessInfo) + private: + void set_has_name(); + void clear_has_name(); + void set_has_count(); + void clear_has_count(); + + ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + ::google::protobuf::internal::HasBits<1> _has_bits_; + mutable int _cached_size_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::FieldAccessInfo > field_; + ::google::protobuf::internal::ArenaStringPtr name_; + ::google::protobuf::uint64 count_; + friend struct protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::TableStruct; +}; +// ------------------------------------------------------------------- + +class LIBPROTOC_EXPORT AccessInfo : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.AccessInfo) */ { + public: + AccessInfo(); + virtual ~AccessInfo(); + + AccessInfo(const AccessInfo& from); + + inline AccessInfo& operator=(const AccessInfo& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _internal_metadata_.unknown_fields(); + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return _internal_metadata_.mutable_unknown_fields(); + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const AccessInfo& default_instance(); + + static inline const AccessInfo* internal_default_instance() { + return reinterpret_cast( + &_AccessInfo_default_instance_); + } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 2; + + void Swap(AccessInfo* other); + + // implements Message ---------------------------------------------- + + inline AccessInfo* New() const PROTOBUF_FINAL { return New(NULL); } + + AccessInfo* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL; + void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void CopyFrom(const AccessInfo& from); + void MergeFrom(const AccessInfo& from); + void Clear() PROTOBUF_FINAL; + bool IsInitialized() const PROTOBUF_FINAL; + + size_t ByteSizeLong() const PROTOBUF_FINAL; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL; + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; + ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; + int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const PROTOBUF_FINAL; + void InternalSwap(AccessInfo* other); + private: + inline ::google::protobuf::Arena* GetArenaNoVirtual() const { + return NULL; + } + inline void* MaybeArenaPtr() const { + return NULL; + } + public: + + ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated .google.protobuf.compiler.MessageAccessInfo message = 1; + int message_size() const; + void clear_message(); + static const int kMessageFieldNumber = 1; + const ::google::protobuf::compiler::MessageAccessInfo& message(int index) const; + ::google::protobuf::compiler::MessageAccessInfo* mutable_message(int index); + ::google::protobuf::compiler::MessageAccessInfo* add_message(); + ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::MessageAccessInfo >* + mutable_message(); + const ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::MessageAccessInfo >& + message() const; + + // @@protoc_insertion_point(class_scope:google.protobuf.compiler.AccessInfo) + private: + + ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + ::google::protobuf::internal::HasBits<1> _has_bits_; + mutable int _cached_size_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::MessageAccessInfo > message_; + friend struct protobuf_google_2fprotobuf_2fcompiler_2fprofile_2eproto::TableStruct; +}; +// =================================================================== + + +// =================================================================== + +#if !PROTOBUF_INLINE_NOT_IN_HEADERS +// FieldAccessInfo + +// optional string name = 1; +inline bool FieldAccessInfo::has_name() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void FieldAccessInfo::set_has_name() { + _has_bits_[0] |= 0x00000001u; +} +inline void FieldAccessInfo::clear_has_name() { + _has_bits_[0] &= ~0x00000001u; +} +inline void FieldAccessInfo::clear_name() { + name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + clear_has_name(); +} +inline const ::std::string& FieldAccessInfo::name() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.FieldAccessInfo.name) + return name_.GetNoArena(); +} +inline void FieldAccessInfo::set_name(const ::std::string& value) { + set_has_name(); + name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + // @@protoc_insertion_point(field_set:google.protobuf.compiler.FieldAccessInfo.name) +} +#if LANG_CXX11 +inline void FieldAccessInfo::set_name(::std::string&& value) { + set_has_name(); + name_.SetNoArena( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.compiler.FieldAccessInfo.name) +} +#endif +inline void FieldAccessInfo::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); + set_has_name(); + name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.FieldAccessInfo.name) +} +inline void FieldAccessInfo::set_name(const char* value, size_t size) { + set_has_name(); + name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast(value), size)); + // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.FieldAccessInfo.name) +} +inline ::std::string* FieldAccessInfo::mutable_name() { + set_has_name(); + // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.FieldAccessInfo.name) + return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline ::std::string* FieldAccessInfo::release_name() { + // @@protoc_insertion_point(field_release:google.protobuf.compiler.FieldAccessInfo.name) + clear_has_name(); + return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline void FieldAccessInfo::set_allocated_name(::std::string* name) { + if (name != NULL) { + set_has_name(); + } else { + clear_has_name(); + } + name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); + // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.FieldAccessInfo.name) +} + +// optional uint64 getters_count = 2; +inline bool FieldAccessInfo::has_getters_count() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void FieldAccessInfo::set_has_getters_count() { + _has_bits_[0] |= 0x00000002u; +} +inline void FieldAccessInfo::clear_has_getters_count() { + _has_bits_[0] &= ~0x00000002u; +} +inline void FieldAccessInfo::clear_getters_count() { + getters_count_ = GOOGLE_ULONGLONG(0); + clear_has_getters_count(); +} +inline ::google::protobuf::uint64 FieldAccessInfo::getters_count() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.FieldAccessInfo.getters_count) + return getters_count_; +} +inline void FieldAccessInfo::set_getters_count(::google::protobuf::uint64 value) { + set_has_getters_count(); + getters_count_ = value; + // @@protoc_insertion_point(field_set:google.protobuf.compiler.FieldAccessInfo.getters_count) +} + +// optional uint64 setters_count = 3; +inline bool FieldAccessInfo::has_setters_count() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void FieldAccessInfo::set_has_setters_count() { + _has_bits_[0] |= 0x00000004u; +} +inline void FieldAccessInfo::clear_has_setters_count() { + _has_bits_[0] &= ~0x00000004u; +} +inline void FieldAccessInfo::clear_setters_count() { + setters_count_ = GOOGLE_ULONGLONG(0); + clear_has_setters_count(); +} +inline ::google::protobuf::uint64 FieldAccessInfo::setters_count() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.FieldAccessInfo.setters_count) + return setters_count_; +} +inline void FieldAccessInfo::set_setters_count(::google::protobuf::uint64 value) { + set_has_setters_count(); + setters_count_ = value; + // @@protoc_insertion_point(field_set:google.protobuf.compiler.FieldAccessInfo.setters_count) +} + +// optional uint64 configs_count = 4; +inline bool FieldAccessInfo::has_configs_count() const { + return (_has_bits_[0] & 0x00000008u) != 0; +} +inline void FieldAccessInfo::set_has_configs_count() { + _has_bits_[0] |= 0x00000008u; +} +inline void FieldAccessInfo::clear_has_configs_count() { + _has_bits_[0] &= ~0x00000008u; +} +inline void FieldAccessInfo::clear_configs_count() { + configs_count_ = GOOGLE_ULONGLONG(0); + clear_has_configs_count(); +} +inline ::google::protobuf::uint64 FieldAccessInfo::configs_count() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.FieldAccessInfo.configs_count) + return configs_count_; +} +inline void FieldAccessInfo::set_configs_count(::google::protobuf::uint64 value) { + set_has_configs_count(); + configs_count_ = value; + // @@protoc_insertion_point(field_set:google.protobuf.compiler.FieldAccessInfo.configs_count) +} + +// ------------------------------------------------------------------- + +// MessageAccessInfo + +// optional string name = 1; +inline bool MessageAccessInfo::has_name() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void MessageAccessInfo::set_has_name() { + _has_bits_[0] |= 0x00000001u; +} +inline void MessageAccessInfo::clear_has_name() { + _has_bits_[0] &= ~0x00000001u; +} +inline void MessageAccessInfo::clear_name() { + name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + clear_has_name(); +} +inline const ::std::string& MessageAccessInfo::name() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.MessageAccessInfo.name) + return name_.GetNoArena(); +} +inline void MessageAccessInfo::set_name(const ::std::string& value) { + set_has_name(); + name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + // @@protoc_insertion_point(field_set:google.protobuf.compiler.MessageAccessInfo.name) +} +#if LANG_CXX11 +inline void MessageAccessInfo::set_name(::std::string&& value) { + set_has_name(); + name_.SetNoArena( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.compiler.MessageAccessInfo.name) +} +#endif +inline void MessageAccessInfo::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); + set_has_name(); + name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.MessageAccessInfo.name) +} +inline void MessageAccessInfo::set_name(const char* value, size_t size) { + set_has_name(); + name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast(value), size)); + // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.MessageAccessInfo.name) +} +inline ::std::string* MessageAccessInfo::mutable_name() { + set_has_name(); + // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.MessageAccessInfo.name) + return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline ::std::string* MessageAccessInfo::release_name() { + // @@protoc_insertion_point(field_release:google.protobuf.compiler.MessageAccessInfo.name) + clear_has_name(); + return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline void MessageAccessInfo::set_allocated_name(::std::string* name) { + if (name != NULL) { + set_has_name(); + } else { + clear_has_name(); + } + name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); + // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.MessageAccessInfo.name) +} + +// optional uint64 count = 2; +inline bool MessageAccessInfo::has_count() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void MessageAccessInfo::set_has_count() { + _has_bits_[0] |= 0x00000002u; +} +inline void MessageAccessInfo::clear_has_count() { + _has_bits_[0] &= ~0x00000002u; +} +inline void MessageAccessInfo::clear_count() { + count_ = GOOGLE_ULONGLONG(0); + clear_has_count(); +} +inline ::google::protobuf::uint64 MessageAccessInfo::count() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.MessageAccessInfo.count) + return count_; +} +inline void MessageAccessInfo::set_count(::google::protobuf::uint64 value) { + set_has_count(); + count_ = value; + // @@protoc_insertion_point(field_set:google.protobuf.compiler.MessageAccessInfo.count) +} + +// repeated .google.protobuf.compiler.FieldAccessInfo field = 3; +inline int MessageAccessInfo::field_size() const { + return field_.size(); +} +inline void MessageAccessInfo::clear_field() { + field_.Clear(); +} +inline const ::google::protobuf::compiler::FieldAccessInfo& MessageAccessInfo::field(int index) const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.MessageAccessInfo.field) + return field_.Get(index); +} +inline ::google::protobuf::compiler::FieldAccessInfo* MessageAccessInfo::mutable_field(int index) { + // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.MessageAccessInfo.field) + return field_.Mutable(index); +} +inline ::google::protobuf::compiler::FieldAccessInfo* MessageAccessInfo::add_field() { + // @@protoc_insertion_point(field_add:google.protobuf.compiler.MessageAccessInfo.field) + return field_.Add(); +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::FieldAccessInfo >* +MessageAccessInfo::mutable_field() { + // @@protoc_insertion_point(field_mutable_list:google.protobuf.compiler.MessageAccessInfo.field) + return &field_; +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::FieldAccessInfo >& +MessageAccessInfo::field() const { + // @@protoc_insertion_point(field_list:google.protobuf.compiler.MessageAccessInfo.field) + return field_; +} + +// ------------------------------------------------------------------- + +// AccessInfo + +// repeated .google.protobuf.compiler.MessageAccessInfo message = 1; +inline int AccessInfo::message_size() const { + return message_.size(); +} +inline void AccessInfo::clear_message() { + message_.Clear(); +} +inline const ::google::protobuf::compiler::MessageAccessInfo& AccessInfo::message(int index) const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.AccessInfo.message) + return message_.Get(index); +} +inline ::google::protobuf::compiler::MessageAccessInfo* AccessInfo::mutable_message(int index) { + // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.AccessInfo.message) + return message_.Mutable(index); +} +inline ::google::protobuf::compiler::MessageAccessInfo* AccessInfo::add_message() { + // @@protoc_insertion_point(field_add:google.protobuf.compiler.AccessInfo.message) + return message_.Add(); +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::MessageAccessInfo >* +AccessInfo::mutable_message() { + // @@protoc_insertion_point(field_mutable_list:google.protobuf.compiler.AccessInfo.message) + return &message_; +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::MessageAccessInfo >& +AccessInfo::message() const { + // @@protoc_insertion_point(field_list:google.protobuf.compiler.AccessInfo.message) + return message_; +} + +#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + + +// @@protoc_insertion_point(namespace_scope) + + +} // namespace compiler +} // namespace protobuf +} // namespace google + +// @@protoc_insertion_point(global_scope) + +#endif // PROTOBUF_google_2fprotobuf_2fcompiler_2fprofile_2eproto__INCLUDED diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/profile.proto b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/profile.proto new file mode 100644 index 0000000000..09ebe091b8 --- /dev/null +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/profile.proto @@ -0,0 +1,68 @@ +// 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: seongkim@google.com (Seong Beom Kim) +// +// protoc (Protocol Compiler) can generate more efficient code +// if it knows how a workload accesses fields of a message; +// e.g. some much more frequently than others. +// +// Protos defined here describe the access information per message +// and per field. Note that one can use any methods to collect +// the access patterns like CPU profiling, instrumented build, etc. + +syntax = "proto2"; + +package google.protobuf.compiler; + +// To convey the access pattern of a field, it classifies +// the type of the accessor methods into getters, setters and +// configs. Getters and setters read and write the field +// respectively and other operations like checking if the field +// exists are considered as configs. +message FieldAccessInfo { + optional string name = 1; + optional uint64 getters_count = 2; + optional uint64 setters_count = 3; + optional uint64 configs_count = 4; +} + +// "count" correlates with how many samples an access info has +// for a message. High "count" means more confident optimization +// based on the info. +message MessageAccessInfo { + optional string name = 1; + optional uint64 count = 2; + repeated FieldAccessInfo field = 3; +} + +message AccessInfo { + repeated MessageAccessInfo message = 1; +} diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/python/python_generator.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/python/python_generator.cc index f83f155a82..21a7e158c7 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/python/python_generator.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/python/python_generator.cc @@ -445,8 +445,6 @@ void Generator::PrintFileDescriptor() const { printer_->Outdent(); printer_->Print(")\n"); - printer_->Print("_sym_db.RegisterFileDescriptor($name$)\n", "name", - kDescriptorKey); printer_->Print("\n"); } @@ -999,6 +997,10 @@ void Generator::FixForeignFieldsInDescriptors() const { for (int i = 0; i < file_->extension_count(); ++i) { AddExtensionToFileDescriptor(*file_->extension(i)); } + // TODO(jieluo): Move this register to PrintFileDescriptor() when + // FieldDescriptor.file is added in generated file. + printer_->Print("_sym_db.RegisterFileDescriptor($name$)\n", "name", + kDescriptorKey); printer_->Print("\n"); } diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/test_plugin.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/test_plugin.cc index 4830fd70a0..c676ce8ce9 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/test_plugin.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/test_plugin.cc @@ -37,7 +37,6 @@ #include #include #include -#include int main(int argc, char* argv[]) { #ifdef _MSC_VER diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/zip_writer.cc b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/zip_writer.cc index 07d52b18cd..458cced29d 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/zip_writer.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/zip_writer.cc @@ -28,6 +28,36 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// 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: ambrose@google.com (Ambrose Feinstein), // kenton@google.com (Kenton Varda) // diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/zip_writer.h b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/zip_writer.h index 737f4d42f3..03db4d573c 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/compiler/zip_writer.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/compiler/zip_writer.h @@ -28,6 +28,36 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// 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: kenton@google.com (Kenton Varda) #include diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/descriptor.cc b/third_party/protobuf/3.2.0/src/google/protobuf/descriptor.cc index c87327ce01..6a807926ad 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/descriptor.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/descriptor.cc @@ -72,6 +72,79 @@ namespace google { namespace protobuf { +struct Symbol { + enum Type { + NULL_SYMBOL, + MESSAGE, + FIELD, + ONEOF, + ENUM, + ENUM_VALUE, + SERVICE, + METHOD, + PACKAGE + }; + Type type; + union { + const Descriptor* descriptor; + const FieldDescriptor* field_descriptor; + const OneofDescriptor* oneof_descriptor; + const EnumDescriptor* enum_descriptor; + const EnumValueDescriptor* enum_value_descriptor; + const ServiceDescriptor* service_descriptor; + const MethodDescriptor* method_descriptor; + const FileDescriptor* package_file_descriptor; + }; + + inline Symbol() : type(NULL_SYMBOL) { descriptor = NULL; } + inline bool IsNull() const { return type == NULL_SYMBOL; } + inline bool IsType() const { return type == MESSAGE || type == ENUM; } + inline bool IsAggregate() const { + return type == MESSAGE || type == PACKAGE || type == ENUM || + type == SERVICE; + } + +#define CONSTRUCTOR(TYPE, TYPE_CONSTANT, FIELD) \ + inline explicit Symbol(const TYPE* value) { \ + type = TYPE_CONSTANT; \ + this->FIELD = value; \ + } + + CONSTRUCTOR(Descriptor, MESSAGE, descriptor) + CONSTRUCTOR(FieldDescriptor, FIELD, field_descriptor) + CONSTRUCTOR(OneofDescriptor, ONEOF, oneof_descriptor) + CONSTRUCTOR(EnumDescriptor, ENUM, enum_descriptor) + CONSTRUCTOR(EnumValueDescriptor, ENUM_VALUE, enum_value_descriptor) + CONSTRUCTOR(ServiceDescriptor, SERVICE, service_descriptor) + CONSTRUCTOR(MethodDescriptor, METHOD, method_descriptor) + CONSTRUCTOR(FileDescriptor, PACKAGE, package_file_descriptor) +#undef CONSTRUCTOR + + const FileDescriptor* GetFile() const { + switch (type) { + case NULL_SYMBOL: + return NULL; + case MESSAGE: + return descriptor->file(); + case FIELD: + return field_descriptor->file(); + case ONEOF: + return oneof_descriptor->containing_type()->file(); + case ENUM: + return enum_descriptor->file(); + case ENUM_VALUE: + return enum_value_descriptor->type()->file(); + case SERVICE: + return service_descriptor->file(); + case METHOD: + return method_descriptor->service()->file(); + case PACKAGE: + return package_file_descriptor; + } + return NULL; + } +}; + const FieldDescriptor::CppType FieldDescriptor::kTypeToCppTypeMap[MAX_TYPE + 1] = { static_cast(0), // 0 is reserved for errors @@ -369,65 +442,6 @@ struct PointerStringPairHash { }; -struct Symbol { - enum Type { - NULL_SYMBOL, MESSAGE, FIELD, ONEOF, ENUM, ENUM_VALUE, SERVICE, METHOD, - PACKAGE - }; - Type type; - union { - const Descriptor* descriptor; - const FieldDescriptor* field_descriptor; - const OneofDescriptor* oneof_descriptor; - const EnumDescriptor* enum_descriptor; - const EnumValueDescriptor* enum_value_descriptor; - const ServiceDescriptor* service_descriptor; - const MethodDescriptor* method_descriptor; - const FileDescriptor* package_file_descriptor; - }; - - inline Symbol() : type(NULL_SYMBOL) { descriptor = NULL; } - inline bool IsNull() const { return type == NULL_SYMBOL; } - inline bool IsType() const { - return type == MESSAGE || type == ENUM; - } - inline bool IsAggregate() const { - return type == MESSAGE || type == PACKAGE - || type == ENUM || type == SERVICE; - } - -#define CONSTRUCTOR(TYPE, TYPE_CONSTANT, FIELD) \ - inline explicit Symbol(const TYPE* value) { \ - type = TYPE_CONSTANT; \ - this->FIELD = value; \ - } - - CONSTRUCTOR(Descriptor , MESSAGE , descriptor ) - CONSTRUCTOR(FieldDescriptor , FIELD , field_descriptor ) - CONSTRUCTOR(OneofDescriptor , ONEOF , oneof_descriptor ) - CONSTRUCTOR(EnumDescriptor , ENUM , enum_descriptor ) - CONSTRUCTOR(EnumValueDescriptor, ENUM_VALUE, enum_value_descriptor ) - CONSTRUCTOR(ServiceDescriptor , SERVICE , service_descriptor ) - CONSTRUCTOR(MethodDescriptor , METHOD , method_descriptor ) - CONSTRUCTOR(FileDescriptor , PACKAGE , package_file_descriptor) -#undef CONSTRUCTOR - - const FileDescriptor* GetFile() const { - switch (type) { - case NULL_SYMBOL: return NULL; - case MESSAGE : return descriptor ->file(); - case FIELD : return field_descriptor ->file(); - case ONEOF : return oneof_descriptor ->containing_type()->file(); - case ENUM : return enum_descriptor ->file(); - case ENUM_VALUE : return enum_value_descriptor->type()->file(); - case SERVICE : return service_descriptor ->file(); - case METHOD : return method_descriptor ->service()->file(); - case PACKAGE : return package_file_descriptor; - } - return NULL; - } -}; - const Symbol kNullSymbol; typedef hash_map strings_; // All strings in the pool. std::vector messages_; // All messages in the pool. + std::vector + once_dynamics_; // All GoogleOnceDynamics in the pool. std::vector file_tables_; // All file tables in the pool. std::vector allocations_; // All other memory allocated in the pool. @@ -632,19 +652,20 @@ class DescriptorPool::Tables { struct CheckPoint { explicit CheckPoint(const Tables* tables) - : strings_before_checkpoint(tables->strings_.size()), - messages_before_checkpoint(tables->messages_.size()), - file_tables_before_checkpoint(tables->file_tables_.size()), - allocations_before_checkpoint(tables->allocations_.size()), - pending_symbols_before_checkpoint( - tables->symbols_after_checkpoint_.size()), - pending_files_before_checkpoint( - tables->files_after_checkpoint_.size()), - pending_extensions_before_checkpoint( - tables->extensions_after_checkpoint_.size()) { - } + : strings_before_checkpoint(tables->strings_.size()), + messages_before_checkpoint(tables->messages_.size()), + once_dynamics_before_checkpoint(tables->once_dynamics_.size()), + file_tables_before_checkpoint(tables->file_tables_.size()), + allocations_before_checkpoint(tables->allocations_.size()), + pending_symbols_before_checkpoint( + tables->symbols_after_checkpoint_.size()), + pending_files_before_checkpoint( + tables->files_after_checkpoint_.size()), + pending_extensions_before_checkpoint( + tables->extensions_after_checkpoint_.size()) {} int strings_before_checkpoint; int messages_before_checkpoint; + int once_dynamics_before_checkpoint; int file_tables_before_checkpoint; int allocations_before_checkpoint; int pending_symbols_before_checkpoint; @@ -767,6 +788,7 @@ DescriptorPool::Tables::~Tables() { } STLDeleteElements(&strings_); STLDeleteElements(&file_tables_); + STLDeleteElements(&once_dynamics_); } FileDescriptorTables::FileDescriptorTables() @@ -855,6 +877,9 @@ void DescriptorPool::Tables::RollbackToLastCheckpoint() { STLDeleteContainerPointers( messages_.begin() + checkpoint.messages_before_checkpoint, messages_.end()); + STLDeleteContainerPointers( + once_dynamics_.begin() + checkpoint.once_dynamics_before_checkpoint, + once_dynamics_.end()); STLDeleteContainerPointers( file_tables_.begin() + checkpoint.file_tables_before_checkpoint, file_tables_.end()); @@ -866,6 +891,7 @@ void DescriptorPool::Tables::RollbackToLastCheckpoint() { strings_.resize(checkpoint.strings_before_checkpoint); messages_.resize(checkpoint.messages_before_checkpoint); + once_dynamics_.resize(checkpoint.once_dynamics_before_checkpoint); file_tables_.resize(checkpoint.file_tables_before_checkpoint); allocations_.resize(checkpoint.allocations_before_checkpoint); checkpoints_.pop_back(); @@ -1104,6 +1130,12 @@ string* DescriptorPool::Tables::AllocateString(const string& value) { return result; } +GoogleOnceDynamic* DescriptorPool::Tables::AllocateOnceDynamic() { + GoogleOnceDynamic* result = new GoogleOnceDynamic(); + once_dynamics_.push_back(result); + return result; +} + template Type* DescriptorPool::Tables::AllocateMessage(Type* /* dummy */) { Type* result = new Type; @@ -1157,8 +1189,10 @@ DescriptorPool::DescriptorPool() underlay_(NULL), tables_(new Tables), enforce_dependencies_(true), + lazily_build_dependencies_(false), allow_unknown_(false), - enforce_weak_(false) {} + enforce_weak_(false), + disallow_enforce_utf8_(false) {} DescriptorPool::DescriptorPool(DescriptorDatabase* fallback_database, ErrorCollector* error_collector) @@ -1168,8 +1202,10 @@ DescriptorPool::DescriptorPool(DescriptorDatabase* fallback_database, underlay_(NULL), tables_(new Tables), enforce_dependencies_(true), + lazily_build_dependencies_(false), allow_unknown_(false), - enforce_weak_(false) { + enforce_weak_(false), + disallow_enforce_utf8_(false) { } DescriptorPool::DescriptorPool(const DescriptorPool* underlay) @@ -1179,8 +1215,10 @@ DescriptorPool::DescriptorPool(const DescriptorPool* underlay) underlay_(underlay), tables_(new Tables), enforce_dependencies_(true), + lazily_build_dependencies_(false), allow_unknown_(false), - enforce_weak_(false) {} + enforce_weak_(false), + disallow_enforce_utf8_(false) {} DescriptorPool::~DescriptorPool() { if (mutex_ != NULL) delete mutex_; @@ -1225,6 +1263,7 @@ void DeleteGeneratedPool() { static void InitGeneratedPool() { generated_database_ = new EncodedDescriptorDatabase; generated_pool_ = new DescriptorPool(generated_database_); + generated_pool_->InternalSetLazilyBuildDependencies(); internal::OnShutdown(&DeleteGeneratedPool); } @@ -3023,15 +3062,16 @@ class DescriptorBuilder { // - Search the pool's underlay if not found in tables_. // - Insure that the resulting Symbol is from one of the file's declared // dependencies. - Symbol FindSymbol(const string& name); + Symbol FindSymbol(const string& name, bool build_it = true); // Like FindSymbol() but does not require that the symbol is in one of the // file's declared dependencies. - Symbol FindSymbolNotEnforcingDeps(const string& name); + Symbol FindSymbolNotEnforcingDeps(const string& name, bool build_it = true); // This implements the body of FindSymbolNotEnforcingDeps(). Symbol FindSymbolNotEnforcingDepsHelper(const DescriptorPool* pool, - const string& name); + const string& name, + bool build_it = true); // Like FindSymbol(), but looks up the name relative to some other symbol // name. This first searches siblings of relative_to, then siblings of its @@ -3047,31 +3087,21 @@ class DescriptorBuilder { // that LookupSymbol may still return a non-type symbol in LOOKUP_TYPES mode, // if it believes that's all it could refer to. The caller should always // check that it receives the type of symbol it was expecting. - enum PlaceholderType { - PLACEHOLDER_MESSAGE, - PLACEHOLDER_ENUM, - PLACEHOLDER_EXTENDABLE_MESSAGE - }; enum ResolveMode { LOOKUP_ALL, LOOKUP_TYPES }; Symbol LookupSymbol(const string& name, const string& relative_to, - PlaceholderType placeholder_type = PLACEHOLDER_MESSAGE, - ResolveMode resolve_mode = LOOKUP_ALL); + DescriptorPool::PlaceholderType placeholder_type = + DescriptorPool::PLACEHOLDER_MESSAGE, + ResolveMode resolve_mode = LOOKUP_ALL, + bool build_it = true); // Like LookupSymbol() but will not return a placeholder even if // AllowUnknownDependencies() has been used. Symbol LookupSymbolNoPlaceholder(const string& name, const string& relative_to, - ResolveMode resolve_mode = LOOKUP_ALL); - - // Creates a placeholder type suitable for return from LookupSymbol(). May - // return kNullSymbol if the name is not a valid type name. - Symbol NewPlaceholder(const string& name, PlaceholderType placeholder_type); - - // Creates a placeholder file. Never returns NULL. This is used when an - // import is not found and AllowUnknownDependencies() is enabled. - FileDescriptor* NewPlaceholderFile(const string& name); + ResolveMode resolve_mode = LOOKUP_ALL, + bool build_it = true); // Calls tables_->AddSymbol() and records an error if it fails. Returns // true if successful or false if failed, though most callers can ignore @@ -3093,10 +3123,6 @@ class DescriptorBuilder { void ValidateSymbolName(const string& name, const string& full_name, const Message& proto); - // Like ValidateSymbolName(), but the name is allowed to contain periods and - // an error is indicated by returning false (not recording the error). - bool ValidateQualifiedName(const string& name); - // Used by BUILD_ARRAY macro (below) to avoid having to have the type // specified as a macro parameter. template @@ -3495,7 +3521,7 @@ void DescriptorBuilder::RecordPublicDependencies(const FileDescriptor* file) { } Symbol DescriptorBuilder::FindSymbolNotEnforcingDepsHelper( - const DescriptorPool* pool, const string& name) { + const DescriptorPool* pool, const string& name, bool build_it) { // If we are looking at an underlay, we must lock its mutex_, since we are // accessing the underlay's tables_ directly. MutexLockMaybe lock((pool == pool_) ? NULL : pool->mutex_); @@ -3507,12 +3533,14 @@ Symbol DescriptorBuilder::FindSymbolNotEnforcingDepsHelper( } if (result.IsNull()) { - // In theory, we shouldn't need to check fallback_database_ because the - // symbol should be in one of its file's direct dependencies, and we have - // already loaded those by the time we get here. But we check anyway so - // that we can generate better error message when dependencies are missing - // (i.e., "missing dependency" rather than "type is not defined"). - if (pool->TryFindSymbolInFallbackDatabase(name)) { + // With lazily_build_dependencies_, a symbol lookup at cross link time is + // not guaranteed to be successful. In most cases, build_it will be false, + // which intentionally prevents us from building an import until it's + // actually needed. In some cases, like registering an extension, we want + // to build the file containing the symbol, and build_it will be set. + // Also, build_it will be true when !lazily_build_dependencies_, to provide + // better error reporting of missing dependencies. + if (build_it && pool->TryFindSymbolInFallbackDatabase(name)) { result = pool->tables_->FindSymbol(name); } } @@ -3520,17 +3548,18 @@ Symbol DescriptorBuilder::FindSymbolNotEnforcingDepsHelper( return result; } -Symbol DescriptorBuilder::FindSymbolNotEnforcingDeps(const string& name) { - return FindSymbolNotEnforcingDepsHelper(pool_, name); +Symbol DescriptorBuilder::FindSymbolNotEnforcingDeps(const string& name, + bool build_it) { + return FindSymbolNotEnforcingDepsHelper(pool_, name, build_it); } -Symbol DescriptorBuilder::FindSymbol(const string& name) { - Symbol result = FindSymbolNotEnforcingDeps(name); +Symbol DescriptorBuilder::FindSymbol(const string& name, bool build_it) { + Symbol result = FindSymbolNotEnforcingDeps(name, build_it); if (result.IsNull()) return result; if (!pool_->enforce_dependencies_) { - // Hack for CompilerUpgrader. + // Hack for CompilerUpgrader, and also used for lazily_build_dependencies_ return result; } @@ -3564,14 +3593,16 @@ Symbol DescriptorBuilder::FindSymbol(const string& name) { return kNullSymbol; } -Symbol DescriptorBuilder::LookupSymbolNoPlaceholder( - const string& name, const string& relative_to, ResolveMode resolve_mode) { +Symbol DescriptorBuilder::LookupSymbolNoPlaceholder(const string& name, + const string& relative_to, + ResolveMode resolve_mode, + bool build_it) { possible_undeclared_dependency_ = NULL; undefine_resolved_name_.clear(); - if (name.size() > 0 && name[0] == '.') { + if (!name.empty() && name[0] == '.') { // Fully-qualified name. - return FindSymbol(name.substr(1)); + return FindSymbol(name.substr(1), build_it); } // If name is something like "Foo.Bar.baz", and symbols named "Foo" are @@ -3599,7 +3630,7 @@ Symbol DescriptorBuilder::LookupSymbolNoPlaceholder( // Chop off the last component of the scope. string::size_type dot_pos = scope_to_try.find_last_of('.'); if (dot_pos == string::npos) { - return FindSymbol(name); + return FindSymbol(name, build_it); } else { scope_to_try.erase(dot_pos); } @@ -3608,7 +3639,7 @@ Symbol DescriptorBuilder::LookupSymbolNoPlaceholder( string::size_type old_size = scope_to_try.size(); scope_to_try.append(1, '.'); scope_to_try.append(first_part_of_name); - Symbol result = FindSymbol(scope_to_try); + Symbol result = FindSymbol(scope_to_try, build_it); if (!result.IsNull()) { if (first_part_of_name.size() < name.size()) { // name is a compound symbol, of which we only found the first part. @@ -3616,7 +3647,7 @@ Symbol DescriptorBuilder::LookupSymbolNoPlaceholder( if (result.IsAggregate()) { scope_to_try.append(name, first_part_of_name.size(), name.size() - first_part_of_name.size()); - result = FindSymbol(scope_to_try); + result = FindSymbol(scope_to_try, build_it); if (result.IsNull()) { undefine_resolved_name_ = scope_to_try; } @@ -3640,19 +3671,49 @@ Symbol DescriptorBuilder::LookupSymbolNoPlaceholder( Symbol DescriptorBuilder::LookupSymbol( const string& name, const string& relative_to, - PlaceholderType placeholder_type, ResolveMode resolve_mode) { - Symbol result = LookupSymbolNoPlaceholder( - name, relative_to, resolve_mode); + DescriptorPool::PlaceholderType placeholder_type, ResolveMode resolve_mode, + bool build_it) { + Symbol result = + LookupSymbolNoPlaceholder(name, relative_to, resolve_mode, build_it); if (result.IsNull() && pool_->allow_unknown_) { // Not found, but AllowUnknownDependencies() is enabled. Return a // placeholder instead. - result = NewPlaceholder(name, placeholder_type); + result = pool_->NewPlaceholderWithMutexHeld(name, placeholder_type); } return result; } -Symbol DescriptorBuilder::NewPlaceholder(const string& name, - PlaceholderType placeholder_type) { +static bool ValidateQualifiedName(const string& name) { + bool last_was_period = false; + + for (int i = 0; i < name.size(); i++) { + // I don't trust isalnum() due to locales. :( + if (('a' <= name[i] && name[i] <= 'z') || + ('A' <= name[i] && name[i] <= 'Z') || + ('0' <= name[i] && name[i] <= '9') || (name[i] == '_')) { + last_was_period = false; + } else if (name[i] == '.') { + if (last_was_period) return false; + last_was_period = true; + } else { + return false; + } + } + + return !name.empty() && !last_was_period; +} + +Symbol DescriptorPool::NewPlaceholder(const string& name, + PlaceholderType placeholder_type) const { + MutexLockMaybe lock(mutex_); + return NewPlaceholderWithMutexHeld(name, placeholder_type); +} + +Symbol DescriptorPool::NewPlaceholderWithMutexHeld( + const string& name, PlaceholderType placeholder_type) const { + if (mutex_) { + mutex_->AssertHeld(); + } // Compute names. const string* placeholder_full_name; const string* placeholder_name; @@ -3678,7 +3739,7 @@ Symbol DescriptorBuilder::NewPlaceholder(const string& name, } // Create the placeholders. - FileDescriptor* placeholder_file = NewPlaceholderFile( + FileDescriptor* placeholder_file = NewPlaceholderFileWithMutexHeld( *placeholder_full_name + ".placeholder.proto"); placeholder_file->package_ = placeholder_package; @@ -3744,19 +3805,28 @@ Symbol DescriptorBuilder::NewPlaceholder(const string& name, } } -FileDescriptor* DescriptorBuilder::NewPlaceholderFile( - const string& name) { +FileDescriptor* DescriptorPool::NewPlaceholderFile(const string& name) const { + MutexLockMaybe lock(mutex_); + return NewPlaceholderFileWithMutexHeld(name); +} + +FileDescriptor* DescriptorPool::NewPlaceholderFileWithMutexHeld( + const string& name) const { + if (mutex_) { + mutex_->AssertHeld(); + } FileDescriptor* placeholder = tables_->Allocate(); memset(placeholder, 0, sizeof(*placeholder)); placeholder->name_ = tables_->AllocateString(name); placeholder->package_ = &internal::GetEmptyString(); - placeholder->pool_ = pool_; + placeholder->pool_ = this; placeholder->options_ = &FileOptions::default_instance(); placeholder->tables_ = &FileDescriptorTables::GetEmptyInstance(); placeholder->source_code_info_ = &SourceCodeInfo::default_instance(); placeholder->is_placeholder_ = true; placeholder->syntax_ = FileDescriptor::SYNTAX_PROTO2; + placeholder->finished_building_ = true; // All other fields are zero or NULL. return placeholder; @@ -3850,27 +3920,6 @@ void DescriptorBuilder::ValidateSymbolName( } } -bool DescriptorBuilder::ValidateQualifiedName(const string& name) { - bool last_was_period = false; - - for (int i = 0; i < name.size(); i++) { - // I don't trust isalnum() due to locales. :( - if (('a' <= name[i] && name[i] <= 'z') || - ('A' <= name[i] && name[i] <= 'Z') || - ('0' <= name[i] && name[i] <= '9') || - (name[i] == '_')) { - last_was_period = false; - } else if (name[i] == '.') { - if (last_was_period) return false; - last_was_period = true; - } else { - return false; - } - } - - return !name.empty() && !last_was_period; -} - // ------------------------------------------------------------------- // This generic implementation is good for all descriptors except @@ -4014,20 +4063,22 @@ const FileDescriptor* DescriptorBuilder::BuildFile( } } - // If we have a fallback_database_, attempt to load all dependencies now, - // before checkpointing tables_. This avoids confusion with recursive - // checkpoints. - if (pool_->fallback_database_ != NULL) { - tables_->pending_files_.push_back(proto.name()); - for (int i = 0; i < proto.dependency_size(); i++) { - if (tables_->FindFile(proto.dependency(i)) == NULL && - (pool_->underlay_ == NULL || - pool_->underlay_->FindFileByName(proto.dependency(i)) == NULL)) { - // We don't care what this returns since we'll find out below anyway. - pool_->TryFindFileInFallbackDatabase(proto.dependency(i)); + // If we have a fallback_database_, and we aren't doing lazy import building, + // attempt to load all dependencies now, before checkpointing tables_. This + // avoids confusion with recursive checkpoints. + if (!pool_->lazily_build_dependencies_) { + if (pool_->fallback_database_ != NULL) { + tables_->pending_files_.push_back(proto.name()); + for (int i = 0; i < proto.dependency_size(); i++) { + if (tables_->FindFile(proto.dependency(i)) == NULL && + (pool_->underlay_ == NULL || + pool_->underlay_->FindFileByName(proto.dependency(i)) == NULL)) { + // We don't care what this returns since we'll find out below anyway. + pool_->TryFindFileInFallbackDatabase(proto.dependency(i)); + } } + tables_->pending_files_.pop_back(); } - tables_->pending_files_.pop_back(); } return BuildFileImpl(proto); } @@ -4041,6 +4092,7 @@ const FileDescriptor* DescriptorBuilder::BuildFileImpl( file_ = result; result->is_placeholder_ = false; + result->finished_building_ = false; if (proto.has_source_code_info()) { SourceCodeInfo *info = tables_->AllocateMessage(); info->CopyFrom(proto.source_code_info()); @@ -4098,7 +4150,17 @@ const FileDescriptor* DescriptorBuilder::BuildFileImpl( std::set seen_dependencies; result->dependency_count_ = proto.dependency_size(); result->dependencies_ = - tables_->AllocateArray(proto.dependency_size()); + tables_->AllocateArray(proto.dependency_size()); + if (pool_->lazily_build_dependencies_) { + result->dependencies_once_ = tables_->AllocateOnceDynamic(); + result->dependencies_names_ = + tables_->AllocateArray(proto.dependency_size()); + memset(result->dependencies_names_, 0, + sizeof(*result->dependencies_names_) * proto.dependency_size()); + } else { + result->dependencies_once_ = NULL; + result->dependencies_names_ = NULL; + } unused_dependency_.clear(); std::set weak_deps; for (int i = 0; i < proto.weak_dependency_size(); ++i) { @@ -4125,9 +4187,12 @@ const FileDescriptor* DescriptorBuilder::BuildFileImpl( if (dependency == NULL) { if (pool_->allow_unknown_ || (!pool_->enforce_weak_ && weak_deps.find(i) != weak_deps.end())) { - dependency = NewPlaceholderFile(proto.dependency(i)); + dependency = + pool_->NewPlaceholderFileWithMutexHeld(proto.dependency(i)); } else { - AddImportError(proto, i); + if (!pool_->lazily_build_dependencies_) { + AddImportError(proto, i); + } } } else { // Add to unused_dependency_ to track unused imported files. @@ -4141,6 +4206,10 @@ const FileDescriptor* DescriptorBuilder::BuildFileImpl( } result->dependencies_[i] = dependency; + if (pool_->lazily_build_dependencies_ && !dependency) { + result->dependencies_names_[i] = + tables_->AllocateString(proto.dependency(i)); + } } // Check public dependencies. @@ -4153,7 +4222,12 @@ const FileDescriptor* DescriptorBuilder::BuildFileImpl( if (index >= 0 && index < proto.dependency_size()) { result->public_dependencies_[public_dependency_count++] = index; // Do not track unused imported files for public import. - unused_dependency_.erase(result->dependency(index)); + // Calling dependency(i) builds that file when doing lazy imports, + // need to avoid doing this. Unused dependency detection isn't done + // when building lazily, anyways. + if (!pool_->lazily_build_dependencies_) { + unused_dependency_.erase(result->dependency(index)); + } } else { AddError(proto.name(), proto, DescriptorPool::ErrorCollector::OTHER, @@ -4164,8 +4238,13 @@ const FileDescriptor* DescriptorBuilder::BuildFileImpl( // Build dependency set dependencies_.clear(); - for (int i = 0; i < result->dependency_count(); i++) { - RecordPublicDependencies(result->dependency(i)); + // We don't/can't do proper dependency error checking when + // lazily_build_dependencies_, and calling dependency(i) will force + // a dependency to be built, which we don't want. + if (!pool_->lazily_build_dependencies_) { + for (int i = 0; i < result->dependency_count(); i++) { + RecordPublicDependencies(result->dependency(i)); + } } // Check weak dependencies. @@ -4215,8 +4294,9 @@ const FileDescriptor* DescriptorBuilder::BuildFileImpl( options_to_interpret_.clear(); } - // Validate options. - if (!had_errors_) { + // Validate options. See comments at InternalSetLazilyBuildDependencies about + // error checking and lazy import building. + if (!had_errors_ && !pool_->lazily_build_dependencies_) { ValidateFileOptions(result, proto); } @@ -4229,7 +4309,9 @@ const FileDescriptor* DescriptorBuilder::BuildFileImpl( } - if (!unused_dependency_.empty()) { + // Again, see comments at InternalSetLazilyBuildDependencies about error + // checking. + if (!unused_dependency_.empty() && !pool_->lazily_build_dependencies_) { LogUnusedDependency(proto, result); } @@ -4238,6 +4320,7 @@ const FileDescriptor* DescriptorBuilder::BuildFileImpl( return NULL; } else { tables_->ClearLastCheckpoint(); + result->finished_building_ = true; return result; } } @@ -4447,6 +4530,10 @@ void DescriptorBuilder::BuildFieldOrExtension(const FieldDescriptorProto& proto, result->extension_scope_ = NULL; result->message_type_ = NULL; result->enum_type_ = NULL; + result->type_name_ = NULL; + result->type_once_ = NULL; + result->default_value_enum_ = NULL; + result->default_value_enum_name_ = NULL; result->has_default_value_ = proto.has_default_value(); if (proto.has_default_value() && result->is_repeated()) { @@ -4947,8 +5034,8 @@ void DescriptorBuilder::BuildMethod(const MethodDescriptorProto& proto, ValidateSymbolName(proto.name(), *full_name, proto); // These will be filled in when cross-linking. - result->input_type_ = NULL; - result->output_type_ = NULL; + result->input_type_.Init(); + result->output_type_.Init(); // Copy options. if (!proto.has_options()) { @@ -5081,9 +5168,13 @@ void DescriptorBuilder::CrossLinkField( field->options_ = &FieldOptions::default_instance(); } + // Add the field to the lowercase-name and camelcase-name tables. + file_tables_->AddFieldByStylizedNames(field); + if (proto.has_extendee()) { - Symbol extendee = LookupSymbol(proto.extendee(), field->full_name(), - PLACEHOLDER_EXTENDABLE_MESSAGE); + Symbol extendee = + LookupSymbol(proto.extendee(), field->full_name(), + DescriptorPool::PLACEHOLDER_EXTENDABLE_MESSAGE); if (extendee.IsNull()) { AddNotDefinedError(field->full_name(), proto, DescriptorPool::ErrorCollector::EXTENDEE, @@ -5129,9 +5220,10 @@ void DescriptorBuilder::CrossLinkField( proto.has_default_value(); Symbol type = - LookupSymbol(proto.type_name(), field->full_name(), - expecting_enum ? PLACEHOLDER_ENUM : PLACEHOLDER_MESSAGE, - LOOKUP_TYPES); + LookupSymbol(proto.type_name(), field->full_name(), + expecting_enum ? DescriptorPool::PLACEHOLDER_ENUM + : DescriptorPool::PLACEHOLDER_MESSAGE, + LOOKUP_TYPES, !pool_->lazily_build_dependencies_); // If the type is a weak type, we change the type to a google.protobuf.Empty field. if (type.IsNull() && !pool_->enforce_weak_ && proto.options().weak()) { @@ -5139,10 +5231,35 @@ void DescriptorBuilder::CrossLinkField( } if (type.IsNull()) { - AddNotDefinedError(field->full_name(), proto, - DescriptorPool::ErrorCollector::TYPE, - proto.type_name()); - return; + if (pool_->lazily_build_dependencies_) { + // Save the symbol names for later for lookup, and allocate the once + // object needed for the accessors. + string name = proto.type_name(); + if (!pool_->enforce_weak_ && proto.options().weak()) { + name = kNonLinkedWeakMessageReplacementName; + } + field->type_once_ = tables_->AllocateOnceDynamic(); + field->type_name_ = tables_->AllocateString(name); + if (proto.has_default_value()) { + field->default_value_enum_name_ = + tables_->AllocateString(proto.default_value()); + } + // AddFieldByNumber and AddExtension are done later in this function, + // and can/must be done if the field type was not found. The related + // error checking is not necessary when in lazily_build_dependencies_ + // mode, and can't be done without building the type's descriptor, + // which we don't want to do. + file_tables_->AddFieldByNumber(field); + if (field->is_extension()) { + tables_->AddExtension(field); + } + return; + } else { + AddNotDefinedError(field->full_name(), proto, + DescriptorPool::ErrorCollector::TYPE, + proto.type_name()); + return; + } } if (!proto.has_type()) { @@ -5238,7 +5355,10 @@ void DescriptorBuilder::CrossLinkField( // Add the field to the fields-by-number table. // Note: We have to do this *after* cross-linking because extensions do not - // know their containing type until now. + // know their containing type until now. If we're in + // lazily_build_dependencies_ mode, we're guaranteed there's no errors, so no + // risk to calling containing_type() or other accessors that will build + // dependencies. if (!file_tables_->AddFieldByNumber(field)) { const FieldDescriptor* conflicting_field = file_tables_->FindFieldByNumber(field->containing_type(), @@ -5284,9 +5404,6 @@ void DescriptorBuilder::CrossLinkField( } } } - - // Add the field to the lowercase-name and camelcase-name tables. - file_tables_->AddFieldByStylizedNames(field); } void DescriptorBuilder::CrossLinkEnum( @@ -5325,30 +5442,44 @@ void DescriptorBuilder::CrossLinkMethod( method->options_ = &MethodOptions::default_instance(); } - Symbol input_type = LookupSymbol(proto.input_type(), method->full_name()); + Symbol input_type = + LookupSymbol(proto.input_type(), method->full_name(), + DescriptorPool::PLACEHOLDER_MESSAGE, LOOKUP_ALL, + !pool_->lazily_build_dependencies_); if (input_type.IsNull()) { - AddNotDefinedError(method->full_name(), proto, - DescriptorPool::ErrorCollector::INPUT_TYPE, - proto.input_type()); + if (!pool_->lazily_build_dependencies_) { + AddNotDefinedError(method->full_name(), proto, + DescriptorPool::ErrorCollector::INPUT_TYPE, + proto.input_type()); + } else { + method->input_type_.SetLazy(proto.input_type(), file_); + } } else if (input_type.type != Symbol::MESSAGE) { AddError(method->full_name(), proto, DescriptorPool::ErrorCollector::INPUT_TYPE, "\"" + proto.input_type() + "\" is not a message type."); } else { - method->input_type_ = input_type.descriptor; + method->input_type_.Set(input_type.descriptor); } - Symbol output_type = LookupSymbol(proto.output_type(), method->full_name()); + Symbol output_type = + LookupSymbol(proto.output_type(), method->full_name(), + DescriptorPool::PLACEHOLDER_MESSAGE, LOOKUP_ALL, + !pool_->lazily_build_dependencies_); if (output_type.IsNull()) { - AddNotDefinedError(method->full_name(), proto, - DescriptorPool::ErrorCollector::OUTPUT_TYPE, - proto.output_type()); + if (!pool_->lazily_build_dependencies_) { + AddNotDefinedError(method->full_name(), proto, + DescriptorPool::ErrorCollector::OUTPUT_TYPE, + proto.output_type()); + } else { + method->output_type_.SetLazy(proto.output_type(), file_); + } } else if (output_type.type != Symbol::MESSAGE) { AddError(method->full_name(), proto, DescriptorPool::ErrorCollector::OUTPUT_TYPE, "\"" + proto.output_type() + "\" is not a message type."); } else { - method->output_type_ = output_type.descriptor; + method->output_type_.Set(output_type.descriptor); } } @@ -5539,8 +5670,12 @@ void DescriptorBuilder::ValidateMessageOptions(Descriptor* message, } } + void DescriptorBuilder::ValidateFieldOptions(FieldDescriptor* field, const FieldDescriptorProto& proto) { + if (pool_->lazily_build_dependencies_ && (!field || !field->message_type())) { + return; + } // Only message type fields may be lazy. if (field->options().lazy()) { if (field->type() != FieldDescriptor::TYPE_MESSAGE) { @@ -6553,5 +6688,165 @@ void DescriptorBuilder::LogUnusedDependency(const FileDescriptorProto& proto, } } +Symbol DescriptorPool::CrossLinkOnDemandHelper(const string& name, + bool expecting_enum) const { + string lookup_name = name; + if (!lookup_name.empty() && lookup_name[0] == '.') { + lookup_name = lookup_name.substr(1); + } + Symbol result = tables_->FindByNameHelper(this, lookup_name); + return result; +} + +// Handle the lazy import building for a message field whose type wasn't built +// at cross link time. If that was the case, we saved the name of the type to +// be looked up when the accessor for the type was called. Set type_, +// enum_type_, message_type_, and default_value_enum_ appropriately. +void FieldDescriptor::InternalTypeOnceInit() const { + GOOGLE_CHECK(file()->finished_building_ == true); + if (type_name_) { + Symbol result = file()->pool()->CrossLinkOnDemandHelper( + *type_name_, type_ == FieldDescriptor::TYPE_ENUM); + if (result.type == Symbol::MESSAGE) { + type_ = FieldDescriptor::TYPE_MESSAGE; + message_type_ = result.descriptor; + } else if (result.type == Symbol::ENUM) { + type_ = FieldDescriptor::TYPE_ENUM; + enum_type_ = result.enum_descriptor; + } + } + if (enum_type_ && !default_value_enum_) { + if (default_value_enum_name_) { + // Have to build the full name now instead of at CrossLink time, + // because enum_type_ may not be known at the time. + string name = enum_type_->full_name(); + // Enum values reside in the same scope as the enum type. + string::size_type last_dot = name.find_last_of('.'); + if (last_dot != string::npos) { + name = name.substr(0, last_dot) + "." + *default_value_enum_name_; + } else { + name = *default_value_enum_name_; + } + Symbol result = file()->pool()->CrossLinkOnDemandHelper(name, true); + if (result.type == Symbol::ENUM_VALUE) { + default_value_enum_ = result.enum_value_descriptor; + } + } + if (!default_value_enum_) { + // We use the first defined value as the default + // if a default is not explicitly defined. + GOOGLE_CHECK(enum_type_->value_count()); + default_value_enum_ = enum_type_->value(0); + } + } +} + +void FieldDescriptor::TypeOnceInit(const FieldDescriptor* to_init) { + to_init->InternalTypeOnceInit(); +} + +// message_type(), enum_type(), default_value_enum(), and type() +// all share the same GoogleOnceDynamic init path to do lazy +// import building and cross linking of a field of a message. +const Descriptor* FieldDescriptor::message_type() const { + if (type_once_) { + type_once_->Init(&FieldDescriptor::TypeOnceInit, this); + } + return message_type_; +} + +const EnumDescriptor* FieldDescriptor::enum_type() const { + if (type_once_) { + type_once_->Init(&FieldDescriptor::TypeOnceInit, this); + } + return enum_type_; +} + +const EnumValueDescriptor* FieldDescriptor::default_value_enum() const { + if (type_once_) { + type_once_->Init(&FieldDescriptor::TypeOnceInit, this); + } + return default_value_enum_; +} + +FieldDescriptor::Type FieldDescriptor::type() const { + if (type_once_) { + type_once_->Init(&FieldDescriptor::TypeOnceInit, this); + } + return type_; +} + +void FileDescriptor::InternalDependenciesOnceInit() const { + GOOGLE_CHECK(finished_building_ == true); + for (int i = 0; i < dependency_count(); i++) { + if (dependencies_names_[i]) { + dependencies_[i] = pool_->FindFileByName(*dependencies_names_[i]); + } + } +} + +void FileDescriptor::DependenciesOnceInit(const FileDescriptor* to_init) { + to_init->InternalDependenciesOnceInit(); +} + +const FileDescriptor* FileDescriptor::dependency(int index) const { + if (dependencies_once_) { + // Do once init for all indicies, as it's unlikely only a single index would + // be called, and saves on GoogleOnceDynamic allocations. + dependencies_once_->Init(&FileDescriptor::DependenciesOnceInit, this); + } + return dependencies_[index]; +} + +const Descriptor* MethodDescriptor::input_type() const { + return input_type_.Get(); +} + +const Descriptor* MethodDescriptor::output_type() const { + return output_type_.Get(); +} + + +namespace internal { +void LazyDescriptor::Set(const Descriptor* descriptor) { + GOOGLE_CHECK(!name_); + GOOGLE_CHECK(!once_); + GOOGLE_CHECK(!file_); + descriptor_ = descriptor; +} + +void LazyDescriptor::SetLazy(const string& name, const FileDescriptor* file) { + // verify Init() has been called and Set hasn't been called yet. + GOOGLE_CHECK(!descriptor_); + GOOGLE_CHECK(!file_); + GOOGLE_CHECK(!name_); + GOOGLE_CHECK(!once_); + GOOGLE_CHECK(file && file->pool_); + GOOGLE_CHECK(file->pool_->lazily_build_dependencies_); + GOOGLE_CHECK(!file->finished_building_); + file_ = file; + name_ = file->pool_->tables_->AllocateString(name); + once_ = file->pool_->tables_->AllocateOnceDynamic(); +} + +void LazyDescriptor::Once() { + if (once_) { + once_->Init(&LazyDescriptor::OnceStatic, this); + } +} + +void LazyDescriptor::OnceStatic(LazyDescriptor* lazy) { lazy->OnceInternal(); } + +void LazyDescriptor::OnceInternal() { + GOOGLE_CHECK(file_->finished_building_); + if (!descriptor_ && name_) { + Symbol result = file_->pool_->CrossLinkOnDemandHelper(*name_, false); + if (!result.IsNull() && result.type == Symbol::MESSAGE) { + descriptor_ = result.descriptor; + } + } +} +} // namespace internal + } // namespace protobuf } // namespace google diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/descriptor.h b/third_party/protobuf/3.2.0/src/google/protobuf/descriptor.h index cc09969346..7aea7344da 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/descriptor.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/descriptor.h @@ -63,6 +63,7 @@ #include #include #include +#include // TYPE_BOOL is defined in the MacOS's ConditionalMacros.h. #ifdef TYPE_BOOL @@ -110,6 +111,7 @@ class Message; // Defined in descriptor.cc class DescriptorBuilder; class FileDescriptorTables; +struct Symbol; // Defined in unknown_field_set.h. class UnknownField; @@ -165,6 +167,55 @@ struct DebugStringOptions { elide_oneof_body(false) {} }; +// A class to handle the simplest cases of a lazily linked descriptor +// for a message type that isn't built at the time of cross linking, +// which is needed when a pool has lazily_build_dependencies_ set. +// Must be instantiated as mutable in a descriptor. +namespace internal { +class LIBPROTOBUF_EXPORT LazyDescriptor { + public: + // Init function to be called at init time of a descriptor containing + // a LazyDescriptor. + void Init() { + descriptor_ = NULL; + name_ = NULL; + once_ = NULL; + file_ = NULL; + } + + // Sets the value of the descriptor if it is known during the descriptor + // building process. Not thread safe, should only be called during the + // descriptor build process. Should not be called after SetLazy has been + // called. + void Set(const Descriptor* descriptor); + + // Sets the information needed to lazily cross link the descriptor at a later + // time, SetLazy is not thread safe, should be called only once at descriptor + // build time if the symbol wasn't found and building of the file containing + // that type is delayed because lazily_build_dependencies_ is set on the pool. + // Should not be called after Set() has been called. + void SetLazy(const string& name, const FileDescriptor* file); + + // Returns the current value of the descriptor, thread-safe. If SetLazy(...) + // has been called, will do a one-time cross link of the type specified, + // building the descriptor file that contains the type if necessary. + inline const Descriptor* Get() { + Once(); + return descriptor_; + } + + private: + static void OnceStatic(LazyDescriptor* lazy); + void OnceInternal(); + void Once(); + + const Descriptor* descriptor_; + const string* name_; + GoogleOnceDynamic* once_; + const FileDescriptor* file_; +}; +} // namespace internal + // Describes a type of protocol message, or a particular group within a // message. To obtain the Descriptor for a given message object, call // Message::GetDescriptor(). Generated message classes also have a @@ -417,6 +468,7 @@ class LIBPROTOBUF_EXPORT Descriptor { // Must be constructed using DescriptorPool. Descriptor() {} friend class DescriptorBuilder; + friend class DescriptorPool; friend class EnumDescriptor; friend class FieldDescriptor; friend class OneofDescriptor; @@ -692,16 +744,21 @@ class LIBPROTOBUF_EXPORT FieldDescriptor { const string* json_name_; const FileDescriptor* file_; int number_; - Type type_; + GoogleOnceDynamic* type_once_; + static void TypeOnceInit(const FieldDescriptor* to_init); + void InternalTypeOnceInit() const; + mutable Type type_; Label label_; bool is_extension_; int index_in_oneof_; const Descriptor* containing_type_; const OneofDescriptor* containing_oneof_; const Descriptor* extension_scope_; - const Descriptor* message_type_; - const EnumDescriptor* enum_type_; + mutable const Descriptor* message_type_; + mutable const EnumDescriptor* enum_type_; const FieldOptions* options_; + const string* type_name_; + const string* default_value_enum_name_; // IMPORTANT: If you add a new field, make sure to search for all instances // of Allocate() and AllocateArray() in // descriptor.cc and update them to initialize the field. @@ -716,7 +773,7 @@ class LIBPROTOBUF_EXPORT FieldDescriptor { double default_value_double_; bool default_value_bool_; - const EnumValueDescriptor* default_value_enum_; + mutable const EnumValueDescriptor* default_value_enum_; const string* default_value_string_; }; @@ -918,6 +975,7 @@ class LIBPROTOBUF_EXPORT EnumDescriptor { friend class FieldDescriptor; friend class EnumValueDescriptor; friend class FileDescriptor; + friend class DescriptorPool; friend class internal::GeneratedMessageReflection; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumDescriptor); }; @@ -994,6 +1052,7 @@ class LIBPROTOBUF_EXPORT EnumValueDescriptor { EnumValueDescriptor() {} friend class DescriptorBuilder; friend class EnumDescriptor; + friend class DescriptorPool; friend class FileDescriptorTables; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumValueDescriptor); }; @@ -1144,8 +1203,8 @@ class LIBPROTOBUF_EXPORT MethodDescriptor { const string* name_; const string* full_name_; const ServiceDescriptor* service_; - const Descriptor* input_type_; - const Descriptor* output_type_; + mutable internal::LazyDescriptor input_type_; + mutable internal::LazyDescriptor output_type_; const MethodOptions* options_; bool client_streaming_; bool server_streaming_; @@ -1302,7 +1361,11 @@ class LIBPROTOBUF_EXPORT FileDescriptor { const string* package_; const DescriptorPool* pool_; int dependency_count_; - const FileDescriptor** dependencies_; + mutable const FileDescriptor** dependencies_; + const string** dependencies_names_; + GoogleOnceDynamic* dependencies_once_; + static void DependenciesOnceInit(const FileDescriptor* to_init); + void InternalDependenciesOnceInit() const; int public_dependency_count_; int* public_dependencies_; int weak_dependency_count_; @@ -1321,14 +1384,22 @@ class LIBPROTOBUF_EXPORT FileDescriptor { const FileDescriptorTables* tables_; const SourceCodeInfo* source_code_info_; + + // Indicates the FileDescriptor is completed building. Used to verify + // that type accessor functions that can possibly build a dependent file + // aren't called during the process of building the file. + bool finished_building_; + // IMPORTANT: If you add a new field, make sure to search for all instances // of Allocate() and AllocateArray() in // descriptor.cc and update them to initialize the field. FileDescriptor() {} friend class DescriptorBuilder; + friend class DescriptorPool; friend class Descriptor; friend class FieldDescriptor; + friend class internal::LazyDescriptor; friend class OneofDescriptor; friend class EnumDescriptor; friend class EnumValueDescriptor; @@ -1559,6 +1630,9 @@ class LIBPROTOBUF_EXPORT DescriptorPool { static void InternalAddGeneratedFile( const void* encoded_file_descriptor, int size); + // Disallow [enforce_utf8 = false] in .proto files. + void DisallowEnforceUtf8() { disallow_enforce_utf8_ = true; } + // For internal use only: Gets a non-const pointer to the generated pool. // This is called at static-initialization time only, so thread-safety is @@ -1571,6 +1645,21 @@ class LIBPROTOBUF_EXPORT DescriptorPool { // which it did not officially declare as dependencies. void InternalDontEnforceDependencies(); + // For internal use only: Enables lazy building of dependencies of a file. + // Delay the building of dependencies of a file descriptor until absolutely + // necessary, like when message_type() is called on a field that is defined + // in that dependency's file. This will cause functional issues if a proto + // or one of it's dependencies has errors. Should only be enabled for the + // generated_pool_ (because no descriptor build errors are guaranteed by + // the compilation generation process), testing, or if a lack of descriptor + // build errors can be guaranteed for a pool. + void InternalSetLazilyBuildDependencies() { + lazily_build_dependencies_ = true; + // This needs to be set when lazily building dependencies, as it breaks + // dependency checking. + InternalDontEnforceDependencies(); + } + // For internal use only. void internal_set_underlay(const DescriptorPool* underlay) { underlay_ = underlay; @@ -1589,10 +1678,13 @@ class LIBPROTOBUF_EXPORT DescriptorPool { private: friend class Descriptor; + friend class internal::LazyDescriptor; friend class FieldDescriptor; friend class EnumDescriptor; friend class ServiceDescriptor; + friend class MethodDescriptor; friend class FileDescriptor; + friend class StreamDescriptor; friend class DescriptorBuilder; friend class FileDescriptorTables; @@ -1616,6 +1708,28 @@ class LIBPROTOBUF_EXPORT DescriptorPool { const FileDescriptor* BuildFileFromDatabase( const FileDescriptorProto& proto) const; + // Helper for when lazily_build_dependencies_ is set, can look up a symbol + // after the file's descriptor is built, and can build the file where that + // symbol is defined if necessary. Will create a placeholder if the type + // doesn't exist in the fallback database, or the file doesn't build + // successfully. + Symbol CrossLinkOnDemandHelper(const string& name, bool expecting_enum) const; + + // Create a placeholder FileDescriptor of the specified name + FileDescriptor* NewPlaceholderFile(const string& name) const; + FileDescriptor* NewPlaceholderFileWithMutexHeld(const string& name) const; + + enum PlaceholderType { + PLACEHOLDER_MESSAGE, + PLACEHOLDER_ENUM, + PLACEHOLDER_EXTENDABLE_MESSAGE + }; + // Create a placeholder Descriptor of the specified name + Symbol NewPlaceholder(const string& name, + PlaceholderType placeholder_type) const; + Symbol NewPlaceholderWithMutexHeld(const string& name, + PlaceholderType placeholder_type) const; + // If fallback_database_ is NULL, this is NULL. Otherwise, this is a mutex // which must be locked while accessing tables_. Mutex* mutex_; @@ -1631,9 +1745,11 @@ class LIBPROTOBUF_EXPORT DescriptorPool { google::protobuf::scoped_ptr tables_; bool enforce_dependencies_; + bool lazily_build_dependencies_; bool allow_unknown_; bool enforce_weak_; std::set unused_import_track_files_; + bool disallow_enforce_utf8_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorPool); }; @@ -1693,15 +1809,12 @@ PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, camelcase_name) PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, file, const FileDescriptor*) PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, number, int) PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, is_extension, bool) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, type, FieldDescriptor::Type) PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, label, FieldDescriptor::Label) PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, containing_type, const Descriptor*) PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, containing_oneof, const OneofDescriptor*) PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, index_in_oneof, int) PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, extension_scope, const Descriptor*) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, message_type, const Descriptor*) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, enum_type, const EnumDescriptor*) PROTOBUF_DEFINE_OPTIONS_ACCESSOR(FieldDescriptor, FieldOptions) PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, has_default_value, bool) PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, has_json_name, bool) @@ -1712,8 +1825,6 @@ PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_uint64, uint64) PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_float , float ) PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_double, double) PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_bool , bool ) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_enum, - const EnumValueDescriptor*) PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, default_value_string) PROTOBUF_DEFINE_STRING_ACCESSOR(OneofDescriptor, name) @@ -1749,8 +1860,6 @@ PROTOBUF_DEFINE_OPTIONS_ACCESSOR(ServiceDescriptor, ServiceOptions) PROTOBUF_DEFINE_STRING_ACCESSOR(MethodDescriptor, name) PROTOBUF_DEFINE_STRING_ACCESSOR(MethodDescriptor, full_name) PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, service, const ServiceDescriptor*) -PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, input_type, const Descriptor*) -PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, output_type, const Descriptor*) PROTOBUF_DEFINE_OPTIONS_ACCESSOR(MethodDescriptor, MethodOptions) PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, client_streaming, bool) PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, server_streaming, bool) @@ -1824,7 +1933,7 @@ inline bool FieldDescriptor::is_packable() const { // in the parent's array of children. inline int FieldDescriptor::index() const { if (!is_extension_) { - return static_cast(this - containing_type_->fields_); + return static_cast(this - containing_type()->fields_); } else if (extension_scope_ != NULL) { return static_cast(this - extension_scope_->extensions_); } else { @@ -1865,15 +1974,15 @@ inline int MethodDescriptor::index() const { } inline const char* FieldDescriptor::type_name() const { - return kTypeToName[type_]; + return kTypeToName[type()]; } inline FieldDescriptor::CppType FieldDescriptor::cpp_type() const { - return kTypeToCppTypeMap[type_]; + return kTypeToCppTypeMap[type()]; } inline const char* FieldDescriptor::cpp_type_name() const { - return kCppTypeToName[kTypeToCppTypeMap[type_]]; + return kCppTypeToName[kTypeToCppTypeMap[type()]]; } inline FieldDescriptor::CppType FieldDescriptor::TypeToCppType(Type type) { @@ -1895,18 +2004,14 @@ inline bool FieldDescriptor::IsTypePackable(Type field_type) { field_type != FieldDescriptor::TYPE_BYTES); } -inline const FileDescriptor* FileDescriptor::dependency(int index) const { - return dependencies_[index]; -} - inline const FileDescriptor* FileDescriptor::public_dependency( int index) const { - return dependencies_[public_dependencies_[index]]; + return dependency(public_dependencies_[index]); } inline const FileDescriptor* FileDescriptor::weak_dependency( int index) const { - return dependencies_[weak_dependencies_[index]]; + return dependency(weak_dependencies_[index]); } inline FileDescriptor::Syntax FileDescriptor::syntax() const { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/descriptor.pb.cc b/third_party/protobuf/3.2.0/src/google/protobuf/descriptor.pb.cc index 57fbfd86cc..56c395e6b8 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/descriptor.pb.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/descriptor.pb.cc @@ -80,17 +80,57 @@ const ::google::protobuf::EnumDescriptor* file_level_enum_descriptors[6]; } // namespace +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField + const TableStruct::entries[] = { + {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, +}; + +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField + const TableStruct::aux[] = { + ::google::protobuf::internal::AuxillaryParseTableField(), +}; +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const + TableStruct::schema[] = { + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, +}; + const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorSet, _has_bits_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorSet, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorSet, file_), ~0u, GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, _has_bits_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, package_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, dependency_), @@ -119,6 +159,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ExtensionRange, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ExtensionRange, start_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ExtensionRange, end_), 0, @@ -127,6 +168,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ReservedRange, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ReservedRange, start_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ReservedRange, end_), 0, @@ -135,6 +177,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, field_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, extension_), @@ -159,6 +202,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, number_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, label_), @@ -173,8 +217,8 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { 6, 8, 9, - 1, 2, + 1, 3, 7, 4, @@ -183,6 +227,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofDescriptorProto, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofDescriptorProto, name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofDescriptorProto, options_), 0, @@ -191,6 +236,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumDescriptorProto, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumDescriptorProto, name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumDescriptorProto, value_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumDescriptorProto, options_), @@ -201,6 +247,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueDescriptorProto, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueDescriptorProto, name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueDescriptorProto, number_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueDescriptorProto, options_), @@ -211,6 +258,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceDescriptorProto, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceDescriptorProto, name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceDescriptorProto, method_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceDescriptorProto, options_), @@ -221,6 +269,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, input_type_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, output_type_), @@ -237,6 +286,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, _internal_metadata_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, _extensions_), ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, java_package_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, java_outer_classname_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, java_multiple_files_), @@ -275,6 +325,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, _internal_metadata_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, _extensions_), ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, message_set_wire_format_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, no_standard_descriptor_accessor_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, deprecated_), @@ -289,6 +340,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, _internal_metadata_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, _extensions_), ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, ctype_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, packed_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, jstype_), @@ -297,22 +349,24 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, weak_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, uninterpreted_option_), 0, - 2, 1, + 5, + 2, 3, 4, - 5, ~0u, GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofOptions, _has_bits_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofOptions, _internal_metadata_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofOptions, _extensions_), ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofOptions, uninterpreted_option_), ~0u, GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, _has_bits_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, _internal_metadata_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, _extensions_), ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, allow_alias_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, deprecated_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, uninterpreted_option_), @@ -323,6 +377,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueOptions, _internal_metadata_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueOptions, _extensions_), ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueOptions, deprecated_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueOptions, uninterpreted_option_), 0, @@ -331,6 +386,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceOptions, _internal_metadata_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceOptions, _extensions_), ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceOptions, deprecated_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceOptions, uninterpreted_option_), 0, @@ -339,6 +395,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, _internal_metadata_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, _extensions_), ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, deprecated_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, idempotency_level_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, uninterpreted_option_), @@ -349,6 +406,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption_NamePart, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption_NamePart, name_part_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption_NamePart, is_extension_), 0, @@ -357,6 +415,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, identifier_value_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, positive_int_value_), @@ -375,6 +434,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, path_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, span_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, leading_comments_), @@ -389,12 +449,14 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo, location_), ~0u, GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, _has_bits_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, path_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, source_file_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, begin_), @@ -407,36 +469,37 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo, annotation_), ~0u, }; static const ::google::protobuf::internal::MigrationSchema schemas[] = { - { 0, 5, sizeof(FileDescriptorSet)}, - { 6, 22, sizeof(FileDescriptorProto)}, - { 34, 40, sizeof(DescriptorProto_ExtensionRange)}, - { 42, 48, sizeof(DescriptorProto_ReservedRange)}, - { 50, 64, sizeof(DescriptorProto)}, - { 74, 88, sizeof(FieldDescriptorProto)}, - { 98, 104, sizeof(OneofDescriptorProto)}, - { 106, 113, sizeof(EnumDescriptorProto)}, - { 116, 123, sizeof(EnumValueDescriptorProto)}, - { 126, 133, sizeof(ServiceDescriptorProto)}, - { 136, 146, sizeof(MethodDescriptorProto)}, - { 152, 173, sizeof(FileOptions)}, - { 190, 199, sizeof(MessageOptions)}, - { 204, 215, sizeof(FieldOptions)}, - { 222, 227, sizeof(OneofOptions)}, - { 228, 235, sizeof(EnumOptions)}, - { 238, 244, sizeof(EnumValueOptions)}, - { 246, 252, sizeof(ServiceOptions)}, - { 254, 261, sizeof(MethodOptions)}, - { 264, 270, sizeof(UninterpretedOption_NamePart)}, - { 272, 283, sizeof(UninterpretedOption)}, - { 290, 299, sizeof(SourceCodeInfo_Location)}, - { 304, 309, sizeof(SourceCodeInfo)}, - { 310, 318, sizeof(GeneratedCodeInfo_Annotation)}, - { 322, 327, sizeof(GeneratedCodeInfo)}, + { 0, 6, sizeof(FileDescriptorSet)}, + { 7, 24, sizeof(FileDescriptorProto)}, + { 36, 43, sizeof(DescriptorProto_ExtensionRange)}, + { 45, 52, sizeof(DescriptorProto_ReservedRange)}, + { 54, 69, sizeof(DescriptorProto)}, + { 79, 94, sizeof(FieldDescriptorProto)}, + { 104, 111, sizeof(OneofDescriptorProto)}, + { 113, 121, sizeof(EnumDescriptorProto)}, + { 124, 132, sizeof(EnumValueDescriptorProto)}, + { 135, 143, sizeof(ServiceDescriptorProto)}, + { 146, 157, sizeof(MethodDescriptorProto)}, + { 163, 185, sizeof(FileOptions)}, + { 202, 212, sizeof(MessageOptions)}, + { 217, 229, sizeof(FieldOptions)}, + { 236, 242, sizeof(OneofOptions)}, + { 243, 251, sizeof(EnumOptions)}, + { 254, 261, sizeof(EnumValueOptions)}, + { 263, 270, sizeof(ServiceOptions)}, + { 272, 280, sizeof(MethodOptions)}, + { 283, 290, sizeof(UninterpretedOption_NamePart)}, + { 292, 304, sizeof(UninterpretedOption)}, + { 311, 321, sizeof(SourceCodeInfo_Location)}, + { 326, 332, sizeof(SourceCodeInfo)}, + { 333, 342, sizeof(GeneratedCodeInfo_Annotation)}, + { 346, 352, sizeof(GeneratedCodeInfo)}, }; static ::google::protobuf::Message const * const file_default_instances[] = { @@ -681,67 +744,67 @@ void AddDescriptorsImpl() { "\001(\t\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.goo" "gle.protobuf.UninterpretedOption\":\n\014Opti" "mizeMode\022\t\n\005SPEED\020\001\022\r\n\tCODE_SIZE\020\002\022\020\n\014LI" - "TE_RUNTIME\020\003*\t\010\350\007\020\200\200\200\200\002J\004\010&\020\'\"\354\001\n\016Messag" + "TE_RUNTIME\020\003*\t\010\350\007\020\200\200\200\200\002J\004\010&\020\'\"\362\001\n\016Messag" "eOptions\022&\n\027message_set_wire_format\030\001 \001(" "\010:\005false\022.\n\037no_standard_descriptor_acces" "sor\030\002 \001(\010:\005false\022\031\n\ndeprecated\030\003 \001(\010:\005fa" "lse\022\021\n\tmap_entry\030\007 \001(\010\022C\n\024uninterpreted_" "option\030\347\007 \003(\0132$.google.protobuf.Uninterp" - "retedOption*\t\010\350\007\020\200\200\200\200\002J\004\010\010\020\t\"\236\003\n\014FieldOp" - "tions\022:\n\005ctype\030\001 \001(\0162#.google.protobuf.F" - "ieldOptions.CType:\006STRING\022\016\n\006packed\030\002 \001(" - "\010\022\?\n\006jstype\030\006 \001(\0162$.google.protobuf.Fiel" - "dOptions.JSType:\tJS_NORMAL\022\023\n\004lazy\030\005 \001(\010" - ":\005false\022\031\n\ndeprecated\030\003 \001(\010:\005false\022\023\n\004we" - "ak\030\n \001(\010:\005false\022C\n\024uninterpreted_option\030" - "\347\007 \003(\0132$.google.protobuf.UninterpretedOp" - "tion\"/\n\005CType\022\n\n\006STRING\020\000\022\010\n\004CORD\020\001\022\020\n\014S" - "TRING_PIECE\020\002\"5\n\006JSType\022\r\n\tJS_NORMAL\020\000\022\r" - "\n\tJS_STRING\020\001\022\r\n\tJS_NUMBER\020\002*\t\010\350\007\020\200\200\200\200\002J" - "\004\010\004\020\005\"^\n\014OneofOptions\022C\n\024uninterpreted_o" + "retedOption*\t\010\350\007\020\200\200\200\200\002J\004\010\010\020\tJ\004\010\t\020\n\"\236\003\n\014F" + "ieldOptions\022:\n\005ctype\030\001 \001(\0162#.google.prot" + "obuf.FieldOptions.CType:\006STRING\022\016\n\006packe" + "d\030\002 \001(\010\022\?\n\006jstype\030\006 \001(\0162$.google.protobu" + "f.FieldOptions.JSType:\tJS_NORMAL\022\023\n\004lazy" + "\030\005 \001(\010:\005false\022\031\n\ndeprecated\030\003 \001(\010:\005false" + "\022\023\n\004weak\030\n \001(\010:\005false\022C\n\024uninterpreted_o" "ption\030\347\007 \003(\0132$.google.protobuf.Uninterpr" - "etedOption*\t\010\350\007\020\200\200\200\200\002\"\215\001\n\013EnumOptions\022\023\n" - "\013allow_alias\030\002 \001(\010\022\031\n\ndeprecated\030\003 \001(\010:\005" - "false\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.g" - "oogle.protobuf.UninterpretedOption*\t\010\350\007\020" - "\200\200\200\200\002\"}\n\020EnumValueOptions\022\031\n\ndeprecated\030" - "\001 \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\"{\n\016ServiceOptions\022\031\n\ndeprec" - "ated\030! \001(\010:\005false\022C\n\024uninterpreted_optio" - "n\030\347\007 \003(\0132$.google.protobuf.Uninterpreted" - "Option*\t\010\350\007\020\200\200\200\200\002\"\255\002\n\rMethodOptions\022\031\n\nd" - "eprecated\030! \001(\010:\005false\022_\n\021idempotency_le" - "vel\030\" \001(\0162/.google.protobuf.MethodOption" - "s.IdempotencyLevel:\023IDEMPOTENCY_UNKNOWN\022" - "C\n\024uninterpreted_option\030\347\007 \003(\0132$.google." - "protobuf.UninterpretedOption\"P\n\020Idempote" - "ncyLevel\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" - "-.google.protobuf.UninterpretedOption.Na" - "mePart\022\030\n\020identifier_value\030\003 \001(\t\022\032\n\022posi" - "tive_int_value\030\004 \001(\004\022\032\n\022negative_int_val" - "ue\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" - "\010NamePart\022\021\n\tname_part\030\001 \002(\t\022\024\n\014is_exten" - "sion\030\002 \002(\010\"\325\001\n\016SourceCodeInfo\022:\n\010locatio" - "n\030\001 \003(\0132(.google.protobuf.SourceCodeInfo" - ".Location\032\206\001\n\010Location\022\020\n\004path\030\001 \003(\005B\002\020\001" - "\022\020\n\004span\030\002 \003(\005B\002\020\001\022\030\n\020leading_comments\030\003" - " \001(\t\022\031\n\021trailing_comments\030\004 \001(\t\022!\n\031leadi" - "ng_detached_comments\030\006 \003(\t\"\247\001\n\021Generated" - "CodeInfo\022A\n\nannotation\030\001 \003(\0132-.google.pr" - "otobuf.GeneratedCodeInfo.Annotation\032O\n\nA" - "nnotation\022\020\n\004path\030\001 \003(\005B\002\020\001\022\023\n\013source_fi" - "le\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\001" - "Z>github.com/golang/protobuf/protoc-gen-" - "go/descriptor;descriptor\242\002\003GPB\252\002\032Google." - "Protobuf.Reflection" + "etedOption\"/\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_NORM" + "AL\020\000\022\r\n\tJS_STRING\020\001\022\r\n\tJS_NUMBER\020\002*\t\010\350\007\020" + "\200\200\200\200\002J\004\010\004\020\005\"^\n\014OneofOptions\022C\n\024uninterpr" + "eted_option\030\347\007 \003(\0132$.google.protobuf.Uni" + "nterpretedOption*\t\010\350\007\020\200\200\200\200\002\"\223\001\n\013EnumOpti" + "ons\022\023\n\013allow_alias\030\002 \001(\010\022\031\n\ndeprecated\030\003" + " \001(\010:\005false\022C\n\024uninterpreted_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:\005false\022C\n\024uninterprete" + "d_option\030\347\007 \003(\0132$.google.protobuf.Uninte" + "rpretedOption*\t\010\350\007\020\200\200\200\200\002\"{\n\016ServiceOptio" + "ns\022\031\n\ndeprecated\030! \001(\010:\005false\022C\n\024uninter" + "preted_option\030\347\007 \003(\0132$.google.protobuf.U" + "ninterpretedOption*\t\010\350\007\020\200\200\200\200\002\"\255\002\n\rMethod" + "Options\022\031\n\ndeprecated\030! \001(\010:\005false\022_\n\021id" + "empotency_level\030\" \001(\0162/.google.protobuf." + "MethodOptions.IdempotencyLevel:\023IDEMPOTE" + "NCY_UNKNOWN\022C\n\024uninterpreted_option\030\347\007 \003" + "(\0132$.google.protobuf.UninterpretedOption" + "\"P\n\020IdempotencyLevel\022\027\n\023IDEMPOTENCY_UNKN" + "OWN\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-.google.protobuf.Uninterpre" + "tedOption.NamePart\022\030\n\020identifier_value\030\003" + " \001(\t\022\032\n\022positive_int_value\030\004 \001(\004\022\032\n\022nega" + "tive_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_va" + "lue\030\010 \001(\t\0323\n\010NamePart\022\021\n\tname_part\030\001 \002(\t" + "\022\024\n\014is_extension\030\002 \002(\010\"\325\001\n\016SourceCodeInf" + "o\022:\n\010location\030\001 \003(\0132(.google.protobuf.So" + "urceCodeInfo.Location\032\206\001\n\010Location\022\020\n\004pa" + "th\030\001 \003(\005B\002\020\001\022\020\n\004span\030\002 \003(\005B\002\020\001\022\030\n\020leadin" + "g_comments\030\003 \001(\t\022\031\n\021trailing_comments\030\004 " + "\001(\t\022!\n\031leading_detached_comments\030\006 \003(\t\"\247" + "\001\n\021GeneratedCodeInfo\022A\n\nannotation\030\001 \003(\013" + "2-.google.protobuf.GeneratedCodeInfo.Ann" + "otation\032O\n\nAnnotation\022\020\n\004path\030\001 \003(\005B\002\020\001\022" + "\023\n\013source_file\030\002 \001(\t\022\r\n\005begin\030\003 \001(\005\022\013\n\003e" + "nd\030\004 \001(\005B\214\001\n\023com.google.protobufB\020Descri" + "ptorProtosH\001Z>github.com/golang/protobuf" + "/protoc-gen-go/descriptor;descriptor\242\002\003G" + "PB\252\002\032Google.Protobuf.Reflection" }; ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( - descriptor, 5579); + descriptor, 5591); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/descriptor.proto", &protobuf_RegisterTypes); ::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown); @@ -972,7 +1035,7 @@ void FileDescriptorSet::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* FileDescriptorSet::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[0].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const FileDescriptorSet& FileDescriptorSet::default_instance() { @@ -1009,13 +1072,11 @@ bool FileDescriptorSet::MergePartialFromCodedStream( case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(10u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_file())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -1044,6 +1105,9 @@ failure: void FileDescriptorSet::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.FileDescriptorSet) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // repeated .google.protobuf.FileDescriptorProto file = 1; for (unsigned int i = 0, n = this->file_size(); i < n; i++) { ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( @@ -1059,13 +1123,15 @@ 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; + // repeated .google.protobuf.FileDescriptorProto file = 1; for (unsigned int i = 0, n = this->file_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 1, this->file(i), false, target); + 1, this->file(i), deterministic, target); } if (_internal_metadata_.have_unknown_fields()) { @@ -1122,6 +1188,9 @@ void FileDescriptorSet::MergeFrom(const FileDescriptorSet& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FileDescriptorSet) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + file_.MergeFrom(from.file_); } @@ -1149,7 +1218,7 @@ void FileDescriptorSet::Swap(FileDescriptorSet* other) { InternalSwap(other); } void FileDescriptorSet::InternalSwap(FileDescriptorSet* other) { - file_.UnsafeArenaSwap(&other->file_); + file_.InternalSwap(&other->file_); std::swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); std::swap(_cached_size_, other->_cached_size_); @@ -1157,7 +1226,7 @@ void FileDescriptorSet::InternalSwap(FileDescriptorSet* other) { ::google::protobuf::Metadata FileDescriptorSet::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[0]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -1226,12 +1295,12 @@ FileDescriptorProto::FileDescriptorProto(const FileDescriptorProto& from) _has_bits_(from._has_bits_), _cached_size_(0), dependency_(from.dependency_), - public_dependency_(from.public_dependency_), - weak_dependency_(from.weak_dependency_), message_type_(from.message_type_), enum_type_(from.enum_type_), service_(from.service_), - extension_(from.extension_) { + extension_(from.extension_), + public_dependency_(from.public_dependency_), + weak_dependency_(from.weak_dependency_) { _internal_metadata_.MergeFrom(from._internal_metadata_); name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); if (from.has_name()) { @@ -1291,7 +1360,7 @@ void FileDescriptorProto::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* FileDescriptorProto::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[1].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const FileDescriptorProto& FileDescriptorProto::default_instance() { @@ -1310,12 +1379,12 @@ FileDescriptorProto* FileDescriptorProto::New(::google::protobuf::Arena* arena) void FileDescriptorProto::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FileDescriptorProto) dependency_.Clear(); - public_dependency_.Clear(); - weak_dependency_.Clear(); message_type_.Clear(); enum_type_.Clear(); service_.Clear(); extension_.Clear(); + public_dependency_.Clear(); + weak_dependency_.Clear(); if (_has_bits_[0 / 32] & 31u) { if (has_name()) { GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); @@ -1405,13 +1474,11 @@ bool FileDescriptorProto::MergePartialFromCodedStream( case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(34u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_message_type())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -1419,13 +1486,11 @@ bool FileDescriptorProto::MergePartialFromCodedStream( case 5: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(42u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_enum_type())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -1433,13 +1498,11 @@ bool FileDescriptorProto::MergePartialFromCodedStream( case 6: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(50u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_service())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -1447,13 +1510,11 @@ bool FileDescriptorProto::MergePartialFromCodedStream( case 7: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(58u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_extension())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -1558,8 +1619,12 @@ failure: void FileDescriptorProto::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.FileDescriptorProto) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; // optional string name = 1; - if (has_name()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->name().data(), this->name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -1569,7 +1634,7 @@ void FileDescriptorProto::SerializeWithCachedSizes( } // optional string package = 2; - if (has_package()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->package().data(), this->package().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -1613,13 +1678,13 @@ void FileDescriptorProto::SerializeWithCachedSizes( } // optional .google.protobuf.FileOptions options = 8; - if (has_options()) { + if (cached_has_bits & 0x00000008u) { ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( 8, *this->options_, output); } // optional .google.protobuf.SourceCodeInfo source_code_info = 9; - if (has_source_code_info()) { + if (cached_has_bits & 0x00000010u) { ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( 9, *this->source_code_info_, output); } @@ -1637,7 +1702,7 @@ void FileDescriptorProto::SerializeWithCachedSizes( } // optional string syntax = 12; - if (has_syntax()) { + if (cached_has_bits & 0x00000004u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->syntax().data(), this->syntax().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -1655,10 +1720,13 @@ 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; + + cached_has_bits = _has_bits_[0]; // optional string name = 1; - if (has_name()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->name().data(), this->name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -1669,7 +1737,7 @@ void FileDescriptorProto::SerializeWithCachedSizes( } // optional string package = 2; - if (has_package()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->package().data(), this->package().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -1693,58 +1761,54 @@ void FileDescriptorProto::SerializeWithCachedSizes( for (unsigned int i = 0, n = this->message_type_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 4, this->message_type(i), false, target); + 4, this->message_type(i), deterministic, target); } // repeated .google.protobuf.EnumDescriptorProto enum_type = 5; for (unsigned int i = 0, n = this->enum_type_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 5, this->enum_type(i), false, target); + 5, this->enum_type(i), deterministic, target); } // repeated .google.protobuf.ServiceDescriptorProto service = 6; for (unsigned int i = 0, n = this->service_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 6, this->service(i), false, target); + 6, this->service(i), deterministic, target); } // repeated .google.protobuf.FieldDescriptorProto extension = 7; for (unsigned int i = 0, n = this->extension_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 7, this->extension(i), false, target); + 7, this->extension(i), deterministic, target); } // optional .google.protobuf.FileOptions options = 8; - if (has_options()) { + if (cached_has_bits & 0x00000008u) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 8, *this->options_, false, target); + 8, *this->options_, deterministic, target); } // optional .google.protobuf.SourceCodeInfo source_code_info = 9; - if (has_source_code_info()) { + if (cached_has_bits & 0x00000010u) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 9, *this->source_code_info_, false, target); + 9, *this->source_code_info_, deterministic, target); } // repeated int32 public_dependency = 10; - for (int i = 0, n = this->public_dependency_size(); i < n; i++) { - target = ::google::protobuf::internal::WireFormatLite:: - WriteInt32ToArray(10, this->public_dependency(i), target); - } + target = ::google::protobuf::internal::WireFormatLite:: + WriteInt32ToArray(10, this->public_dependency_, target); // repeated int32 weak_dependency = 11; - for (int i = 0, n = this->weak_dependency_size(); i < n; i++) { - target = ::google::protobuf::internal::WireFormatLite:: - WriteInt32ToArray(11, this->weak_dependency(i), target); - } + target = ::google::protobuf::internal::WireFormatLite:: + WriteInt32ToArray(11, this->weak_dependency_, target); // optional string syntax = 12; - if (has_syntax()) { + if (cached_has_bits & 0x00000004u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->syntax().data(), this->syntax().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -1779,24 +1843,6 @@ size_t FileDescriptorProto::ByteSizeLong() const { this->dependency(i)); } - // repeated int32 public_dependency = 10; - { - size_t data_size = ::google::protobuf::internal::WireFormatLite:: - Int32Size(this->public_dependency_); - total_size += 1 * - ::google::protobuf::internal::FromIntSize(this->public_dependency_size()); - total_size += data_size; - } - - // repeated int32 weak_dependency = 11; - { - size_t data_size = ::google::protobuf::internal::WireFormatLite:: - Int32Size(this->weak_dependency_); - total_size += 1 * - ::google::protobuf::internal::FromIntSize(this->weak_dependency_size()); - total_size += data_size; - } - // repeated .google.protobuf.DescriptorProto message_type = 4; { unsigned int count = this->message_type_size(); @@ -1841,6 +1887,24 @@ size_t FileDescriptorProto::ByteSizeLong() const { } } + // repeated int32 public_dependency = 10; + { + size_t data_size = ::google::protobuf::internal::WireFormatLite:: + Int32Size(this->public_dependency_); + total_size += 1 * + ::google::protobuf::internal::FromIntSize(this->public_dependency_size()); + total_size += data_size; + } + + // repeated int32 weak_dependency = 11; + { + size_t data_size = ::google::protobuf::internal::WireFormatLite:: + Int32Size(this->weak_dependency_); + total_size += 1 * + ::google::protobuf::internal::FromIntSize(this->weak_dependency_size()); + total_size += data_size; + } + if (_has_bits_[0 / 32] & 31u) { // optional string name = 1; if (has_name()) { @@ -1904,30 +1968,34 @@ void FileDescriptorProto::MergeFrom(const FileDescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FileDescriptorProto) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + dependency_.MergeFrom(from.dependency_); - public_dependency_.MergeFrom(from.public_dependency_); - weak_dependency_.MergeFrom(from.weak_dependency_); message_type_.MergeFrom(from.message_type_); enum_type_.MergeFrom(from.enum_type_); service_.MergeFrom(from.service_); extension_.MergeFrom(from.extension_); - if (from._has_bits_[0 / 32] & 31u) { - if (from.has_name()) { + public_dependency_.MergeFrom(from.public_dependency_); + weak_dependency_.MergeFrom(from.weak_dependency_); + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 31u) { + if (cached_has_bits & 0x00000001u) { set_has_name(); name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); } - if (from.has_package()) { + if (cached_has_bits & 0x00000002u) { set_has_package(); package_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.package_); } - if (from.has_syntax()) { + if (cached_has_bits & 0x00000004u) { set_has_syntax(); syntax_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.syntax_); } - if (from.has_options()) { + if (cached_has_bits & 0x00000008u) { mutable_options()->::google::protobuf::FileOptions::MergeFrom(from.options()); } - if (from.has_source_code_info()) { + if (cached_has_bits & 0x00000010u) { mutable_source_code_info()->::google::protobuf::SourceCodeInfo::MergeFrom(from.source_code_info()); } } @@ -1963,13 +2031,13 @@ void FileDescriptorProto::Swap(FileDescriptorProto* other) { InternalSwap(other); } void FileDescriptorProto::InternalSwap(FileDescriptorProto* other) { - dependency_.UnsafeArenaSwap(&other->dependency_); - public_dependency_.UnsafeArenaSwap(&other->public_dependency_); - weak_dependency_.UnsafeArenaSwap(&other->weak_dependency_); - message_type_.UnsafeArenaSwap(&other->message_type_); - enum_type_.UnsafeArenaSwap(&other->enum_type_); - service_.UnsafeArenaSwap(&other->service_); - extension_.UnsafeArenaSwap(&other->extension_); + dependency_.InternalSwap(&other->dependency_); + message_type_.InternalSwap(&other->message_type_); + enum_type_.InternalSwap(&other->enum_type_); + service_.InternalSwap(&other->service_); + extension_.InternalSwap(&other->extension_); + public_dependency_.InternalSwap(&other->public_dependency_); + weak_dependency_.InternalSwap(&other->weak_dependency_); name_.Swap(&other->name_); package_.Swap(&other->package_); syntax_.Swap(&other->syntax_); @@ -1982,7 +2050,7 @@ void FileDescriptorProto::InternalSwap(FileDescriptorProto* other) { ::google::protobuf::Metadata FileDescriptorProto::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[1]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -2020,6 +2088,7 @@ void FileDescriptorProto::set_name(::std::string&& value) { } #endif void FileDescriptorProto::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileDescriptorProto.name) @@ -2082,6 +2151,7 @@ void FileDescriptorProto::set_package(::std::string&& value) { } #endif void FileDescriptorProto::set_package(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_package(); package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileDescriptorProto.package) @@ -2138,6 +2208,7 @@ void FileDescriptorProto::set_dependency(int index, ::std::string&& value) { } #endif void FileDescriptorProto::set_dependency(int index, const char* value) { + GOOGLE_DCHECK(value != NULL); dependency_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.FileDescriptorProto.dependency) } @@ -2156,11 +2227,12 @@ void FileDescriptorProto::add_dependency(const ::std::string& value) { } #if LANG_CXX11 void FileDescriptorProto::add_dependency(::std::string&& value) { - dependency_.Add()->assign(std::move(value)); + dependency_.Add(std::move(value)); // @@protoc_insertion_point(field_add:google.protobuf.FileDescriptorProto.dependency) } #endif void FileDescriptorProto::add_dependency(const char* value) { + GOOGLE_DCHECK(value != NULL); dependency_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.FileDescriptorProto.dependency) } @@ -2481,6 +2553,7 @@ void FileDescriptorProto::set_syntax(::std::string&& value) { } #endif void FileDescriptorProto::set_syntax(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_syntax(); syntax_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileDescriptorProto.syntax) @@ -2561,7 +2634,7 @@ void DescriptorProto_ExtensionRange::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* DescriptorProto_ExtensionRange::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[2].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const DescriptorProto_ExtensionRange& DescriptorProto_ExtensionRange::default_instance() { @@ -2650,13 +2723,17 @@ failure: void DescriptorProto_ExtensionRange::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.DescriptorProto.ExtensionRange) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; // optional int32 start = 1; - if (has_start()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormatLite::WriteInt32(1, this->start(), output); } // optional int32 end = 2; - if (has_end()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormatLite::WriteInt32(2, this->end(), output); } @@ -2669,15 +2746,18 @@ 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; + + cached_has_bits = _has_bits_[0]; // optional int32 start = 1; - if (has_start()) { + if (cached_has_bits & 0x00000001u) { target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(1, this->start(), target); } // optional int32 end = 2; - if (has_end()) { + if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(2, this->end(), target); } @@ -2740,13 +2820,18 @@ void DescriptorProto_ExtensionRange::MergeFrom(const DescriptorProto_ExtensionRa // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DescriptorProto.ExtensionRange) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); - if (from._has_bits_[0 / 32] & 3u) { - if (from.has_start()) { - set_start(from.start()); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 3u) { + if (cached_has_bits & 0x00000001u) { + start_ = from.start_; } - if (from.has_end()) { - set_end(from.end()); + if (cached_has_bits & 0x00000002u) { + end_ = from.end_; } + _has_bits_[0] |= cached_has_bits; } } @@ -2782,7 +2867,7 @@ void DescriptorProto_ExtensionRange::InternalSwap(DescriptorProto_ExtensionRange ::google::protobuf::Metadata DescriptorProto_ExtensionRange::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[2]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -2886,7 +2971,7 @@ void DescriptorProto_ReservedRange::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* DescriptorProto_ReservedRange::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[3].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const DescriptorProto_ReservedRange& DescriptorProto_ReservedRange::default_instance() { @@ -2975,13 +3060,17 @@ failure: void DescriptorProto_ReservedRange::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.DescriptorProto.ReservedRange) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; // optional int32 start = 1; - if (has_start()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormatLite::WriteInt32(1, this->start(), output); } // optional int32 end = 2; - if (has_end()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormatLite::WriteInt32(2, this->end(), output); } @@ -2994,15 +3083,18 @@ 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; + + cached_has_bits = _has_bits_[0]; // optional int32 start = 1; - if (has_start()) { + if (cached_has_bits & 0x00000001u) { target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(1, this->start(), target); } // optional int32 end = 2; - if (has_end()) { + if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(2, this->end(), target); } @@ -3065,13 +3157,18 @@ void DescriptorProto_ReservedRange::MergeFrom(const DescriptorProto_ReservedRang // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DescriptorProto.ReservedRange) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); - if (from._has_bits_[0 / 32] & 3u) { - if (from.has_start()) { - set_start(from.start()); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 3u) { + if (cached_has_bits & 0x00000001u) { + start_ = from.start_; } - if (from.has_end()) { - set_end(from.end()); + if (cached_has_bits & 0x00000002u) { + end_ = from.end_; } + _has_bits_[0] |= cached_has_bits; } } @@ -3107,7 +3204,7 @@ void DescriptorProto_ReservedRange::InternalSwap(DescriptorProto_ReservedRange* ::google::protobuf::Metadata DescriptorProto_ReservedRange::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[3]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -3192,10 +3289,10 @@ DescriptorProto::DescriptorProto(const DescriptorProto& from) _has_bits_(from._has_bits_), _cached_size_(0), field_(from.field_), - extension_(from.extension_), nested_type_(from.nested_type_), enum_type_(from.enum_type_), extension_range_(from.extension_range_), + extension_(from.extension_), oneof_decl_(from.oneof_decl_), reserved_range_(from.reserved_range_), reserved_name_(from.reserved_name_) { @@ -3237,7 +3334,7 @@ void DescriptorProto::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* DescriptorProto::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[4].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const DescriptorProto& DescriptorProto::default_instance() { @@ -3256,10 +3353,10 @@ DescriptorProto* DescriptorProto::New(::google::protobuf::Arena* arena) const { void DescriptorProto::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.DescriptorProto) field_.Clear(); - extension_.Clear(); nested_type_.Clear(); enum_type_.Clear(); extension_range_.Clear(); + extension_.Clear(); oneof_decl_.Clear(); reserved_range_.Clear(); reserved_name_.Clear(); @@ -3307,13 +3404,11 @@ bool DescriptorProto::MergePartialFromCodedStream( case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(18u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_field())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -3321,13 +3416,11 @@ bool DescriptorProto::MergePartialFromCodedStream( case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(26u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_nested_type())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -3335,13 +3428,11 @@ bool DescriptorProto::MergePartialFromCodedStream( case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(34u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_enum_type())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -3349,13 +3440,11 @@ bool DescriptorProto::MergePartialFromCodedStream( case 5: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(42u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_extension_range())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -3363,13 +3452,11 @@ bool DescriptorProto::MergePartialFromCodedStream( case 6: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(50u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_extension())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -3389,13 +3476,11 @@ bool DescriptorProto::MergePartialFromCodedStream( case 8: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(66u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_oneof_decl())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -3403,13 +3488,11 @@ bool DescriptorProto::MergePartialFromCodedStream( case 9: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(74u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_reserved_range())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -3455,8 +3538,12 @@ failure: void DescriptorProto::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.DescriptorProto) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; // optional string name = 1; - if (has_name()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->name().data(), this->name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -3496,7 +3583,7 @@ void DescriptorProto::SerializeWithCachedSizes( } // optional .google.protobuf.MessageOptions options = 7; - if (has_options()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( 7, *this->options_, output); } @@ -3532,10 +3619,13 @@ 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; + + cached_has_bits = _has_bits_[0]; // optional string name = 1; - if (has_name()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->name().data(), this->name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -3549,56 +3639,56 @@ void DescriptorProto::SerializeWithCachedSizes( for (unsigned int i = 0, n = this->field_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 2, this->field(i), false, target); + 2, this->field(i), deterministic, target); } // repeated .google.protobuf.DescriptorProto nested_type = 3; for (unsigned int i = 0, n = this->nested_type_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 3, this->nested_type(i), false, target); + 3, this->nested_type(i), deterministic, target); } // repeated .google.protobuf.EnumDescriptorProto enum_type = 4; for (unsigned int i = 0, n = this->enum_type_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 4, this->enum_type(i), false, target); + 4, this->enum_type(i), deterministic, target); } // repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; for (unsigned int i = 0, n = this->extension_range_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 5, this->extension_range(i), false, target); + 5, this->extension_range(i), deterministic, target); } // repeated .google.protobuf.FieldDescriptorProto extension = 6; for (unsigned int i = 0, n = this->extension_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 6, this->extension(i), false, target); + 6, this->extension(i), deterministic, target); } // optional .google.protobuf.MessageOptions options = 7; - if (has_options()) { + if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 7, *this->options_, false, target); + 7, *this->options_, deterministic, target); } // repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8; for (unsigned int i = 0, n = this->oneof_decl_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 8, this->oneof_decl(i), false, target); + 8, this->oneof_decl(i), deterministic, target); } // repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9; for (unsigned int i = 0, n = this->reserved_range_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 9, this->reserved_range(i), false, target); + 9, this->reserved_range(i), deterministic, target); } // repeated string reserved_name = 10; @@ -3639,17 +3729,6 @@ size_t DescriptorProto::ByteSizeLong() const { } } - // repeated .google.protobuf.FieldDescriptorProto extension = 6; - { - unsigned int count = this->extension_size(); - total_size += 1UL * count; - for (unsigned int i = 0; i < count; i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->extension(i)); - } - } - // repeated .google.protobuf.DescriptorProto nested_type = 3; { unsigned int count = this->nested_type_size(); @@ -3683,6 +3762,17 @@ size_t DescriptorProto::ByteSizeLong() const { } } + // repeated .google.protobuf.FieldDescriptorProto extension = 6; + { + unsigned int count = this->extension_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->extension(i)); + } + } + // repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8; { unsigned int count = this->oneof_decl_size(); @@ -3755,20 +3845,24 @@ void DescriptorProto::MergeFrom(const DescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DescriptorProto) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + field_.MergeFrom(from.field_); - extension_.MergeFrom(from.extension_); nested_type_.MergeFrom(from.nested_type_); enum_type_.MergeFrom(from.enum_type_); extension_range_.MergeFrom(from.extension_range_); + extension_.MergeFrom(from.extension_); oneof_decl_.MergeFrom(from.oneof_decl_); reserved_range_.MergeFrom(from.reserved_range_); reserved_name_.MergeFrom(from.reserved_name_); - if (from._has_bits_[0 / 32] & 3u) { - if (from.has_name()) { + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 3u) { + if (cached_has_bits & 0x00000001u) { set_has_name(); name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); } - if (from.has_options()) { + if (cached_has_bits & 0x00000002u) { mutable_options()->::google::protobuf::MessageOptions::MergeFrom(from.options()); } } @@ -3790,9 +3884,9 @@ void DescriptorProto::CopyFrom(const DescriptorProto& from) { bool DescriptorProto::IsInitialized() const { if (!::google::protobuf::internal::AllAreInitialized(this->field())) return false; - if (!::google::protobuf::internal::AllAreInitialized(this->extension())) return false; if (!::google::protobuf::internal::AllAreInitialized(this->nested_type())) return false; if (!::google::protobuf::internal::AllAreInitialized(this->enum_type())) return false; + if (!::google::protobuf::internal::AllAreInitialized(this->extension())) return false; if (!::google::protobuf::internal::AllAreInitialized(this->oneof_decl())) return false; if (has_options()) { if (!this->options_->IsInitialized()) return false; @@ -3805,14 +3899,14 @@ void DescriptorProto::Swap(DescriptorProto* other) { InternalSwap(other); } void DescriptorProto::InternalSwap(DescriptorProto* other) { - field_.UnsafeArenaSwap(&other->field_); - extension_.UnsafeArenaSwap(&other->extension_); - nested_type_.UnsafeArenaSwap(&other->nested_type_); - enum_type_.UnsafeArenaSwap(&other->enum_type_); - extension_range_.UnsafeArenaSwap(&other->extension_range_); - oneof_decl_.UnsafeArenaSwap(&other->oneof_decl_); - reserved_range_.UnsafeArenaSwap(&other->reserved_range_); - reserved_name_.UnsafeArenaSwap(&other->reserved_name_); + field_.InternalSwap(&other->field_); + nested_type_.InternalSwap(&other->nested_type_); + enum_type_.InternalSwap(&other->enum_type_); + extension_range_.InternalSwap(&other->extension_range_); + extension_.InternalSwap(&other->extension_); + oneof_decl_.InternalSwap(&other->oneof_decl_); + reserved_range_.InternalSwap(&other->reserved_range_); + reserved_name_.InternalSwap(&other->reserved_name_); name_.Swap(&other->name_); std::swap(options_, other->options_); std::swap(_has_bits_[0], other->_has_bits_[0]); @@ -3822,7 +3916,7 @@ void DescriptorProto::InternalSwap(DescriptorProto* other) { ::google::protobuf::Metadata DescriptorProto::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[4]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -3860,6 +3954,7 @@ void DescriptorProto::set_name(::std::string&& value) { } #endif void DescriptorProto::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.DescriptorProto.name) @@ -4171,6 +4266,7 @@ void DescriptorProto::set_reserved_name(int index, ::std::string&& value) { } #endif void DescriptorProto::set_reserved_name(int index, const char* value) { + GOOGLE_DCHECK(value != NULL); reserved_name_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.DescriptorProto.reserved_name) } @@ -4189,11 +4285,12 @@ void DescriptorProto::add_reserved_name(const ::std::string& value) { } #if LANG_CXX11 void DescriptorProto::add_reserved_name(::std::string&& value) { - reserved_name_.Add()->assign(std::move(value)); + reserved_name_.Add(std::move(value)); // @@protoc_insertion_point(field_add:google.protobuf.DescriptorProto.reserved_name) } #endif void DescriptorProto::add_reserved_name(const char* value) { + GOOGLE_DCHECK(value != NULL); reserved_name_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.DescriptorProto.reserved_name) } @@ -4247,14 +4344,14 @@ FieldDescriptorProto::FieldDescriptorProto(const FieldDescriptorProto& from) if (from.has_name()) { name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); } - type_name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (from.has_type_name()) { - type_name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.type_name_); - } extendee_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); if (from.has_extendee()) { extendee_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.extendee_); } + type_name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + if (from.has_type_name()) { + type_name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.type_name_); + } default_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); if (from.has_default_value()) { default_value_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.default_value_); @@ -4277,8 +4374,8 @@ FieldDescriptorProto::FieldDescriptorProto(const FieldDescriptorProto& from) void FieldDescriptorProto::SharedCtor() { _cached_size_ = 0; name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - type_name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); extendee_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + type_name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); default_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); json_name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); ::memset(&options_, 0, reinterpret_cast(&oneof_index_) - @@ -4294,8 +4391,8 @@ FieldDescriptorProto::~FieldDescriptorProto() { void FieldDescriptorProto::SharedDtor() { name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - type_name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); extendee_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + type_name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); default_value_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); json_name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); if (this != internal_default_instance()) { @@ -4310,7 +4407,7 @@ void FieldDescriptorProto::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* FieldDescriptorProto::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[5].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const FieldDescriptorProto& FieldDescriptorProto::default_instance() { @@ -4333,14 +4430,14 @@ void FieldDescriptorProto::Clear() { GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*name_.UnsafeRawStringPointer())->clear(); } - if (has_type_name()) { - GOOGLE_DCHECK(!type_name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); - (*type_name_.UnsafeRawStringPointer())->clear(); - } if (has_extendee()) { GOOGLE_DCHECK(!extendee_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*extendee_.UnsafeRawStringPointer())->clear(); } + if (has_type_name()) { + GOOGLE_DCHECK(!type_name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); + (*type_name_.UnsafeRawStringPointer())->clear(); + } if (has_default_value()) { GOOGLE_DCHECK(!default_value_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*default_value_.UnsafeRawStringPointer())->clear(); @@ -4559,8 +4656,12 @@ failure: void FieldDescriptorProto::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.FieldDescriptorProto) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; // optional string name = 1; - if (has_name()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->name().data(), this->name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -4570,7 +4671,7 @@ void FieldDescriptorProto::SerializeWithCachedSizes( } // optional string extendee = 2; - if (has_extendee()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->extendee().data(), this->extendee().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -4580,24 +4681,24 @@ void FieldDescriptorProto::SerializeWithCachedSizes( } // optional int32 number = 3; - if (has_number()) { + if (cached_has_bits & 0x00000040u) { ::google::protobuf::internal::WireFormatLite::WriteInt32(3, this->number(), output); } // optional .google.protobuf.FieldDescriptorProto.Label label = 4; - if (has_label()) { + if (cached_has_bits & 0x00000100u) { ::google::protobuf::internal::WireFormatLite::WriteEnum( 4, this->label(), output); } // optional .google.protobuf.FieldDescriptorProto.Type type = 5; - if (has_type()) { + if (cached_has_bits & 0x00000200u) { ::google::protobuf::internal::WireFormatLite::WriteEnum( 5, this->type(), output); } // optional string type_name = 6; - if (has_type_name()) { + if (cached_has_bits & 0x00000004u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->type_name().data(), this->type_name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -4607,7 +4708,7 @@ void FieldDescriptorProto::SerializeWithCachedSizes( } // optional string default_value = 7; - if (has_default_value()) { + if (cached_has_bits & 0x00000008u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->default_value().data(), this->default_value().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -4617,18 +4718,18 @@ void FieldDescriptorProto::SerializeWithCachedSizes( } // optional .google.protobuf.FieldOptions options = 8; - if (has_options()) { + if (cached_has_bits & 0x00000020u) { ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( 8, *this->options_, output); } // optional int32 oneof_index = 9; - if (has_oneof_index()) { + if (cached_has_bits & 0x00000080u) { ::google::protobuf::internal::WireFormatLite::WriteInt32(9, this->oneof_index(), output); } // optional string json_name = 10; - if (has_json_name()) { + if (cached_has_bits & 0x00000010u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->json_name().data(), this->json_name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -4646,10 +4747,13 @@ 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; + + cached_has_bits = _has_bits_[0]; // optional string name = 1; - if (has_name()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->name().data(), this->name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -4660,7 +4764,7 @@ void FieldDescriptorProto::SerializeWithCachedSizes( } // optional string extendee = 2; - if (has_extendee()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->extendee().data(), this->extendee().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -4671,24 +4775,24 @@ void FieldDescriptorProto::SerializeWithCachedSizes( } // optional int32 number = 3; - if (has_number()) { + if (cached_has_bits & 0x00000040u) { target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(3, this->number(), target); } // optional .google.protobuf.FieldDescriptorProto.Label label = 4; - if (has_label()) { + if (cached_has_bits & 0x00000100u) { target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray( 4, this->label(), target); } // optional .google.protobuf.FieldDescriptorProto.Type type = 5; - if (has_type()) { + if (cached_has_bits & 0x00000200u) { target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray( 5, this->type(), target); } // optional string type_name = 6; - if (has_type_name()) { + if (cached_has_bits & 0x00000004u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->type_name().data(), this->type_name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -4699,7 +4803,7 @@ void FieldDescriptorProto::SerializeWithCachedSizes( } // optional string default_value = 7; - if (has_default_value()) { + if (cached_has_bits & 0x00000008u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->default_value().data(), this->default_value().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -4710,19 +4814,19 @@ void FieldDescriptorProto::SerializeWithCachedSizes( } // optional .google.protobuf.FieldOptions options = 8; - if (has_options()) { + if (cached_has_bits & 0x00000020u) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 8, *this->options_, false, target); + 8, *this->options_, deterministic, target); } // optional int32 oneof_index = 9; - if (has_oneof_index()) { + if (cached_has_bits & 0x00000080u) { target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(9, this->oneof_index(), target); } // optional string json_name = 10; - if (has_json_name()) { + if (cached_has_bits & 0x00000010u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->json_name().data(), this->json_name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -4757,18 +4861,18 @@ size_t FieldDescriptorProto::ByteSizeLong() const { this->name()); } - // optional string type_name = 6; - if (has_type_name()) { + // optional string extendee = 2; + if (has_extendee()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( - this->type_name()); + this->extendee()); } - // optional string extendee = 2; - if (has_extendee()) { + // optional string type_name = 6; + if (has_type_name()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( - this->extendee()); + this->type_name()); } // optional string default_value = 7; @@ -4847,44 +4951,50 @@ void FieldDescriptorProto::MergeFrom(const FieldDescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldDescriptorProto) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); - if (from._has_bits_[0 / 32] & 255u) { - if (from.has_name()) { + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 255u) { + if (cached_has_bits & 0x00000001u) { set_has_name(); name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); } - if (from.has_type_name()) { - set_has_type_name(); - type_name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.type_name_); - } - if (from.has_extendee()) { + if (cached_has_bits & 0x00000002u) { set_has_extendee(); extendee_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.extendee_); } - if (from.has_default_value()) { + if (cached_has_bits & 0x00000004u) { + set_has_type_name(); + type_name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.type_name_); + } + if (cached_has_bits & 0x00000008u) { set_has_default_value(); default_value_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.default_value_); } - if (from.has_json_name()) { + if (cached_has_bits & 0x00000010u) { set_has_json_name(); json_name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.json_name_); } - if (from.has_options()) { + if (cached_has_bits & 0x00000020u) { mutable_options()->::google::protobuf::FieldOptions::MergeFrom(from.options()); } - if (from.has_number()) { - set_number(from.number()); + if (cached_has_bits & 0x00000040u) { + number_ = from.number_; } - if (from.has_oneof_index()) { - set_oneof_index(from.oneof_index()); + if (cached_has_bits & 0x00000080u) { + oneof_index_ = from.oneof_index_; } + _has_bits_[0] |= cached_has_bits; } - if (from._has_bits_[8 / 32] & 768u) { - if (from.has_label()) { - set_label(from.label()); + if (cached_has_bits & 768u) { + if (cached_has_bits & 0x00000100u) { + label_ = from.label_; } - if (from.has_type()) { - set_type(from.type()); + if (cached_has_bits & 0x00000200u) { + type_ = from.type_; } + _has_bits_[0] |= cached_has_bits; } } @@ -4915,8 +5025,8 @@ void FieldDescriptorProto::Swap(FieldDescriptorProto* other) { } void FieldDescriptorProto::InternalSwap(FieldDescriptorProto* other) { name_.Swap(&other->name_); - type_name_.Swap(&other->type_name_); extendee_.Swap(&other->extendee_); + type_name_.Swap(&other->type_name_); default_value_.Swap(&other->default_value_); json_name_.Swap(&other->json_name_); std::swap(options_, other->options_); @@ -4931,7 +5041,7 @@ void FieldDescriptorProto::InternalSwap(FieldDescriptorProto* other) { ::google::protobuf::Metadata FieldDescriptorProto::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[5]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -4969,6 +5079,7 @@ void FieldDescriptorProto::set_name(::std::string&& value) { } #endif void FieldDescriptorProto::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FieldDescriptorProto.name) @@ -5075,13 +5186,13 @@ void FieldDescriptorProto::set_type(::google::protobuf::FieldDescriptorProto_Typ // optional string type_name = 6; bool FieldDescriptorProto::has_type_name() const { - return (_has_bits_[0] & 0x00000002u) != 0; + return (_has_bits_[0] & 0x00000004u) != 0; } void FieldDescriptorProto::set_has_type_name() { - _has_bits_[0] |= 0x00000002u; + _has_bits_[0] |= 0x00000004u; } void FieldDescriptorProto::clear_has_type_name() { - _has_bits_[0] &= ~0x00000002u; + _has_bits_[0] &= ~0x00000004u; } void FieldDescriptorProto::clear_type_name() { type_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); @@ -5105,6 +5216,7 @@ void FieldDescriptorProto::set_type_name(::std::string&& value) { } #endif void FieldDescriptorProto::set_type_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_type_name(); type_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FieldDescriptorProto.type_name) @@ -5137,13 +5249,13 @@ void FieldDescriptorProto::set_allocated_type_name(::std::string* type_name) { // optional string extendee = 2; bool FieldDescriptorProto::has_extendee() const { - return (_has_bits_[0] & 0x00000004u) != 0; + return (_has_bits_[0] & 0x00000002u) != 0; } void FieldDescriptorProto::set_has_extendee() { - _has_bits_[0] |= 0x00000004u; + _has_bits_[0] |= 0x00000002u; } void FieldDescriptorProto::clear_has_extendee() { - _has_bits_[0] &= ~0x00000004u; + _has_bits_[0] &= ~0x00000002u; } void FieldDescriptorProto::clear_extendee() { extendee_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); @@ -5167,6 +5279,7 @@ void FieldDescriptorProto::set_extendee(::std::string&& value) { } #endif void FieldDescriptorProto::set_extendee(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_extendee(); extendee_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FieldDescriptorProto.extendee) @@ -5229,6 +5342,7 @@ void FieldDescriptorProto::set_default_value(::std::string&& value) { } #endif void FieldDescriptorProto::set_default_value(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_default_value(); default_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FieldDescriptorProto.default_value) @@ -5315,6 +5429,7 @@ void FieldDescriptorProto::set_json_name(::std::string&& value) { } #endif void FieldDescriptorProto::set_json_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_json_name(); json_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FieldDescriptorProto.json_name) @@ -5450,7 +5565,7 @@ void OneofDescriptorProto::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* OneofDescriptorProto::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[6].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const OneofDescriptorProto& OneofDescriptorProto::default_instance() { @@ -5545,8 +5660,12 @@ failure: void OneofDescriptorProto::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.OneofDescriptorProto) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; // optional string name = 1; - if (has_name()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->name().data(), this->name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -5556,7 +5675,7 @@ void OneofDescriptorProto::SerializeWithCachedSizes( } // optional .google.protobuf.OneofOptions options = 2; - if (has_options()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( 2, *this->options_, output); } @@ -5570,10 +5689,13 @@ 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; + + cached_has_bits = _has_bits_[0]; // optional string name = 1; - if (has_name()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->name().data(), this->name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -5584,10 +5706,10 @@ void OneofDescriptorProto::SerializeWithCachedSizes( } // optional .google.protobuf.OneofOptions options = 2; - if (has_options()) { + if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 2, *this->options_, false, target); + 2, *this->options_, deterministic, target); } if (_internal_metadata_.have_unknown_fields()) { @@ -5649,12 +5771,16 @@ void OneofDescriptorProto::MergeFrom(const OneofDescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.OneofDescriptorProto) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); - if (from._has_bits_[0 / 32] & 3u) { - if (from.has_name()) { + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 3u) { + if (cached_has_bits & 0x00000001u) { set_has_name(); name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); } - if (from.has_options()) { + if (cached_has_bits & 0x00000002u) { mutable_options()->::google::protobuf::OneofOptions::MergeFrom(from.options()); } } @@ -5695,7 +5821,7 @@ void OneofDescriptorProto::InternalSwap(OneofDescriptorProto* other) { ::google::protobuf::Metadata OneofDescriptorProto::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[6]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -5733,6 +5859,7 @@ void OneofDescriptorProto::set_name(::std::string&& value) { } #endif void OneofDescriptorProto::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.OneofDescriptorProto.name) @@ -5870,7 +5997,7 @@ void EnumDescriptorProto::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* EnumDescriptorProto::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[7].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const EnumDescriptorProto& EnumDescriptorProto::default_instance() { @@ -5933,13 +6060,11 @@ bool EnumDescriptorProto::MergePartialFromCodedStream( case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(18u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_value())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -5980,8 +6105,12 @@ failure: void EnumDescriptorProto::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.EnumDescriptorProto) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; // optional string name = 1; - if (has_name()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->name().data(), this->name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -5997,7 +6126,7 @@ void EnumDescriptorProto::SerializeWithCachedSizes( } // optional .google.protobuf.EnumOptions options = 3; - if (has_options()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( 3, *this->options_, output); } @@ -6011,10 +6140,13 @@ 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; + + cached_has_bits = _has_bits_[0]; // optional string name = 1; - if (has_name()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->name().data(), this->name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -6028,14 +6160,14 @@ void EnumDescriptorProto::SerializeWithCachedSizes( for (unsigned int i = 0, n = this->value_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 2, this->value(i), false, target); + 2, this->value(i), deterministic, target); } // optional .google.protobuf.EnumOptions options = 3; - if (has_options()) { + if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 3, *this->options_, false, target); + 3, *this->options_, deterministic, target); } if (_internal_metadata_.have_unknown_fields()) { @@ -6108,13 +6240,17 @@ void EnumDescriptorProto::MergeFrom(const EnumDescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumDescriptorProto) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + value_.MergeFrom(from.value_); - if (from._has_bits_[0 / 32] & 3u) { - if (from.has_name()) { + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 3u) { + if (cached_has_bits & 0x00000001u) { set_has_name(); name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); } - if (from.has_options()) { + if (cached_has_bits & 0x00000002u) { mutable_options()->::google::protobuf::EnumOptions::MergeFrom(from.options()); } } @@ -6147,7 +6283,7 @@ void EnumDescriptorProto::Swap(EnumDescriptorProto* other) { InternalSwap(other); } void EnumDescriptorProto::InternalSwap(EnumDescriptorProto* other) { - value_.UnsafeArenaSwap(&other->value_); + value_.InternalSwap(&other->value_); name_.Swap(&other->name_); std::swap(options_, other->options_); std::swap(_has_bits_[0], other->_has_bits_[0]); @@ -6157,7 +6293,7 @@ void EnumDescriptorProto::InternalSwap(EnumDescriptorProto* other) { ::google::protobuf::Metadata EnumDescriptorProto::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[7]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -6195,6 +6331,7 @@ void EnumDescriptorProto::set_name(::std::string&& value) { } #endif void EnumDescriptorProto::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.EnumDescriptorProto.name) @@ -6363,7 +6500,7 @@ void EnumValueDescriptorProto::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* EnumValueDescriptorProto::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[8].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const EnumValueDescriptorProto& EnumValueDescriptorProto::default_instance() { @@ -6473,8 +6610,12 @@ failure: void EnumValueDescriptorProto::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.EnumValueDescriptorProto) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; // optional string name = 1; - if (has_name()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->name().data(), this->name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -6484,12 +6625,12 @@ void EnumValueDescriptorProto::SerializeWithCachedSizes( } // optional int32 number = 2; - if (has_number()) { + if (cached_has_bits & 0x00000004u) { ::google::protobuf::internal::WireFormatLite::WriteInt32(2, this->number(), output); } // optional .google.protobuf.EnumValueOptions options = 3; - if (has_options()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( 3, *this->options_, output); } @@ -6503,10 +6644,13 @@ 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; + + cached_has_bits = _has_bits_[0]; // optional string name = 1; - if (has_name()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->name().data(), this->name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -6517,15 +6661,15 @@ void EnumValueDescriptorProto::SerializeWithCachedSizes( } // optional int32 number = 2; - if (has_number()) { + if (cached_has_bits & 0x00000004u) { target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(2, this->number(), target); } // optional .google.protobuf.EnumValueOptions options = 3; - if (has_options()) { + if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 3, *this->options_, false, target); + 3, *this->options_, deterministic, target); } if (_internal_metadata_.have_unknown_fields()) { @@ -6594,17 +6738,22 @@ void EnumValueDescriptorProto::MergeFrom(const EnumValueDescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumValueDescriptorProto) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); - if (from._has_bits_[0 / 32] & 7u) { - if (from.has_name()) { + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 7u) { + if (cached_has_bits & 0x00000001u) { set_has_name(); name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); } - if (from.has_options()) { + if (cached_has_bits & 0x00000002u) { mutable_options()->::google::protobuf::EnumValueOptions::MergeFrom(from.options()); } - if (from.has_number()) { - set_number(from.number()); + if (cached_has_bits & 0x00000004u) { + number_ = from.number_; } + _has_bits_[0] |= cached_has_bits; } } @@ -6644,7 +6793,7 @@ void EnumValueDescriptorProto::InternalSwap(EnumValueDescriptorProto* other) { ::google::protobuf::Metadata EnumValueDescriptorProto::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[8]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -6682,6 +6831,7 @@ void EnumValueDescriptorProto::set_name(::std::string&& value) { } #endif void EnumValueDescriptorProto::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.EnumValueDescriptorProto.name) @@ -6843,7 +6993,7 @@ void ServiceDescriptorProto::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* ServiceDescriptorProto::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[9].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const ServiceDescriptorProto& ServiceDescriptorProto::default_instance() { @@ -6906,13 +7056,11 @@ bool ServiceDescriptorProto::MergePartialFromCodedStream( case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(18u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_method())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -6953,8 +7101,12 @@ failure: void ServiceDescriptorProto::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.ServiceDescriptorProto) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; // optional string name = 1; - if (has_name()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->name().data(), this->name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -6970,7 +7122,7 @@ void ServiceDescriptorProto::SerializeWithCachedSizes( } // optional .google.protobuf.ServiceOptions options = 3; - if (has_options()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( 3, *this->options_, output); } @@ -6984,10 +7136,13 @@ 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; + + cached_has_bits = _has_bits_[0]; // optional string name = 1; - if (has_name()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->name().data(), this->name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -7001,14 +7156,14 @@ void ServiceDescriptorProto::SerializeWithCachedSizes( for (unsigned int i = 0, n = this->method_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 2, this->method(i), false, target); + 2, this->method(i), deterministic, target); } // optional .google.protobuf.ServiceOptions options = 3; - if (has_options()) { + if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 3, *this->options_, false, target); + 3, *this->options_, deterministic, target); } if (_internal_metadata_.have_unknown_fields()) { @@ -7081,13 +7236,17 @@ void ServiceDescriptorProto::MergeFrom(const ServiceDescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ServiceDescriptorProto) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + method_.MergeFrom(from.method_); - if (from._has_bits_[0 / 32] & 3u) { - if (from.has_name()) { + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 3u) { + if (cached_has_bits & 0x00000001u) { set_has_name(); name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); } - if (from.has_options()) { + if (cached_has_bits & 0x00000002u) { mutable_options()->::google::protobuf::ServiceOptions::MergeFrom(from.options()); } } @@ -7120,7 +7279,7 @@ void ServiceDescriptorProto::Swap(ServiceDescriptorProto* other) { InternalSwap(other); } void ServiceDescriptorProto::InternalSwap(ServiceDescriptorProto* other) { - method_.UnsafeArenaSwap(&other->method_); + method_.InternalSwap(&other->method_); name_.Swap(&other->name_); std::swap(options_, other->options_); std::swap(_has_bits_[0], other->_has_bits_[0]); @@ -7130,7 +7289,7 @@ void ServiceDescriptorProto::InternalSwap(ServiceDescriptorProto* other) { ::google::protobuf::Metadata ServiceDescriptorProto::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[9]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -7168,6 +7327,7 @@ void ServiceDescriptorProto::set_name(::std::string&& value) { } #endif void ServiceDescriptorProto::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.ServiceDescriptorProto.name) @@ -7353,7 +7513,7 @@ void MethodDescriptorProto::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* MethodDescriptorProto::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[10].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const MethodDescriptorProto& MethodDescriptorProto::default_instance() { @@ -7520,8 +7680,12 @@ failure: void MethodDescriptorProto::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.MethodDescriptorProto) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; // optional string name = 1; - if (has_name()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->name().data(), this->name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -7531,7 +7695,7 @@ void MethodDescriptorProto::SerializeWithCachedSizes( } // optional string input_type = 2; - if (has_input_type()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->input_type().data(), this->input_type().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -7541,7 +7705,7 @@ void MethodDescriptorProto::SerializeWithCachedSizes( } // optional string output_type = 3; - if (has_output_type()) { + if (cached_has_bits & 0x00000004u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->output_type().data(), this->output_type().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -7551,18 +7715,18 @@ void MethodDescriptorProto::SerializeWithCachedSizes( } // optional .google.protobuf.MethodOptions options = 4; - if (has_options()) { + if (cached_has_bits & 0x00000008u) { ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( 4, *this->options_, output); } // optional bool client_streaming = 5 [default = false]; - if (has_client_streaming()) { + if (cached_has_bits & 0x00000010u) { ::google::protobuf::internal::WireFormatLite::WriteBool(5, this->client_streaming(), output); } // optional bool server_streaming = 6 [default = false]; - if (has_server_streaming()) { + if (cached_has_bits & 0x00000020u) { ::google::protobuf::internal::WireFormatLite::WriteBool(6, this->server_streaming(), output); } @@ -7575,10 +7739,13 @@ 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; + + cached_has_bits = _has_bits_[0]; // optional string name = 1; - if (has_name()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->name().data(), this->name().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -7589,7 +7756,7 @@ void MethodDescriptorProto::SerializeWithCachedSizes( } // optional string input_type = 2; - if (has_input_type()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->input_type().data(), this->input_type().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -7600,7 +7767,7 @@ void MethodDescriptorProto::SerializeWithCachedSizes( } // optional string output_type = 3; - if (has_output_type()) { + if (cached_has_bits & 0x00000004u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->output_type().data(), this->output_type().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -7611,19 +7778,19 @@ void MethodDescriptorProto::SerializeWithCachedSizes( } // optional .google.protobuf.MethodOptions options = 4; - if (has_options()) { + if (cached_has_bits & 0x00000008u) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 4, *this->options_, false, target); + 4, *this->options_, deterministic, target); } // optional bool client_streaming = 5 [default = false]; - if (has_client_streaming()) { + if (cached_has_bits & 0x00000010u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(5, this->client_streaming(), target); } // optional bool server_streaming = 6 [default = false]; - if (has_server_streaming()) { + if (cached_has_bits & 0x00000020u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(6, this->server_streaming(), target); } @@ -7710,28 +7877,33 @@ void MethodDescriptorProto::MergeFrom(const MethodDescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.MethodDescriptorProto) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); - if (from._has_bits_[0 / 32] & 63u) { - if (from.has_name()) { + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 63u) { + if (cached_has_bits & 0x00000001u) { set_has_name(); name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); } - if (from.has_input_type()) { + if (cached_has_bits & 0x00000002u) { set_has_input_type(); input_type_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.input_type_); } - if (from.has_output_type()) { + if (cached_has_bits & 0x00000004u) { set_has_output_type(); output_type_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.output_type_); } - if (from.has_options()) { + if (cached_has_bits & 0x00000008u) { mutable_options()->::google::protobuf::MethodOptions::MergeFrom(from.options()); } - if (from.has_client_streaming()) { - set_client_streaming(from.client_streaming()); + if (cached_has_bits & 0x00000010u) { + client_streaming_ = from.client_streaming_; } - if (from.has_server_streaming()) { - set_server_streaming(from.server_streaming()); + if (cached_has_bits & 0x00000020u) { + server_streaming_ = from.server_streaming_; } + _has_bits_[0] |= cached_has_bits; } } @@ -7774,7 +7946,7 @@ void MethodDescriptorProto::InternalSwap(MethodDescriptorProto* other) { ::google::protobuf::Metadata MethodDescriptorProto::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[10]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -7812,6 +7984,7 @@ void MethodDescriptorProto::set_name(::std::string&& value) { } #endif void MethodDescriptorProto::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.MethodDescriptorProto.name) @@ -7874,6 +8047,7 @@ void MethodDescriptorProto::set_input_type(::std::string&& value) { } #endif void MethodDescriptorProto::set_input_type(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_input_type(); input_type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.MethodDescriptorProto.input_type) @@ -7936,6 +8110,7 @@ void MethodDescriptorProto::set_output_type(::std::string&& value) { } #endif void MethodDescriptorProto::set_output_type(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_output_type(); output_type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.MethodDescriptorProto.output_type) @@ -8169,7 +8344,7 @@ void FileOptions::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* FileOptions::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[11].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const FileOptions& FileOptions::default_instance() { @@ -8486,13 +8661,11 @@ bool FileOptions::MergePartialFromCodedStream( case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(7994u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_uninterpreted_option())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -8526,8 +8699,12 @@ failure: void FileOptions::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.FileOptions) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; // optional string java_package = 1; - if (has_java_package()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->java_package().data(), this->java_package().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -8537,7 +8714,7 @@ void FileOptions::SerializeWithCachedSizes( } // optional string java_outer_classname = 8; - if (has_java_outer_classname()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->java_outer_classname().data(), this->java_outer_classname().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -8547,18 +8724,18 @@ void FileOptions::SerializeWithCachedSizes( } // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; - if (has_optimize_for()) { + if (cached_has_bits & 0x00008000u) { ::google::protobuf::internal::WireFormatLite::WriteEnum( 9, this->optimize_for(), output); } // optional bool java_multiple_files = 10 [default = false]; - if (has_java_multiple_files()) { + if (cached_has_bits & 0x00000080u) { ::google::protobuf::internal::WireFormatLite::WriteBool(10, this->java_multiple_files(), output); } // optional string go_package = 11; - if (has_go_package()) { + if (cached_has_bits & 0x00000004u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->go_package().data(), this->go_package().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -8568,42 +8745,42 @@ void FileOptions::SerializeWithCachedSizes( } // optional bool cc_generic_services = 16 [default = false]; - if (has_cc_generic_services()) { + if (cached_has_bits & 0x00000400u) { ::google::protobuf::internal::WireFormatLite::WriteBool(16, this->cc_generic_services(), output); } // optional bool java_generic_services = 17 [default = false]; - if (has_java_generic_services()) { + if (cached_has_bits & 0x00000800u) { ::google::protobuf::internal::WireFormatLite::WriteBool(17, this->java_generic_services(), output); } // optional bool py_generic_services = 18 [default = false]; - if (has_py_generic_services()) { + if (cached_has_bits & 0x00001000u) { ::google::protobuf::internal::WireFormatLite::WriteBool(18, this->py_generic_services(), output); } // optional bool java_generate_equals_and_hash = 20 [deprecated = true]; - if (has_java_generate_equals_and_hash()) { + if (cached_has_bits & 0x00000100u) { ::google::protobuf::internal::WireFormatLite::WriteBool(20, this->java_generate_equals_and_hash(), output); } // optional bool deprecated = 23 [default = false]; - if (has_deprecated()) { + if (cached_has_bits & 0x00002000u) { ::google::protobuf::internal::WireFormatLite::WriteBool(23, this->deprecated(), output); } // optional bool java_string_check_utf8 = 27 [default = false]; - if (has_java_string_check_utf8()) { + if (cached_has_bits & 0x00000200u) { ::google::protobuf::internal::WireFormatLite::WriteBool(27, this->java_string_check_utf8(), output); } // optional bool cc_enable_arenas = 31 [default = false]; - if (has_cc_enable_arenas()) { + if (cached_has_bits & 0x00004000u) { ::google::protobuf::internal::WireFormatLite::WriteBool(31, this->cc_enable_arenas(), output); } // optional string objc_class_prefix = 36; - if (has_objc_class_prefix()) { + if (cached_has_bits & 0x00000008u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->objc_class_prefix().data(), this->objc_class_prefix().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -8613,7 +8790,7 @@ void FileOptions::SerializeWithCachedSizes( } // optional string csharp_namespace = 37; - if (has_csharp_namespace()) { + if (cached_has_bits & 0x00000010u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->csharp_namespace().data(), this->csharp_namespace().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -8623,7 +8800,7 @@ void FileOptions::SerializeWithCachedSizes( } // optional string swift_prefix = 39; - if (has_swift_prefix()) { + if (cached_has_bits & 0x00000020u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->swift_prefix().data(), this->swift_prefix().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -8633,7 +8810,7 @@ void FileOptions::SerializeWithCachedSizes( } // optional string php_class_prefix = 40; - if (has_php_class_prefix()) { + if (cached_has_bits & 0x00000040u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->php_class_prefix().data(), this->php_class_prefix().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -8661,10 +8838,13 @@ 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; + + cached_has_bits = _has_bits_[0]; // optional string java_package = 1; - if (has_java_package()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->java_package().data(), this->java_package().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -8675,7 +8855,7 @@ void FileOptions::SerializeWithCachedSizes( } // optional string java_outer_classname = 8; - if (has_java_outer_classname()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->java_outer_classname().data(), this->java_outer_classname().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -8686,18 +8866,18 @@ void FileOptions::SerializeWithCachedSizes( } // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; - if (has_optimize_for()) { + if (cached_has_bits & 0x00008000u) { target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray( 9, this->optimize_for(), target); } // optional bool java_multiple_files = 10 [default = false]; - if (has_java_multiple_files()) { + if (cached_has_bits & 0x00000080u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(10, this->java_multiple_files(), target); } // optional string go_package = 11; - if (has_go_package()) { + if (cached_has_bits & 0x00000004u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->go_package().data(), this->go_package().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -8708,42 +8888,42 @@ void FileOptions::SerializeWithCachedSizes( } // optional bool cc_generic_services = 16 [default = false]; - if (has_cc_generic_services()) { + if (cached_has_bits & 0x00000400u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(16, this->cc_generic_services(), target); } // optional bool java_generic_services = 17 [default = false]; - if (has_java_generic_services()) { + if (cached_has_bits & 0x00000800u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(17, this->java_generic_services(), target); } // optional bool py_generic_services = 18 [default = false]; - if (has_py_generic_services()) { + if (cached_has_bits & 0x00001000u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(18, this->py_generic_services(), target); } // optional bool java_generate_equals_and_hash = 20 [deprecated = true]; - if (has_java_generate_equals_and_hash()) { + if (cached_has_bits & 0x00000100u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(20, this->java_generate_equals_and_hash(), target); } // optional bool deprecated = 23 [default = false]; - if (has_deprecated()) { + if (cached_has_bits & 0x00002000u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(23, this->deprecated(), target); } // optional bool java_string_check_utf8 = 27 [default = false]; - if (has_java_string_check_utf8()) { + if (cached_has_bits & 0x00000200u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(27, this->java_string_check_utf8(), target); } // optional bool cc_enable_arenas = 31 [default = false]; - if (has_cc_enable_arenas()) { + if (cached_has_bits & 0x00004000u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(31, this->cc_enable_arenas(), target); } // optional string objc_class_prefix = 36; - if (has_objc_class_prefix()) { + if (cached_has_bits & 0x00000008u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->objc_class_prefix().data(), this->objc_class_prefix().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -8754,7 +8934,7 @@ void FileOptions::SerializeWithCachedSizes( } // optional string csharp_namespace = 37; - if (has_csharp_namespace()) { + if (cached_has_bits & 0x00000010u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->csharp_namespace().data(), this->csharp_namespace().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -8765,7 +8945,7 @@ void FileOptions::SerializeWithCachedSizes( } // optional string swift_prefix = 39; - if (has_swift_prefix()) { + if (cached_has_bits & 0x00000020u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->swift_prefix().data(), this->swift_prefix().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -8776,7 +8956,7 @@ void FileOptions::SerializeWithCachedSizes( } // optional string php_class_prefix = 40; - if (has_php_class_prefix()) { + if (cached_has_bits & 0x00000040u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->php_class_prefix().data(), this->php_class_prefix().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -8790,7 +8970,7 @@ void FileOptions::SerializeWithCachedSizes( for (unsigned int i = 0, n = this->uninterpreted_option_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 999, this->uninterpreted_option(i), false, target); + 999, this->uninterpreted_option(i), deterministic, target); } // Extension range [1000, 536870912) @@ -8953,65 +9133,71 @@ void FileOptions::MergeFrom(const FileOptions& from) { GOOGLE_DCHECK_NE(&from, this); _extensions_.MergeFrom(from._extensions_); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + uninterpreted_option_.MergeFrom(from.uninterpreted_option_); - if (from._has_bits_[0 / 32] & 255u) { - if (from.has_java_package()) { + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 255u) { + if (cached_has_bits & 0x00000001u) { set_has_java_package(); java_package_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.java_package_); } - if (from.has_java_outer_classname()) { + if (cached_has_bits & 0x00000002u) { set_has_java_outer_classname(); java_outer_classname_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.java_outer_classname_); } - if (from.has_go_package()) { + if (cached_has_bits & 0x00000004u) { set_has_go_package(); go_package_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.go_package_); } - if (from.has_objc_class_prefix()) { + if (cached_has_bits & 0x00000008u) { set_has_objc_class_prefix(); objc_class_prefix_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.objc_class_prefix_); } - if (from.has_csharp_namespace()) { + if (cached_has_bits & 0x00000010u) { set_has_csharp_namespace(); csharp_namespace_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.csharp_namespace_); } - if (from.has_swift_prefix()) { + if (cached_has_bits & 0x00000020u) { set_has_swift_prefix(); swift_prefix_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.swift_prefix_); } - if (from.has_php_class_prefix()) { + if (cached_has_bits & 0x00000040u) { set_has_php_class_prefix(); php_class_prefix_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.php_class_prefix_); } - if (from.has_java_multiple_files()) { - set_java_multiple_files(from.java_multiple_files()); + if (cached_has_bits & 0x00000080u) { + java_multiple_files_ = from.java_multiple_files_; } + _has_bits_[0] |= cached_has_bits; } - if (from._has_bits_[8 / 32] & 65280u) { - if (from.has_java_generate_equals_and_hash()) { - set_java_generate_equals_and_hash(from.java_generate_equals_and_hash()); + if (cached_has_bits & 65280u) { + if (cached_has_bits & 0x00000100u) { + java_generate_equals_and_hash_ = from.java_generate_equals_and_hash_; } - if (from.has_java_string_check_utf8()) { - set_java_string_check_utf8(from.java_string_check_utf8()); + if (cached_has_bits & 0x00000200u) { + java_string_check_utf8_ = from.java_string_check_utf8_; } - if (from.has_cc_generic_services()) { - set_cc_generic_services(from.cc_generic_services()); + if (cached_has_bits & 0x00000400u) { + cc_generic_services_ = from.cc_generic_services_; } - if (from.has_java_generic_services()) { - set_java_generic_services(from.java_generic_services()); + if (cached_has_bits & 0x00000800u) { + java_generic_services_ = from.java_generic_services_; } - if (from.has_py_generic_services()) { - set_py_generic_services(from.py_generic_services()); + if (cached_has_bits & 0x00001000u) { + py_generic_services_ = from.py_generic_services_; } - if (from.has_deprecated()) { - set_deprecated(from.deprecated()); + if (cached_has_bits & 0x00002000u) { + deprecated_ = from.deprecated_; } - if (from.has_cc_enable_arenas()) { - set_cc_enable_arenas(from.cc_enable_arenas()); + if (cached_has_bits & 0x00004000u) { + cc_enable_arenas_ = from.cc_enable_arenas_; } - if (from.has_optimize_for()) { - set_optimize_for(from.optimize_for()); + if (cached_has_bits & 0x00008000u) { + optimize_for_ = from.optimize_for_; } + _has_bits_[0] |= cached_has_bits; } } @@ -9043,7 +9229,7 @@ void FileOptions::Swap(FileOptions* other) { InternalSwap(other); } void FileOptions::InternalSwap(FileOptions* other) { - uninterpreted_option_.UnsafeArenaSwap(&other->uninterpreted_option_); + uninterpreted_option_.InternalSwap(&other->uninterpreted_option_); java_package_.Swap(&other->java_package_); java_outer_classname_.Swap(&other->java_outer_classname_); go_package_.Swap(&other->go_package_); @@ -9068,7 +9254,7 @@ void FileOptions::InternalSwap(FileOptions* other) { ::google::protobuf::Metadata FileOptions::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[11]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -9106,6 +9292,7 @@ void FileOptions::set_java_package(::std::string&& value) { } #endif void FileOptions::set_java_package(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_java_package(); java_package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.java_package) @@ -9168,6 +9355,7 @@ void FileOptions::set_java_outer_classname(::std::string&& value) { } #endif void FileOptions::set_java_outer_classname(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_java_outer_classname(); java_outer_classname_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.java_outer_classname) @@ -9327,6 +9515,7 @@ void FileOptions::set_go_package(::std::string&& value) { } #endif void FileOptions::set_go_package(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_go_package(); go_package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.go_package) @@ -9509,6 +9698,7 @@ void FileOptions::set_objc_class_prefix(::std::string&& value) { } #endif void FileOptions::set_objc_class_prefix(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_objc_class_prefix(); objc_class_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.objc_class_prefix) @@ -9571,6 +9761,7 @@ void FileOptions::set_csharp_namespace(::std::string&& value) { } #endif void FileOptions::set_csharp_namespace(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_csharp_namespace(); csharp_namespace_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.csharp_namespace) @@ -9633,6 +9824,7 @@ void FileOptions::set_swift_prefix(::std::string&& value) { } #endif void FileOptions::set_swift_prefix(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_swift_prefix(); swift_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.swift_prefix) @@ -9695,6 +9887,7 @@ void FileOptions::set_php_class_prefix(::std::string&& value) { } #endif void FileOptions::set_php_class_prefix(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_php_class_prefix(); php_class_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.php_class_prefix) @@ -9810,7 +10003,7 @@ void MessageOptions::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* MessageOptions::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[12].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const MessageOptions& MessageOptions::default_instance() { @@ -9908,13 +10101,11 @@ bool MessageOptions::MergePartialFromCodedStream( case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(7994u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_uninterpreted_option())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -9948,23 +10139,27 @@ failure: void MessageOptions::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.MessageOptions) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; // optional bool message_set_wire_format = 1 [default = false]; - if (has_message_set_wire_format()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormatLite::WriteBool(1, this->message_set_wire_format(), output); } // optional bool no_standard_descriptor_accessor = 2 [default = false]; - if (has_no_standard_descriptor_accessor()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormatLite::WriteBool(2, this->no_standard_descriptor_accessor(), output); } // optional bool deprecated = 3 [default = false]; - if (has_deprecated()) { + if (cached_has_bits & 0x00000004u) { ::google::protobuf::internal::WireFormatLite::WriteBool(3, this->deprecated(), output); } // optional bool map_entry = 7; - if (has_map_entry()) { + if (cached_has_bits & 0x00000008u) { ::google::protobuf::internal::WireFormatLite::WriteBool(7, this->map_entry(), output); } @@ -9987,25 +10182,28 @@ 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; + + cached_has_bits = _has_bits_[0]; // optional bool message_set_wire_format = 1 [default = false]; - if (has_message_set_wire_format()) { + if (cached_has_bits & 0x00000001u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(1, this->message_set_wire_format(), target); } // optional bool no_standard_descriptor_accessor = 2 [default = false]; - if (has_no_standard_descriptor_accessor()) { + if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(2, this->no_standard_descriptor_accessor(), target); } // optional bool deprecated = 3 [default = false]; - if (has_deprecated()) { + if (cached_has_bits & 0x00000004u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(3, this->deprecated(), target); } // optional bool map_entry = 7; - if (has_map_entry()) { + if (cached_has_bits & 0x00000008u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(7, this->map_entry(), target); } @@ -10013,7 +10211,7 @@ void MessageOptions::SerializeWithCachedSizes( for (unsigned int i = 0, n = this->uninterpreted_option_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 999, this->uninterpreted_option(i), false, target); + 999, this->uninterpreted_option(i), deterministic, target); } // Extension range [1000, 536870912) @@ -10099,20 +10297,25 @@ void MessageOptions::MergeFrom(const MessageOptions& from) { GOOGLE_DCHECK_NE(&from, this); _extensions_.MergeFrom(from._extensions_); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + uninterpreted_option_.MergeFrom(from.uninterpreted_option_); - if (from._has_bits_[0 / 32] & 15u) { - if (from.has_message_set_wire_format()) { - set_message_set_wire_format(from.message_set_wire_format()); + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 15u) { + if (cached_has_bits & 0x00000001u) { + message_set_wire_format_ = from.message_set_wire_format_; } - if (from.has_no_standard_descriptor_accessor()) { - set_no_standard_descriptor_accessor(from.no_standard_descriptor_accessor()); + if (cached_has_bits & 0x00000002u) { + no_standard_descriptor_accessor_ = from.no_standard_descriptor_accessor_; } - if (from.has_deprecated()) { - set_deprecated(from.deprecated()); + if (cached_has_bits & 0x00000004u) { + deprecated_ = from.deprecated_; } - if (from.has_map_entry()) { - set_map_entry(from.map_entry()); + if (cached_has_bits & 0x00000008u) { + map_entry_ = from.map_entry_; } + _has_bits_[0] |= cached_has_bits; } } @@ -10144,7 +10347,7 @@ void MessageOptions::Swap(MessageOptions* other) { InternalSwap(other); } void MessageOptions::InternalSwap(MessageOptions* other) { - uninterpreted_option_.UnsafeArenaSwap(&other->uninterpreted_option_); + uninterpreted_option_.InternalSwap(&other->uninterpreted_option_); std::swap(message_set_wire_format_, other->message_set_wire_format_); std::swap(no_standard_descriptor_accessor_, other->no_standard_descriptor_accessor_); std::swap(deprecated_, other->deprecated_); @@ -10157,7 +10360,7 @@ void MessageOptions::InternalSwap(MessageOptions* other) { ::google::protobuf::Metadata MessageOptions::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[12]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -10320,15 +10523,15 @@ FieldOptions::FieldOptions(const FieldOptions& from) _internal_metadata_.MergeFrom(from._internal_metadata_); _extensions_.MergeFrom(from._extensions_); ::memcpy(&ctype_, &from.ctype_, - reinterpret_cast(&weak_) - - reinterpret_cast(&ctype_) + sizeof(weak_)); + reinterpret_cast(&jstype_) - + reinterpret_cast(&ctype_) + sizeof(jstype_)); // @@protoc_insertion_point(copy_constructor:google.protobuf.FieldOptions) } void FieldOptions::SharedCtor() { _cached_size_ = 0; - ::memset(&ctype_, 0, reinterpret_cast(&weak_) - - reinterpret_cast(&ctype_) + sizeof(weak_)); + ::memset(&ctype_, 0, reinterpret_cast(&jstype_) - + reinterpret_cast(&ctype_) + sizeof(jstype_)); } FieldOptions::~FieldOptions() { @@ -10346,7 +10549,7 @@ void FieldOptions::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* FieldOptions::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[13].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const FieldOptions& FieldOptions::default_instance() { @@ -10367,8 +10570,8 @@ void FieldOptions::Clear() { _extensions_.Clear(); uninterpreted_option_.Clear(); if (_has_bits_[0 / 32] & 63u) { - ::memset(&ctype_, 0, reinterpret_cast(&weak_) - - reinterpret_cast(&ctype_) + sizeof(weak_)); + ::memset(&ctype_, 0, reinterpret_cast(&jstype_) - + reinterpret_cast(&ctype_) + sizeof(jstype_)); } _has_bits_.Clear(); _internal_metadata_.Clear(); @@ -10482,13 +10685,11 @@ bool FieldOptions::MergePartialFromCodedStream( case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(7994u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_uninterpreted_option())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -10522,35 +10723,39 @@ failure: void FieldOptions::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.FieldOptions) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; // optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; - if (has_ctype()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormatLite::WriteEnum( 1, this->ctype(), output); } // optional bool packed = 2; - if (has_packed()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormatLite::WriteBool(2, this->packed(), output); } // optional bool deprecated = 3 [default = false]; - if (has_deprecated()) { + if (cached_has_bits & 0x00000008u) { ::google::protobuf::internal::WireFormatLite::WriteBool(3, this->deprecated(), output); } // optional bool lazy = 5 [default = false]; - if (has_lazy()) { + if (cached_has_bits & 0x00000004u) { ::google::protobuf::internal::WireFormatLite::WriteBool(5, this->lazy(), output); } // optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL]; - if (has_jstype()) { + if (cached_has_bits & 0x00000020u) { ::google::protobuf::internal::WireFormatLite::WriteEnum( 6, this->jstype(), output); } // optional bool weak = 10 [default = false]; - if (has_weak()) { + if (cached_has_bits & 0x00000010u) { ::google::protobuf::internal::WireFormatLite::WriteBool(10, this->weak(), output); } @@ -10573,37 +10778,40 @@ 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; + + cached_has_bits = _has_bits_[0]; // optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; - if (has_ctype()) { + if (cached_has_bits & 0x00000001u) { target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray( 1, this->ctype(), target); } // optional bool packed = 2; - if (has_packed()) { + if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(2, this->packed(), target); } // optional bool deprecated = 3 [default = false]; - if (has_deprecated()) { + if (cached_has_bits & 0x00000008u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(3, this->deprecated(), target); } // optional bool lazy = 5 [default = false]; - if (has_lazy()) { + if (cached_has_bits & 0x00000004u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(5, this->lazy(), target); } // optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL]; - if (has_jstype()) { + if (cached_has_bits & 0x00000020u) { target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray( 6, this->jstype(), target); } // optional bool weak = 10 [default = false]; - if (has_weak()) { + if (cached_has_bits & 0x00000010u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(10, this->weak(), target); } @@ -10611,7 +10819,7 @@ void FieldOptions::SerializeWithCachedSizes( for (unsigned int i = 0, n = this->uninterpreted_option_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 999, this->uninterpreted_option(i), false, target); + 999, this->uninterpreted_option(i), deterministic, target); } // Extension range [1000, 536870912) @@ -10655,12 +10863,6 @@ size_t FieldOptions::ByteSizeLong() const { ::google::protobuf::internal::WireFormatLite::EnumSize(this->ctype()); } - // optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL]; - if (has_jstype()) { - total_size += 1 + - ::google::protobuf::internal::WireFormatLite::EnumSize(this->jstype()); - } - // optional bool packed = 2; if (has_packed()) { total_size += 1 + 1; @@ -10681,6 +10883,12 @@ size_t FieldOptions::ByteSizeLong() const { total_size += 1 + 1; } + // optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL]; + if (has_jstype()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::EnumSize(this->jstype()); + } + } int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); @@ -10709,26 +10917,31 @@ void FieldOptions::MergeFrom(const FieldOptions& from) { GOOGLE_DCHECK_NE(&from, this); _extensions_.MergeFrom(from._extensions_); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + uninterpreted_option_.MergeFrom(from.uninterpreted_option_); - if (from._has_bits_[0 / 32] & 63u) { - if (from.has_ctype()) { - set_ctype(from.ctype()); + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 63u) { + if (cached_has_bits & 0x00000001u) { + ctype_ = from.ctype_; } - if (from.has_jstype()) { - set_jstype(from.jstype()); + if (cached_has_bits & 0x00000002u) { + packed_ = from.packed_; } - if (from.has_packed()) { - set_packed(from.packed()); + if (cached_has_bits & 0x00000004u) { + lazy_ = from.lazy_; } - if (from.has_lazy()) { - set_lazy(from.lazy()); + if (cached_has_bits & 0x00000008u) { + deprecated_ = from.deprecated_; } - if (from.has_deprecated()) { - set_deprecated(from.deprecated()); + if (cached_has_bits & 0x00000010u) { + weak_ = from.weak_; } - if (from.has_weak()) { - set_weak(from.weak()); + if (cached_has_bits & 0x00000020u) { + jstype_ = from.jstype_; } + _has_bits_[0] |= cached_has_bits; } } @@ -10760,13 +10973,13 @@ void FieldOptions::Swap(FieldOptions* other) { InternalSwap(other); } void FieldOptions::InternalSwap(FieldOptions* other) { - uninterpreted_option_.UnsafeArenaSwap(&other->uninterpreted_option_); + uninterpreted_option_.InternalSwap(&other->uninterpreted_option_); std::swap(ctype_, other->ctype_); - std::swap(jstype_, other->jstype_); std::swap(packed_, other->packed_); std::swap(lazy_, other->lazy_); std::swap(deprecated_, other->deprecated_); std::swap(weak_, other->weak_); + std::swap(jstype_, other->jstype_); std::swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); std::swap(_cached_size_, other->_cached_size_); @@ -10775,7 +10988,7 @@ void FieldOptions::InternalSwap(FieldOptions* other) { ::google::protobuf::Metadata FieldOptions::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[13]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -10808,13 +11021,13 @@ void FieldOptions::set_ctype(::google::protobuf::FieldOptions_CType value) { // optional bool packed = 2; bool FieldOptions::has_packed() const { - return (_has_bits_[0] & 0x00000004u) != 0; + return (_has_bits_[0] & 0x00000002u) != 0; } void FieldOptions::set_has_packed() { - _has_bits_[0] |= 0x00000004u; + _has_bits_[0] |= 0x00000002u; } void FieldOptions::clear_has_packed() { - _has_bits_[0] &= ~0x00000004u; + _has_bits_[0] &= ~0x00000002u; } void FieldOptions::clear_packed() { packed_ = false; @@ -10832,13 +11045,13 @@ void FieldOptions::set_packed(bool value) { // optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL]; bool FieldOptions::has_jstype() const { - return (_has_bits_[0] & 0x00000002u) != 0; + return (_has_bits_[0] & 0x00000020u) != 0; } void FieldOptions::set_has_jstype() { - _has_bits_[0] |= 0x00000002u; + _has_bits_[0] |= 0x00000020u; } void FieldOptions::clear_has_jstype() { - _has_bits_[0] &= ~0x00000002u; + _has_bits_[0] &= ~0x00000020u; } void FieldOptions::clear_jstype() { jstype_ = 0; @@ -10857,13 +11070,13 @@ void FieldOptions::set_jstype(::google::protobuf::FieldOptions_JSType value) { // optional bool lazy = 5 [default = false]; bool FieldOptions::has_lazy() const { - return (_has_bits_[0] & 0x00000008u) != 0; + return (_has_bits_[0] & 0x00000004u) != 0; } void FieldOptions::set_has_lazy() { - _has_bits_[0] |= 0x00000008u; + _has_bits_[0] |= 0x00000004u; } void FieldOptions::clear_has_lazy() { - _has_bits_[0] &= ~0x00000008u; + _has_bits_[0] &= ~0x00000004u; } void FieldOptions::clear_lazy() { lazy_ = false; @@ -10881,13 +11094,13 @@ void FieldOptions::set_lazy(bool value) { // optional bool deprecated = 3 [default = false]; bool FieldOptions::has_deprecated() const { - return (_has_bits_[0] & 0x00000010u) != 0; + return (_has_bits_[0] & 0x00000008u) != 0; } void FieldOptions::set_has_deprecated() { - _has_bits_[0] |= 0x00000010u; + _has_bits_[0] |= 0x00000008u; } void FieldOptions::clear_has_deprecated() { - _has_bits_[0] &= ~0x00000010u; + _has_bits_[0] &= ~0x00000008u; } void FieldOptions::clear_deprecated() { deprecated_ = false; @@ -10905,13 +11118,13 @@ void FieldOptions::set_deprecated(bool value) { // optional bool weak = 10 [default = false]; bool FieldOptions::has_weak() const { - return (_has_bits_[0] & 0x00000020u) != 0; + return (_has_bits_[0] & 0x00000010u) != 0; } void FieldOptions::set_has_weak() { - _has_bits_[0] |= 0x00000020u; + _has_bits_[0] |= 0x00000010u; } void FieldOptions::clear_has_weak() { - _has_bits_[0] &= ~0x00000020u; + _has_bits_[0] &= ~0x00000010u; } void FieldOptions::clear_weak() { weak_ = false; @@ -11003,7 +11216,7 @@ void OneofOptions::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* OneofOptions::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[14].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const OneofOptions& OneofOptions::default_instance() { @@ -11041,13 +11254,11 @@ bool OneofOptions::MergePartialFromCodedStream( case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(7994u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_uninterpreted_option())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -11081,6 +11292,9 @@ failure: void OneofOptions::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.OneofOptions) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; for (unsigned int i = 0, n = this->uninterpreted_option_size(); i < n; i++) { ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( @@ -11100,13 +11314,15 @@ 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; + // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; for (unsigned int i = 0, n = this->uninterpreted_option_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 999, this->uninterpreted_option(i), false, target); + 999, this->uninterpreted_option(i), deterministic, target); } // Extension range [1000, 536870912) @@ -11170,6 +11386,9 @@ void OneofOptions::MergeFrom(const OneofOptions& from) { GOOGLE_DCHECK_NE(&from, this); _extensions_.MergeFrom(from._extensions_); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + uninterpreted_option_.MergeFrom(from.uninterpreted_option_); } @@ -11201,7 +11420,7 @@ void OneofOptions::Swap(OneofOptions* other) { InternalSwap(other); } void OneofOptions::InternalSwap(OneofOptions* other) { - uninterpreted_option_.UnsafeArenaSwap(&other->uninterpreted_option_); + uninterpreted_option_.InternalSwap(&other->uninterpreted_option_); std::swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); std::swap(_cached_size_, other->_cached_size_); @@ -11210,7 +11429,7 @@ void OneofOptions::InternalSwap(OneofOptions* other) { ::google::protobuf::Metadata OneofOptions::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[14]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -11299,7 +11518,7 @@ void EnumOptions::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* EnumOptions::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[15].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const EnumOptions& EnumOptions::default_instance() { @@ -11369,13 +11588,11 @@ bool EnumOptions::MergePartialFromCodedStream( case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(7994u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_uninterpreted_option())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -11409,13 +11626,17 @@ failure: void EnumOptions::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.EnumOptions) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; // optional bool allow_alias = 2; - if (has_allow_alias()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormatLite::WriteBool(2, this->allow_alias(), output); } // optional bool deprecated = 3 [default = false]; - if (has_deprecated()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormatLite::WriteBool(3, this->deprecated(), output); } @@ -11438,15 +11659,18 @@ 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; + + cached_has_bits = _has_bits_[0]; // optional bool allow_alias = 2; - if (has_allow_alias()) { + if (cached_has_bits & 0x00000001u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(2, this->allow_alias(), target); } // optional bool deprecated = 3 [default = false]; - if (has_deprecated()) { + if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(3, this->deprecated(), target); } @@ -11454,7 +11678,7 @@ void EnumOptions::SerializeWithCachedSizes( for (unsigned int i = 0, n = this->uninterpreted_option_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 999, this->uninterpreted_option(i), false, target); + 999, this->uninterpreted_option(i), deterministic, target); } // Extension range [1000, 536870912) @@ -11530,14 +11754,19 @@ void EnumOptions::MergeFrom(const EnumOptions& from) { GOOGLE_DCHECK_NE(&from, this); _extensions_.MergeFrom(from._extensions_); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + uninterpreted_option_.MergeFrom(from.uninterpreted_option_); - if (from._has_bits_[0 / 32] & 3u) { - if (from.has_allow_alias()) { - set_allow_alias(from.allow_alias()); + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 3u) { + if (cached_has_bits & 0x00000001u) { + allow_alias_ = from.allow_alias_; } - if (from.has_deprecated()) { - set_deprecated(from.deprecated()); + if (cached_has_bits & 0x00000002u) { + deprecated_ = from.deprecated_; } + _has_bits_[0] |= cached_has_bits; } } @@ -11569,7 +11798,7 @@ void EnumOptions::Swap(EnumOptions* other) { InternalSwap(other); } void EnumOptions::InternalSwap(EnumOptions* other) { - uninterpreted_option_.UnsafeArenaSwap(&other->uninterpreted_option_); + uninterpreted_option_.InternalSwap(&other->uninterpreted_option_); std::swap(allow_alias_, other->allow_alias_); std::swap(deprecated_, other->deprecated_); std::swap(_has_bits_[0], other->_has_bits_[0]); @@ -11580,7 +11809,7 @@ void EnumOptions::InternalSwap(EnumOptions* other) { ::google::protobuf::Metadata EnumOptions::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[15]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -11713,7 +11942,7 @@ void EnumValueOptions::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* EnumValueOptions::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[16].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const EnumValueOptions& EnumValueOptions::default_instance() { @@ -11766,13 +11995,11 @@ bool EnumValueOptions::MergePartialFromCodedStream( case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(7994u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_uninterpreted_option())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -11806,8 +12033,12 @@ failure: void EnumValueOptions::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.EnumValueOptions) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; // optional bool deprecated = 1 [default = false]; - if (has_deprecated()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormatLite::WriteBool(1, this->deprecated(), output); } @@ -11830,10 +12061,13 @@ 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; + + cached_has_bits = _has_bits_[0]; // optional bool deprecated = 1 [default = false]; - if (has_deprecated()) { + if (cached_has_bits & 0x00000001u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(1, this->deprecated(), target); } @@ -11841,7 +12075,7 @@ void EnumValueOptions::SerializeWithCachedSizes( for (unsigned int i = 0, n = this->uninterpreted_option_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 999, this->uninterpreted_option(i), false, target); + 999, this->uninterpreted_option(i), deterministic, target); } // Extension range [1000, 536870912) @@ -11910,6 +12144,9 @@ void EnumValueOptions::MergeFrom(const EnumValueOptions& from) { GOOGLE_DCHECK_NE(&from, this); _extensions_.MergeFrom(from._extensions_); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + uninterpreted_option_.MergeFrom(from.uninterpreted_option_); if (from.has_deprecated()) { set_deprecated(from.deprecated()); @@ -11944,7 +12181,7 @@ void EnumValueOptions::Swap(EnumValueOptions* other) { InternalSwap(other); } void EnumValueOptions::InternalSwap(EnumValueOptions* other) { - uninterpreted_option_.UnsafeArenaSwap(&other->uninterpreted_option_); + uninterpreted_option_.InternalSwap(&other->uninterpreted_option_); std::swap(deprecated_, other->deprecated_); std::swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); @@ -11954,7 +12191,7 @@ void EnumValueOptions::InternalSwap(EnumValueOptions* other) { ::google::protobuf::Metadata EnumValueOptions::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[16]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -12063,7 +12300,7 @@ void ServiceOptions::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* ServiceOptions::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[17].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const ServiceOptions& ServiceOptions::default_instance() { @@ -12116,13 +12353,11 @@ bool ServiceOptions::MergePartialFromCodedStream( case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(7994u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_uninterpreted_option())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -12156,8 +12391,12 @@ failure: void ServiceOptions::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.ServiceOptions) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; // optional bool deprecated = 33 [default = false]; - if (has_deprecated()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormatLite::WriteBool(33, this->deprecated(), output); } @@ -12180,10 +12419,13 @@ 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; + + cached_has_bits = _has_bits_[0]; // optional bool deprecated = 33 [default = false]; - if (has_deprecated()) { + if (cached_has_bits & 0x00000001u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(33, this->deprecated(), target); } @@ -12191,7 +12433,7 @@ void ServiceOptions::SerializeWithCachedSizes( for (unsigned int i = 0, n = this->uninterpreted_option_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 999, this->uninterpreted_option(i), false, target); + 999, this->uninterpreted_option(i), deterministic, target); } // Extension range [1000, 536870912) @@ -12260,6 +12502,9 @@ void ServiceOptions::MergeFrom(const ServiceOptions& from) { GOOGLE_DCHECK_NE(&from, this); _extensions_.MergeFrom(from._extensions_); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + uninterpreted_option_.MergeFrom(from.uninterpreted_option_); if (from.has_deprecated()) { set_deprecated(from.deprecated()); @@ -12294,7 +12539,7 @@ void ServiceOptions::Swap(ServiceOptions* other) { InternalSwap(other); } void ServiceOptions::InternalSwap(ServiceOptions* other) { - uninterpreted_option_.UnsafeArenaSwap(&other->uninterpreted_option_); + uninterpreted_option_.InternalSwap(&other->uninterpreted_option_); std::swap(deprecated_, other->deprecated_); std::swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); @@ -12304,7 +12549,7 @@ void ServiceOptions::InternalSwap(ServiceOptions* other) { ::google::protobuf::Metadata ServiceOptions::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[17]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -12417,7 +12662,7 @@ void MethodOptions::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* MethodOptions::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[18].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const MethodOptions& MethodOptions::default_instance() { @@ -12492,13 +12737,11 @@ bool MethodOptions::MergePartialFromCodedStream( case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(7994u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_uninterpreted_option())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -12532,13 +12775,17 @@ failure: void MethodOptions::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.MethodOptions) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; // optional bool deprecated = 33 [default = false]; - if (has_deprecated()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormatLite::WriteBool(33, this->deprecated(), output); } // optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN]; - if (has_idempotency_level()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormatLite::WriteEnum( 34, this->idempotency_level(), output); } @@ -12562,15 +12809,18 @@ 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; + + cached_has_bits = _has_bits_[0]; // optional bool deprecated = 33 [default = false]; - if (has_deprecated()) { + if (cached_has_bits & 0x00000001u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(33, this->deprecated(), target); } // optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN]; - if (has_idempotency_level()) { + if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray( 34, this->idempotency_level(), target); } @@ -12579,7 +12829,7 @@ void MethodOptions::SerializeWithCachedSizes( for (unsigned int i = 0, n = this->uninterpreted_option_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 999, this->uninterpreted_option(i), false, target); + 999, this->uninterpreted_option(i), deterministic, target); } // Extension range [1000, 536870912) @@ -12656,14 +12906,19 @@ void MethodOptions::MergeFrom(const MethodOptions& from) { GOOGLE_DCHECK_NE(&from, this); _extensions_.MergeFrom(from._extensions_); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + uninterpreted_option_.MergeFrom(from.uninterpreted_option_); - if (from._has_bits_[0 / 32] & 3u) { - if (from.has_deprecated()) { - set_deprecated(from.deprecated()); + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 3u) { + if (cached_has_bits & 0x00000001u) { + deprecated_ = from.deprecated_; } - if (from.has_idempotency_level()) { - set_idempotency_level(from.idempotency_level()); + if (cached_has_bits & 0x00000002u) { + idempotency_level_ = from.idempotency_level_; } + _has_bits_[0] |= cached_has_bits; } } @@ -12695,7 +12950,7 @@ void MethodOptions::Swap(MethodOptions* other) { InternalSwap(other); } void MethodOptions::InternalSwap(MethodOptions* other) { - uninterpreted_option_.UnsafeArenaSwap(&other->uninterpreted_option_); + uninterpreted_option_.InternalSwap(&other->uninterpreted_option_); std::swap(deprecated_, other->deprecated_); std::swap(idempotency_level_, other->idempotency_level_); std::swap(_has_bits_[0], other->_has_bits_[0]); @@ -12706,7 +12961,7 @@ void MethodOptions::InternalSwap(MethodOptions* other) { ::google::protobuf::Metadata MethodOptions::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[18]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -12844,7 +13099,7 @@ void UninterpretedOption_NamePart::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* UninterpretedOption_NamePart::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[19].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const UninterpretedOption_NamePart& UninterpretedOption_NamePart::default_instance() { @@ -12936,8 +13191,12 @@ failure: void UninterpretedOption_NamePart::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.UninterpretedOption.NamePart) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; // required string name_part = 1; - if (has_name_part()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->name_part().data(), this->name_part().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -12947,7 +13206,7 @@ void UninterpretedOption_NamePart::SerializeWithCachedSizes( } // required bool is_extension = 2; - if (has_is_extension()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormatLite::WriteBool(2, this->is_extension(), output); } @@ -12960,10 +13219,13 @@ 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; + + cached_has_bits = _has_bits_[0]; // required string name_part = 1; - if (has_name_part()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->name_part().data(), this->name_part().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -12974,7 +13236,7 @@ void UninterpretedOption_NamePart::SerializeWithCachedSizes( } // required bool is_extension = 2; - if (has_is_extension()) { + if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(2, this->is_extension(), target); } @@ -13051,14 +13313,19 @@ void UninterpretedOption_NamePart::MergeFrom(const UninterpretedOption_NamePart& // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UninterpretedOption.NamePart) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); - if (from._has_bits_[0 / 32] & 3u) { - if (from.has_name_part()) { + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 3u) { + if (cached_has_bits & 0x00000001u) { set_has_name_part(); name_part_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_part_); } - if (from.has_is_extension()) { - set_is_extension(from.is_extension()); + if (cached_has_bits & 0x00000002u) { + is_extension_ = from.is_extension_; } + _has_bits_[0] |= cached_has_bits; } } @@ -13095,7 +13362,7 @@ void UninterpretedOption_NamePart::InternalSwap(UninterpretedOption_NamePart* ot ::google::protobuf::Metadata UninterpretedOption_NamePart::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[19]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -13133,6 +13400,7 @@ void UninterpretedOption_NamePart::set_name_part(::std::string&& value) { } #endif void UninterpretedOption_NamePart::set_name_part(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_name_part(); name_part_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.UninterpretedOption.NamePart.name_part) @@ -13261,7 +13529,7 @@ void UninterpretedOption::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* UninterpretedOption::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[20].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const UninterpretedOption& UninterpretedOption::default_instance() { @@ -13316,13 +13584,11 @@ bool UninterpretedOption::MergePartialFromCodedStream( case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(18u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_name())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -13437,14 +13703,18 @@ failure: void UninterpretedOption::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.UninterpretedOption) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // repeated .google.protobuf.UninterpretedOption.NamePart name = 2; for (unsigned int i = 0, n = this->name_size(); i < n; i++) { ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( 2, this->name(i), output); } + cached_has_bits = _has_bits_[0]; // optional string identifier_value = 3; - if (has_identifier_value()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->identifier_value().data(), this->identifier_value().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -13454,28 +13724,28 @@ void UninterpretedOption::SerializeWithCachedSizes( } // optional uint64 positive_int_value = 4; - if (has_positive_int_value()) { + if (cached_has_bits & 0x00000008u) { ::google::protobuf::internal::WireFormatLite::WriteUInt64(4, this->positive_int_value(), output); } // optional int64 negative_int_value = 5; - if (has_negative_int_value()) { + if (cached_has_bits & 0x00000010u) { ::google::protobuf::internal::WireFormatLite::WriteInt64(5, this->negative_int_value(), output); } // optional double double_value = 6; - if (has_double_value()) { + if (cached_has_bits & 0x00000020u) { ::google::protobuf::internal::WireFormatLite::WriteDouble(6, this->double_value(), output); } // optional bytes string_value = 7; - if (has_string_value()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased( 7, this->string_value(), output); } // optional string aggregate_value = 8; - if (has_aggregate_value()) { + if (cached_has_bits & 0x00000004u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->aggregate_value().data(), this->aggregate_value().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -13493,17 +13763,20 @@ 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; + // repeated .google.protobuf.UninterpretedOption.NamePart name = 2; for (unsigned int i = 0, n = this->name_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 2, this->name(i), false, target); + 2, this->name(i), deterministic, target); } + cached_has_bits = _has_bits_[0]; // optional string identifier_value = 3; - if (has_identifier_value()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->identifier_value().data(), this->identifier_value().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -13514,29 +13787,29 @@ void UninterpretedOption::SerializeWithCachedSizes( } // optional uint64 positive_int_value = 4; - if (has_positive_int_value()) { + if (cached_has_bits & 0x00000008u) { target = ::google::protobuf::internal::WireFormatLite::WriteUInt64ToArray(4, this->positive_int_value(), target); } // optional int64 negative_int_value = 5; - if (has_negative_int_value()) { + if (cached_has_bits & 0x00000010u) { target = ::google::protobuf::internal::WireFormatLite::WriteInt64ToArray(5, this->negative_int_value(), target); } // optional double double_value = 6; - if (has_double_value()) { + if (cached_has_bits & 0x00000020u) { target = ::google::protobuf::internal::WireFormatLite::WriteDoubleToArray(6, this->double_value(), target); } // optional bytes string_value = 7; - if (has_string_value()) { + if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite::WriteBytesToArray( 7, this->string_value(), target); } // optional string aggregate_value = 8; - if (has_aggregate_value()) { + if (cached_has_bits & 0x00000004u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->aggregate_value().data(), this->aggregate_value().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -13642,29 +13915,34 @@ void UninterpretedOption::MergeFrom(const UninterpretedOption& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UninterpretedOption) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + name_.MergeFrom(from.name_); - if (from._has_bits_[0 / 32] & 63u) { - if (from.has_identifier_value()) { + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 63u) { + if (cached_has_bits & 0x00000001u) { set_has_identifier_value(); identifier_value_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.identifier_value_); } - if (from.has_string_value()) { + if (cached_has_bits & 0x00000002u) { set_has_string_value(); string_value_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.string_value_); } - if (from.has_aggregate_value()) { + if (cached_has_bits & 0x00000004u) { set_has_aggregate_value(); aggregate_value_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.aggregate_value_); } - if (from.has_positive_int_value()) { - set_positive_int_value(from.positive_int_value()); + if (cached_has_bits & 0x00000008u) { + positive_int_value_ = from.positive_int_value_; } - if (from.has_negative_int_value()) { - set_negative_int_value(from.negative_int_value()); + if (cached_has_bits & 0x00000010u) { + negative_int_value_ = from.negative_int_value_; } - if (from.has_double_value()) { - set_double_value(from.double_value()); + if (cached_has_bits & 0x00000020u) { + double_value_ = from.double_value_; } + _has_bits_[0] |= cached_has_bits; } } @@ -13692,7 +13970,7 @@ void UninterpretedOption::Swap(UninterpretedOption* other) { InternalSwap(other); } void UninterpretedOption::InternalSwap(UninterpretedOption* other) { - name_.UnsafeArenaSwap(&other->name_); + name_.InternalSwap(&other->name_); identifier_value_.Swap(&other->identifier_value_); string_value_.Swap(&other->string_value_); aggregate_value_.Swap(&other->aggregate_value_); @@ -13706,7 +13984,7 @@ void UninterpretedOption::InternalSwap(UninterpretedOption* other) { ::google::protobuf::Metadata UninterpretedOption::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[20]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -13774,6 +14052,7 @@ void UninterpretedOption::set_identifier_value(::std::string&& value) { } #endif void UninterpretedOption::set_identifier_value(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_identifier_value(); identifier_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.UninterpretedOption.identifier_value) @@ -13908,6 +14187,7 @@ void UninterpretedOption::set_string_value(::std::string&& value) { } #endif void UninterpretedOption::set_string_value(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_string_value(); string_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.UninterpretedOption.string_value) @@ -13970,6 +14250,7 @@ void UninterpretedOption::set_aggregate_value(::std::string&& value) { } #endif void UninterpretedOption::set_aggregate_value(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_aggregate_value(); aggregate_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.UninterpretedOption.aggregate_value) @@ -14063,7 +14344,7 @@ void SourceCodeInfo_Location::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* SourceCodeInfo_Location::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[21].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const SourceCodeInfo_Location& SourceCodeInfo_Location::default_instance() { @@ -14218,6 +14499,9 @@ failure: void SourceCodeInfo_Location::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.SourceCodeInfo.Location) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // 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); @@ -14238,8 +14522,9 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes( this->span(i), output); } + cached_has_bits = _has_bits_[0]; // optional string leading_comments = 3; - if (has_leading_comments()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->leading_comments().data(), this->leading_comments().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -14249,7 +14534,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes( } // optional string trailing_comments = 4; - if (has_trailing_comments()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->trailing_comments().data(), this->trailing_comments().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -14277,8 +14562,10 @@ 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; + // repeated int32 path = 1 [packed = true]; if (this->path_size() > 0) { target = ::google::protobuf::internal::WireFormatLite::WriteTagToArray( @@ -14287,10 +14574,8 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes( target); target = ::google::protobuf::io::CodedOutputStream::WriteVarint32ToArray( _path_cached_byte_size_, target); - } - for (int i = 0, n = this->path_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - WriteInt32NoTagToArray(this->path(i), target); + WriteInt32NoTagToArray(this->path_, target); } // repeated int32 span = 2 [packed = true]; @@ -14301,14 +14586,13 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes( target); target = ::google::protobuf::io::CodedOutputStream::WriteVarint32ToArray( _span_cached_byte_size_, target); - } - for (int i = 0, n = this->span_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - WriteInt32NoTagToArray(this->span(i), target); + WriteInt32NoTagToArray(this->span_, target); } + cached_has_bits = _has_bits_[0]; // optional string leading_comments = 3; - if (has_leading_comments()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->leading_comments().data(), this->leading_comments().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -14319,7 +14603,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes( } // optional string trailing_comments = 4; - if (has_trailing_comments()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->trailing_comments().data(), this->trailing_comments().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -14436,15 +14720,19 @@ void SourceCodeInfo_Location::MergeFrom(const SourceCodeInfo_Location& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.SourceCodeInfo.Location) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + path_.MergeFrom(from.path_); span_.MergeFrom(from.span_); leading_detached_comments_.MergeFrom(from.leading_detached_comments_); - if (from._has_bits_[0 / 32] & 3u) { - if (from.has_leading_comments()) { + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 3u) { + if (cached_has_bits & 0x00000001u) { set_has_leading_comments(); leading_comments_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.leading_comments_); } - if (from.has_trailing_comments()) { + if (cached_has_bits & 0x00000002u) { set_has_trailing_comments(); trailing_comments_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.trailing_comments_); } @@ -14474,9 +14762,9 @@ void SourceCodeInfo_Location::Swap(SourceCodeInfo_Location* other) { InternalSwap(other); } void SourceCodeInfo_Location::InternalSwap(SourceCodeInfo_Location* other) { - path_.UnsafeArenaSwap(&other->path_); - span_.UnsafeArenaSwap(&other->span_); - leading_detached_comments_.UnsafeArenaSwap(&other->leading_detached_comments_); + path_.InternalSwap(&other->path_); + span_.InternalSwap(&other->span_); + leading_detached_comments_.InternalSwap(&other->leading_detached_comments_); leading_comments_.Swap(&other->leading_comments_); trailing_comments_.Swap(&other->trailing_comments_); std::swap(_has_bits_[0], other->_has_bits_[0]); @@ -14486,7 +14774,7 @@ void SourceCodeInfo_Location::InternalSwap(SourceCodeInfo_Location* other) { ::google::protobuf::Metadata SourceCodeInfo_Location::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[21]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -14584,6 +14872,7 @@ void SourceCodeInfo_Location::set_leading_comments(::std::string&& value) { } #endif void SourceCodeInfo_Location::set_leading_comments(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_leading_comments(); leading_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.SourceCodeInfo.Location.leading_comments) @@ -14646,6 +14935,7 @@ void SourceCodeInfo_Location::set_trailing_comments(::std::string&& value) { } #endif void SourceCodeInfo_Location::set_trailing_comments(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_trailing_comments(); trailing_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.SourceCodeInfo.Location.trailing_comments) @@ -14702,6 +14992,7 @@ void SourceCodeInfo_Location::set_leading_detached_comments(int index, ::std::st } #endif void SourceCodeInfo_Location::set_leading_detached_comments(int index, const char* value) { + GOOGLE_DCHECK(value != NULL); leading_detached_comments_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } @@ -14720,11 +15011,12 @@ void SourceCodeInfo_Location::add_leading_detached_comments(const ::std::string& } #if LANG_CXX11 void SourceCodeInfo_Location::add_leading_detached_comments(::std::string&& value) { - leading_detached_comments_.Add()->assign(std::move(value)); + leading_detached_comments_.Add(std::move(value)); // @@protoc_insertion_point(field_add:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } #endif void SourceCodeInfo_Location::add_leading_detached_comments(const char* value) { + GOOGLE_DCHECK(value != NULL); leading_detached_comments_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } @@ -14788,7 +15080,7 @@ void SourceCodeInfo::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* SourceCodeInfo::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[22].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const SourceCodeInfo& SourceCodeInfo::default_instance() { @@ -14825,13 +15117,11 @@ bool SourceCodeInfo::MergePartialFromCodedStream( case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(10u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_location())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -14860,6 +15150,9 @@ failure: void SourceCodeInfo::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.SourceCodeInfo) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // repeated .google.protobuf.SourceCodeInfo.Location location = 1; for (unsigned int i = 0, n = this->location_size(); i < n; i++) { ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( @@ -14875,13 +15168,15 @@ 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; + // repeated .google.protobuf.SourceCodeInfo.Location location = 1; for (unsigned int i = 0, n = this->location_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 1, this->location(i), false, target); + 1, this->location(i), deterministic, target); } if (_internal_metadata_.have_unknown_fields()) { @@ -14938,6 +15233,9 @@ void SourceCodeInfo::MergeFrom(const SourceCodeInfo& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.SourceCodeInfo) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + location_.MergeFrom(from.location_); } @@ -14964,7 +15262,7 @@ void SourceCodeInfo::Swap(SourceCodeInfo* other) { InternalSwap(other); } void SourceCodeInfo::InternalSwap(SourceCodeInfo* other) { - location_.UnsafeArenaSwap(&other->location_); + location_.InternalSwap(&other->location_); std::swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); std::swap(_cached_size_, other->_cached_size_); @@ -14972,7 +15270,7 @@ void SourceCodeInfo::InternalSwap(SourceCodeInfo* other) { ::google::protobuf::Metadata SourceCodeInfo::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[22]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -15067,7 +15365,7 @@ void GeneratedCodeInfo_Annotation::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* GeneratedCodeInfo_Annotation::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[23].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const GeneratedCodeInfo_Annotation& GeneratedCodeInfo_Annotation::default_instance() { @@ -15195,6 +15493,9 @@ failure: void GeneratedCodeInfo_Annotation::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.GeneratedCodeInfo.Annotation) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // 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); @@ -15205,8 +15506,9 @@ void GeneratedCodeInfo_Annotation::SerializeWithCachedSizes( this->path(i), output); } + cached_has_bits = _has_bits_[0]; // optional string source_file = 2; - if (has_source_file()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->source_file().data(), this->source_file().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -15216,12 +15518,12 @@ void GeneratedCodeInfo_Annotation::SerializeWithCachedSizes( } // optional int32 begin = 3; - if (has_begin()) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormatLite::WriteInt32(3, this->begin(), output); } // optional int32 end = 4; - if (has_end()) { + if (cached_has_bits & 0x00000004u) { ::google::protobuf::internal::WireFormatLite::WriteInt32(4, this->end(), output); } @@ -15234,8 +15536,10 @@ 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; + // repeated int32 path = 1 [packed = true]; if (this->path_size() > 0) { target = ::google::protobuf::internal::WireFormatLite::WriteTagToArray( @@ -15244,14 +15548,13 @@ void GeneratedCodeInfo_Annotation::SerializeWithCachedSizes( target); target = ::google::protobuf::io::CodedOutputStream::WriteVarint32ToArray( _path_cached_byte_size_, target); - } - for (int i = 0, n = this->path_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - WriteInt32NoTagToArray(this->path(i), target); + WriteInt32NoTagToArray(this->path_, target); } + cached_has_bits = _has_bits_[0]; // optional string source_file = 2; - if (has_source_file()) { + if (cached_has_bits & 0x00000001u) { ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( this->source_file().data(), this->source_file().length(), ::google::protobuf::internal::WireFormat::SERIALIZE, @@ -15262,12 +15565,12 @@ void GeneratedCodeInfo_Annotation::SerializeWithCachedSizes( } // optional int32 begin = 3; - if (has_begin()) { + if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(3, this->begin(), target); } // optional int32 end = 4; - if (has_end()) { + if (cached_has_bits & 0x00000004u) { target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(4, this->end(), target); } @@ -15352,18 +15655,23 @@ void GeneratedCodeInfo_Annotation::MergeFrom(const GeneratedCodeInfo_Annotation& // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.GeneratedCodeInfo.Annotation) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + path_.MergeFrom(from.path_); - if (from._has_bits_[0 / 32] & 7u) { - if (from.has_source_file()) { + cached_has_bits = from._has_bits_[0]; + if (cached_has_bits & 7u) { + if (cached_has_bits & 0x00000001u) { set_has_source_file(); source_file_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.source_file_); } - if (from.has_begin()) { - set_begin(from.begin()); + if (cached_has_bits & 0x00000002u) { + begin_ = from.begin_; } - if (from.has_end()) { - set_end(from.end()); + if (cached_has_bits & 0x00000004u) { + end_ = from.end_; } + _has_bits_[0] |= cached_has_bits; } } @@ -15390,7 +15698,7 @@ void GeneratedCodeInfo_Annotation::Swap(GeneratedCodeInfo_Annotation* other) { InternalSwap(other); } void GeneratedCodeInfo_Annotation::InternalSwap(GeneratedCodeInfo_Annotation* other) { - path_.UnsafeArenaSwap(&other->path_); + path_.InternalSwap(&other->path_); source_file_.Swap(&other->source_file_); std::swap(begin_, other->begin_); std::swap(end_, other->end_); @@ -15401,7 +15709,7 @@ void GeneratedCodeInfo_Annotation::InternalSwap(GeneratedCodeInfo_Annotation* ot ::google::protobuf::Metadata GeneratedCodeInfo_Annotation::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[23]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -15469,6 +15777,7 @@ void GeneratedCodeInfo_Annotation::set_source_file(::std::string&& value) { } #endif void GeneratedCodeInfo_Annotation::set_source_file(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_source_file(); source_file_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.GeneratedCodeInfo.Annotation.source_file) @@ -15592,7 +15901,7 @@ void GeneratedCodeInfo::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* GeneratedCodeInfo::descriptor() { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[24].descriptor; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const GeneratedCodeInfo& GeneratedCodeInfo::default_instance() { @@ -15629,13 +15938,11 @@ bool GeneratedCodeInfo::MergePartialFromCodedStream( case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(10u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_annotation())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -15664,6 +15971,9 @@ failure: void GeneratedCodeInfo::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.GeneratedCodeInfo) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1; for (unsigned int i = 0, n = this->annotation_size(); i < n; i++) { ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( @@ -15679,13 +15989,15 @@ 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; + // repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1; for (unsigned int i = 0, n = this->annotation_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 1, this->annotation(i), false, target); + 1, this->annotation(i), deterministic, target); } if (_internal_metadata_.have_unknown_fields()) { @@ -15742,6 +16054,9 @@ void GeneratedCodeInfo::MergeFrom(const GeneratedCodeInfo& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.GeneratedCodeInfo) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + annotation_.MergeFrom(from.annotation_); } @@ -15768,7 +16083,7 @@ void GeneratedCodeInfo::Swap(GeneratedCodeInfo* other) { InternalSwap(other); } void GeneratedCodeInfo::InternalSwap(GeneratedCodeInfo* other) { - annotation_.UnsafeArenaSwap(&other->annotation_); + annotation_.InternalSwap(&other->annotation_); std::swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); std::swap(_cached_size_, other->_cached_size_); @@ -15776,7 +16091,7 @@ void GeneratedCodeInfo::InternalSwap(GeneratedCodeInfo* other) { ::google::protobuf::Metadata GeneratedCodeInfo::GetMetadata() const { protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[24]; + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/descriptor.pb.h b/third_party/protobuf/3.2.0/src/google/protobuf/descriptor.pb.h index 10708963af..d1ed2b1f51 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/descriptor.pb.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/descriptor.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3002000 +#if GOOGLE_PROTOBUF_VERSION < 3003000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003000 < 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. @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -116,6 +117,9 @@ namespace protobuf { namespace protobuf_google_2fprotobuf_2fdescriptor_2eproto { // Internal implementation detail -- do not call these. struct LIBPROTOBUF_EXPORT TableStruct { + static const ::google::protobuf::internal::ParseTableField entries[]; + static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; + static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; static void InitDefaultsImpl(); static void Shutdown(); @@ -288,6 +292,8 @@ class LIBPROTOBUF_EXPORT FileDescriptorSet : public ::google::protobuf::Message return reinterpret_cast( &_FileDescriptorSet_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 0; void Swap(FileDescriptorSet* other); @@ -310,11 +316,6 @@ class LIBPROTOBUF_EXPORT FileDescriptorSet : public ::google::protobuf::Message ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -386,6 +387,8 @@ class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Messag return reinterpret_cast( &_FileDescriptorProto_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 1; void Swap(FileDescriptorProto* other); @@ -408,11 +411,6 @@ class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Messag ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -456,30 +454,6 @@ class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Messag const ::google::protobuf::RepeatedPtrField< ::std::string>& dependency() const; ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_dependency(); - // repeated int32 public_dependency = 10; - int public_dependency_size() const; - void clear_public_dependency(); - static const int kPublicDependencyFieldNumber = 10; - ::google::protobuf::int32 public_dependency(int index) const; - void set_public_dependency(int index, ::google::protobuf::int32 value); - void add_public_dependency(::google::protobuf::int32 value); - const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - public_dependency() const; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_public_dependency(); - - // repeated int32 weak_dependency = 11; - int weak_dependency_size() const; - void clear_weak_dependency(); - static const int kWeakDependencyFieldNumber = 11; - ::google::protobuf::int32 weak_dependency(int index) const; - void set_weak_dependency(int index, ::google::protobuf::int32 value); - void add_weak_dependency(::google::protobuf::int32 value); - const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - weak_dependency() const; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_weak_dependency(); - // repeated .google.protobuf.DescriptorProto message_type = 4; int message_type_size() const; void clear_message_type(); @@ -528,6 +502,30 @@ class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Messag const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& extension() const; + // repeated int32 public_dependency = 10; + int public_dependency_size() const; + void clear_public_dependency(); + static const int kPublicDependencyFieldNumber = 10; + ::google::protobuf::int32 public_dependency(int index) const; + void set_public_dependency(int index, ::google::protobuf::int32 value); + void add_public_dependency(::google::protobuf::int32 value); + const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + public_dependency() const; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_public_dependency(); + + // repeated int32 weak_dependency = 11; + int weak_dependency_size() const; + void clear_weak_dependency(); + static const int kWeakDependencyFieldNumber = 11; + ::google::protobuf::int32 weak_dependency(int index) const; + void set_weak_dependency(int index, ::google::protobuf::int32 value); + void add_weak_dependency(::google::protobuf::int32 value); + const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& + weak_dependency() const; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* + mutable_weak_dependency(); + // optional string name = 1; bool has_name() const; void clear_name(); @@ -608,12 +606,12 @@ class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Messag ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::RepeatedPtrField< ::std::string> dependency_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > public_dependency_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > weak_dependency_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto > message_type_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto > enum_type_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::ServiceDescriptorProto > service_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto > extension_; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > public_dependency_; + ::google::protobuf::RepeatedField< ::google::protobuf::int32 > weak_dependency_; ::google::protobuf::internal::ArenaStringPtr name_; ::google::protobuf::internal::ArenaStringPtr package_; ::google::protobuf::internal::ArenaStringPtr syntax_; @@ -650,6 +648,8 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ExtensionRange : public ::google::proto return reinterpret_cast( &_DescriptorProto_ExtensionRange_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 2; void Swap(DescriptorProto_ExtensionRange* other); @@ -672,11 +672,6 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ExtensionRange : public ::google::proto ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -755,6 +750,8 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ReservedRange : public ::google::protob return reinterpret_cast( &_DescriptorProto_ReservedRange_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 3; void Swap(DescriptorProto_ReservedRange* other); @@ -777,11 +774,6 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ReservedRange : public ::google::protob ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -860,6 +852,8 @@ class LIBPROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message /* return reinterpret_cast( &_DescriptorProto_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 4; void Swap(DescriptorProto* other); @@ -882,11 +876,6 @@ class LIBPROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message /* ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -923,18 +912,6 @@ class LIBPROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message /* const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& field() const; - // repeated .google.protobuf.FieldDescriptorProto extension = 6; - int extension_size() const; - void clear_extension(); - static const int kExtensionFieldNumber = 6; - const ::google::protobuf::FieldDescriptorProto& extension(int index) const; - ::google::protobuf::FieldDescriptorProto* mutable_extension(int index); - ::google::protobuf::FieldDescriptorProto* add_extension(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >* - mutable_extension(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& - extension() const; - // repeated .google.protobuf.DescriptorProto nested_type = 3; int nested_type_size() const; void clear_nested_type(); @@ -971,6 +948,18 @@ class LIBPROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message /* const ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ExtensionRange >& extension_range() const; + // repeated .google.protobuf.FieldDescriptorProto extension = 6; + int extension_size() const; + void clear_extension(); + static const int kExtensionFieldNumber = 6; + const ::google::protobuf::FieldDescriptorProto& extension(int index) const; + ::google::protobuf::FieldDescriptorProto* mutable_extension(int index); + ::google::protobuf::FieldDescriptorProto* add_extension(); + ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >* + mutable_extension(); + const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& + extension() const; + // repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8; int oneof_decl_size() const; void clear_oneof_decl(); @@ -1052,10 +1041,10 @@ class LIBPROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message /* ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto > field_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto > extension_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto > nested_type_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto > enum_type_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ExtensionRange > extension_range_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto > extension_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::OneofDescriptorProto > oneof_decl_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ReservedRange > reserved_range_; ::google::protobuf::RepeatedPtrField< ::std::string> reserved_name_; @@ -1092,6 +1081,8 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa return reinterpret_cast( &_FieldDescriptorProto_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 5; void Swap(FieldDescriptorProto* other); @@ -1114,11 +1105,6 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -1241,21 +1227,6 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa ::std::string* release_name(); void set_allocated_name(::std::string* name); - // optional string type_name = 6; - bool has_type_name() const; - void clear_type_name(); - static const int kTypeNameFieldNumber = 6; - const ::std::string& type_name() const; - void set_type_name(const ::std::string& value); - #if LANG_CXX11 - void set_type_name(::std::string&& value); - #endif - void set_type_name(const char* value); - void set_type_name(const char* value, size_t size); - ::std::string* mutable_type_name(); - ::std::string* release_type_name(); - void set_allocated_type_name(::std::string* type_name); - // optional string extendee = 2; bool has_extendee() const; void clear_extendee(); @@ -1271,6 +1242,21 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa ::std::string* release_extendee(); void set_allocated_extendee(::std::string* extendee); + // optional string type_name = 6; + bool has_type_name() const; + void clear_type_name(); + static const int kTypeNameFieldNumber = 6; + const ::std::string& type_name() const; + void set_type_name(const ::std::string& value); + #if LANG_CXX11 + void set_type_name(::std::string&& value); + #endif + void set_type_name(const char* value); + void set_type_name(const char* value, size_t size); + ::std::string* mutable_type_name(); + ::std::string* release_type_name(); + void set_allocated_type_name(::std::string* type_name); + // optional string default_value = 7; bool has_default_value() const; void clear_default_value(); @@ -1365,8 +1351,8 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::internal::ArenaStringPtr type_name_; ::google::protobuf::internal::ArenaStringPtr extendee_; + ::google::protobuf::internal::ArenaStringPtr type_name_; ::google::protobuf::internal::ArenaStringPtr default_value_; ::google::protobuf::internal::ArenaStringPtr json_name_; ::google::protobuf::FieldOptions* options_; @@ -1405,6 +1391,8 @@ class LIBPROTOBUF_EXPORT OneofDescriptorProto : public ::google::protobuf::Messa return reinterpret_cast( &_OneofDescriptorProto_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 6; void Swap(OneofDescriptorProto* other); @@ -1427,11 +1415,6 @@ class LIBPROTOBUF_EXPORT OneofDescriptorProto : public ::google::protobuf::Messa ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -1520,6 +1503,8 @@ class LIBPROTOBUF_EXPORT EnumDescriptorProto : public ::google::protobuf::Messag return reinterpret_cast( &_EnumDescriptorProto_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 7; void Swap(EnumDescriptorProto* other); @@ -1542,11 +1527,6 @@ class LIBPROTOBUF_EXPORT EnumDescriptorProto : public ::google::protobuf::Messag ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -1648,6 +1628,8 @@ class LIBPROTOBUF_EXPORT EnumValueDescriptorProto : public ::google::protobuf::M return reinterpret_cast( &_EnumValueDescriptorProto_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 8; void Swap(EnumValueDescriptorProto* other); @@ -1670,11 +1652,6 @@ class LIBPROTOBUF_EXPORT EnumValueDescriptorProto : public ::google::protobuf::M ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -1773,6 +1750,8 @@ class LIBPROTOBUF_EXPORT ServiceDescriptorProto : public ::google::protobuf::Mes return reinterpret_cast( &_ServiceDescriptorProto_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 9; void Swap(ServiceDescriptorProto* other); @@ -1795,11 +1774,6 @@ class LIBPROTOBUF_EXPORT ServiceDescriptorProto : public ::google::protobuf::Mes ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -1901,6 +1875,8 @@ class LIBPROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Mess return reinterpret_cast( &_MethodDescriptorProto_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 10; void Swap(MethodDescriptorProto* other); @@ -1923,11 +1899,6 @@ class LIBPROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Mess ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -2072,6 +2043,8 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p return reinterpret_cast( &_FileOptions_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 11; void Swap(FileOptions* other); @@ -2094,11 +2067,6 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -2417,6 +2385,8 @@ class LIBPROTOBUF_EXPORT MessageOptions : public ::google::protobuf::Message /* return reinterpret_cast( &_MessageOptions_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 12; void Swap(MessageOptions* other); @@ -2439,11 +2409,6 @@ class LIBPROTOBUF_EXPORT MessageOptions : public ::google::protobuf::Message /* ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -2558,6 +2523,8 @@ class LIBPROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message /* @@ return reinterpret_cast( &_FieldOptions_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 13; void Swap(FieldOptions* other); @@ -2580,11 +2547,6 @@ class LIBPROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message /* @@ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -2681,13 +2643,6 @@ class LIBPROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message /* @@ ::google::protobuf::FieldOptions_CType ctype() const; void set_ctype(::google::protobuf::FieldOptions_CType value); - // optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL]; - bool has_jstype() const; - void clear_jstype(); - static const int kJstypeFieldNumber = 6; - ::google::protobuf::FieldOptions_JSType jstype() const; - void set_jstype(::google::protobuf::FieldOptions_JSType value); - // optional bool packed = 2; bool has_packed() const; void clear_packed(); @@ -2716,6 +2671,13 @@ class LIBPROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message /* @@ bool weak() const; void set_weak(bool value); + // optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL]; + bool has_jstype() const; + void clear_jstype(); + static const int kJstypeFieldNumber = 6; + ::google::protobuf::FieldOptions_JSType jstype() const; + void set_jstype(::google::protobuf::FieldOptions_JSType value); + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(FieldOptions) // @@protoc_insertion_point(class_scope:google.protobuf.FieldOptions) private: @@ -2739,11 +2701,11 @@ class LIBPROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message /* @@ mutable int _cached_size_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; int ctype_; - int jstype_; bool packed_; bool lazy_; bool deprecated_; bool weak_; + int jstype_; friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct; }; // ------------------------------------------------------------------- @@ -2775,6 +2737,8 @@ class LIBPROTOBUF_EXPORT OneofOptions : public ::google::protobuf::Message /* @@ return reinterpret_cast( &_OneofOptions_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 14; void Swap(OneofOptions* other); @@ -2797,11 +2761,6 @@ class LIBPROTOBUF_EXPORT OneofOptions : public ::google::protobuf::Message /* @@ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -2876,6 +2835,8 @@ class LIBPROTOBUF_EXPORT EnumOptions : public ::google::protobuf::Message /* @@p return reinterpret_cast( &_EnumOptions_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 15; void Swap(EnumOptions* other); @@ -2898,11 +2859,6 @@ class LIBPROTOBUF_EXPORT EnumOptions : public ::google::protobuf::Message /* @@p ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -2997,6 +2953,8 @@ class LIBPROTOBUF_EXPORT EnumValueOptions : public ::google::protobuf::Message / return reinterpret_cast( &_EnumValueOptions_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 16; void Swap(EnumValueOptions* other); @@ -3019,11 +2977,6 @@ class LIBPROTOBUF_EXPORT EnumValueOptions : public ::google::protobuf::Message / ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -3108,6 +3061,8 @@ class LIBPROTOBUF_EXPORT ServiceOptions : public ::google::protobuf::Message /* return reinterpret_cast( &_ServiceOptions_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 17; void Swap(ServiceOptions* other); @@ -3130,11 +3085,6 @@ class LIBPROTOBUF_EXPORT ServiceOptions : public ::google::protobuf::Message /* ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -3219,6 +3169,8 @@ class LIBPROTOBUF_EXPORT MethodOptions : public ::google::protobuf::Message /* @ return reinterpret_cast( &_MethodOptions_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 18; void Swap(MethodOptions* other); @@ -3241,11 +3193,6 @@ class LIBPROTOBUF_EXPORT MethodOptions : public ::google::protobuf::Message /* @ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -3368,6 +3315,8 @@ class LIBPROTOBUF_EXPORT UninterpretedOption_NamePart : public ::google::protobu return reinterpret_cast( &_UninterpretedOption_NamePart_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 19; void Swap(UninterpretedOption_NamePart* other); @@ -3390,11 +3339,6 @@ class LIBPROTOBUF_EXPORT UninterpretedOption_NamePart : public ::google::protobu ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -3484,6 +3428,8 @@ class LIBPROTOBUF_EXPORT UninterpretedOption : public ::google::protobuf::Messag return reinterpret_cast( &_UninterpretedOption_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 20; void Swap(UninterpretedOption* other); @@ -3506,11 +3452,6 @@ class LIBPROTOBUF_EXPORT UninterpretedOption : public ::google::protobuf::Messag ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -3668,6 +3609,8 @@ class LIBPROTOBUF_EXPORT SourceCodeInfo_Location : public ::google::protobuf::Me return reinterpret_cast( &_SourceCodeInfo_Location_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 21; void Swap(SourceCodeInfo_Location* other); @@ -3690,11 +3633,6 @@ class LIBPROTOBUF_EXPORT SourceCodeInfo_Location : public ::google::protobuf::Me ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -3840,6 +3778,8 @@ class LIBPROTOBUF_EXPORT SourceCodeInfo : public ::google::protobuf::Message /* return reinterpret_cast( &_SourceCodeInfo_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 22; void Swap(SourceCodeInfo* other); @@ -3862,11 +3802,6 @@ class LIBPROTOBUF_EXPORT SourceCodeInfo : public ::google::protobuf::Message /* ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -3940,6 +3875,8 @@ class LIBPROTOBUF_EXPORT GeneratedCodeInfo_Annotation : public ::google::protobu return reinterpret_cast( &_GeneratedCodeInfo_Annotation_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 23; void Swap(GeneratedCodeInfo_Annotation* other); @@ -3962,11 +3899,6 @@ class LIBPROTOBUF_EXPORT GeneratedCodeInfo_Annotation : public ::google::protobu ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -4077,6 +4009,8 @@ class LIBPROTOBUF_EXPORT GeneratedCodeInfo : public ::google::protobuf::Message return reinterpret_cast( &_GeneratedCodeInfo_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 24; void Swap(GeneratedCodeInfo* other); @@ -4099,11 +4033,6 @@ class LIBPROTOBUF_EXPORT GeneratedCodeInfo : public ::google::protobuf::Message ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -4222,6 +4151,7 @@ inline void FileDescriptorProto::set_name(::std::string&& value) { } #endif inline void FileDescriptorProto::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileDescriptorProto.name) @@ -4284,6 +4214,7 @@ inline void FileDescriptorProto::set_package(::std::string&& value) { } #endif inline void FileDescriptorProto::set_package(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_package(); package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileDescriptorProto.package) @@ -4340,6 +4271,7 @@ inline void FileDescriptorProto::set_dependency(int index, ::std::string&& value } #endif inline void FileDescriptorProto::set_dependency(int index, const char* value) { + GOOGLE_DCHECK(value != NULL); dependency_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.FileDescriptorProto.dependency) } @@ -4358,11 +4290,12 @@ inline void FileDescriptorProto::add_dependency(const ::std::string& value) { } #if LANG_CXX11 inline void FileDescriptorProto::add_dependency(::std::string&& value) { - dependency_.Add()->assign(std::move(value)); + dependency_.Add(std::move(value)); // @@protoc_insertion_point(field_add:google.protobuf.FileDescriptorProto.dependency) } #endif inline void FileDescriptorProto::add_dependency(const char* value) { + GOOGLE_DCHECK(value != NULL); dependency_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.FileDescriptorProto.dependency) } @@ -4683,6 +4616,7 @@ inline void FileDescriptorProto::set_syntax(::std::string&& value) { } #endif inline void FileDescriptorProto::set_syntax(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_syntax(); syntax_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileDescriptorProto.syntax) @@ -4853,6 +4787,7 @@ inline void DescriptorProto::set_name(::std::string&& value) { } #endif inline void DescriptorProto::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.DescriptorProto.name) @@ -5164,6 +5099,7 @@ inline void DescriptorProto::set_reserved_name(int index, ::std::string&& value) } #endif inline void DescriptorProto::set_reserved_name(int index, const char* value) { + GOOGLE_DCHECK(value != NULL); reserved_name_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.DescriptorProto.reserved_name) } @@ -5182,11 +5118,12 @@ inline void DescriptorProto::add_reserved_name(const ::std::string& value) { } #if LANG_CXX11 inline void DescriptorProto::add_reserved_name(::std::string&& value) { - reserved_name_.Add()->assign(std::move(value)); + reserved_name_.Add(std::move(value)); // @@protoc_insertion_point(field_add:google.protobuf.DescriptorProto.reserved_name) } #endif inline void DescriptorProto::add_reserved_name(const char* value) { + GOOGLE_DCHECK(value != NULL); reserved_name_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.DescriptorProto.reserved_name) } @@ -5241,6 +5178,7 @@ inline void FieldDescriptorProto::set_name(::std::string&& value) { } #endif inline void FieldDescriptorProto::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FieldDescriptorProto.name) @@ -5347,13 +5285,13 @@ inline void FieldDescriptorProto::set_type(::google::protobuf::FieldDescriptorPr // optional string type_name = 6; inline bool FieldDescriptorProto::has_type_name() const { - return (_has_bits_[0] & 0x00000002u) != 0; + return (_has_bits_[0] & 0x00000004u) != 0; } inline void FieldDescriptorProto::set_has_type_name() { - _has_bits_[0] |= 0x00000002u; + _has_bits_[0] |= 0x00000004u; } inline void FieldDescriptorProto::clear_has_type_name() { - _has_bits_[0] &= ~0x00000002u; + _has_bits_[0] &= ~0x00000004u; } inline void FieldDescriptorProto::clear_type_name() { type_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); @@ -5377,6 +5315,7 @@ inline void FieldDescriptorProto::set_type_name(::std::string&& value) { } #endif inline void FieldDescriptorProto::set_type_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_type_name(); type_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FieldDescriptorProto.type_name) @@ -5409,13 +5348,13 @@ inline void FieldDescriptorProto::set_allocated_type_name(::std::string* type_na // optional string extendee = 2; inline bool FieldDescriptorProto::has_extendee() const { - return (_has_bits_[0] & 0x00000004u) != 0; + return (_has_bits_[0] & 0x00000002u) != 0; } inline void FieldDescriptorProto::set_has_extendee() { - _has_bits_[0] |= 0x00000004u; + _has_bits_[0] |= 0x00000002u; } inline void FieldDescriptorProto::clear_has_extendee() { - _has_bits_[0] &= ~0x00000004u; + _has_bits_[0] &= ~0x00000002u; } inline void FieldDescriptorProto::clear_extendee() { extendee_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); @@ -5439,6 +5378,7 @@ inline void FieldDescriptorProto::set_extendee(::std::string&& value) { } #endif inline void FieldDescriptorProto::set_extendee(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_extendee(); extendee_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FieldDescriptorProto.extendee) @@ -5501,6 +5441,7 @@ inline void FieldDescriptorProto::set_default_value(::std::string&& value) { } #endif inline void FieldDescriptorProto::set_default_value(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_default_value(); default_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FieldDescriptorProto.default_value) @@ -5587,6 +5528,7 @@ inline void FieldDescriptorProto::set_json_name(::std::string&& value) { } #endif inline void FieldDescriptorProto::set_json_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_json_name(); json_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FieldDescriptorProto.json_name) @@ -5698,6 +5640,7 @@ inline void OneofDescriptorProto::set_name(::std::string&& value) { } #endif inline void OneofDescriptorProto::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.OneofDescriptorProto.name) @@ -5809,6 +5752,7 @@ inline void EnumDescriptorProto::set_name(::std::string&& value) { } #endif inline void EnumDescriptorProto::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.EnumDescriptorProto.name) @@ -5950,6 +5894,7 @@ inline void EnumValueDescriptorProto::set_name(::std::string&& value) { } #endif inline void EnumValueDescriptorProto::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.EnumValueDescriptorProto.name) @@ -6085,6 +6030,7 @@ inline void ServiceDescriptorProto::set_name(::std::string&& value) { } #endif inline void ServiceDescriptorProto::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.ServiceDescriptorProto.name) @@ -6226,6 +6172,7 @@ inline void MethodDescriptorProto::set_name(::std::string&& value) { } #endif inline void MethodDescriptorProto::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.MethodDescriptorProto.name) @@ -6288,6 +6235,7 @@ inline void MethodDescriptorProto::set_input_type(::std::string&& value) { } #endif inline void MethodDescriptorProto::set_input_type(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_input_type(); input_type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.MethodDescriptorProto.input_type) @@ -6350,6 +6298,7 @@ inline void MethodDescriptorProto::set_output_type(::std::string&& value) { } #endif inline void MethodDescriptorProto::set_output_type(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_output_type(); output_type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.MethodDescriptorProto.output_type) @@ -6509,6 +6458,7 @@ inline void FileOptions::set_java_package(::std::string&& value) { } #endif inline void FileOptions::set_java_package(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_java_package(); java_package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.java_package) @@ -6571,6 +6521,7 @@ inline void FileOptions::set_java_outer_classname(::std::string&& value) { } #endif inline void FileOptions::set_java_outer_classname(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_java_outer_classname(); java_outer_classname_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.java_outer_classname) @@ -6730,6 +6681,7 @@ inline void FileOptions::set_go_package(::std::string&& value) { } #endif inline void FileOptions::set_go_package(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_go_package(); go_package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.go_package) @@ -6912,6 +6864,7 @@ inline void FileOptions::set_objc_class_prefix(::std::string&& value) { } #endif inline void FileOptions::set_objc_class_prefix(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_objc_class_prefix(); objc_class_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.objc_class_prefix) @@ -6974,6 +6927,7 @@ inline void FileOptions::set_csharp_namespace(::std::string&& value) { } #endif inline void FileOptions::set_csharp_namespace(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_csharp_namespace(); csharp_namespace_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.csharp_namespace) @@ -7036,6 +6990,7 @@ inline void FileOptions::set_swift_prefix(::std::string&& value) { } #endif inline void FileOptions::set_swift_prefix(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_swift_prefix(); swift_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.swift_prefix) @@ -7098,6 +7053,7 @@ inline void FileOptions::set_php_class_prefix(::std::string&& value) { } #endif inline void FileOptions::set_php_class_prefix(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_php_class_prefix(); php_class_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.php_class_prefix) @@ -7319,13 +7275,13 @@ inline void FieldOptions::set_ctype(::google::protobuf::FieldOptions_CType value // optional bool packed = 2; inline bool FieldOptions::has_packed() const { - return (_has_bits_[0] & 0x00000004u) != 0; + return (_has_bits_[0] & 0x00000002u) != 0; } inline void FieldOptions::set_has_packed() { - _has_bits_[0] |= 0x00000004u; + _has_bits_[0] |= 0x00000002u; } inline void FieldOptions::clear_has_packed() { - _has_bits_[0] &= ~0x00000004u; + _has_bits_[0] &= ~0x00000002u; } inline void FieldOptions::clear_packed() { packed_ = false; @@ -7343,13 +7299,13 @@ inline void FieldOptions::set_packed(bool value) { // optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL]; inline bool FieldOptions::has_jstype() const { - return (_has_bits_[0] & 0x00000002u) != 0; + return (_has_bits_[0] & 0x00000020u) != 0; } inline void FieldOptions::set_has_jstype() { - _has_bits_[0] |= 0x00000002u; + _has_bits_[0] |= 0x00000020u; } inline void FieldOptions::clear_has_jstype() { - _has_bits_[0] &= ~0x00000002u; + _has_bits_[0] &= ~0x00000020u; } inline void FieldOptions::clear_jstype() { jstype_ = 0; @@ -7368,13 +7324,13 @@ inline void FieldOptions::set_jstype(::google::protobuf::FieldOptions_JSType val // optional bool lazy = 5 [default = false]; inline bool FieldOptions::has_lazy() const { - return (_has_bits_[0] & 0x00000008u) != 0; + return (_has_bits_[0] & 0x00000004u) != 0; } inline void FieldOptions::set_has_lazy() { - _has_bits_[0] |= 0x00000008u; + _has_bits_[0] |= 0x00000004u; } inline void FieldOptions::clear_has_lazy() { - _has_bits_[0] &= ~0x00000008u; + _has_bits_[0] &= ~0x00000004u; } inline void FieldOptions::clear_lazy() { lazy_ = false; @@ -7392,13 +7348,13 @@ inline void FieldOptions::set_lazy(bool value) { // optional bool deprecated = 3 [default = false]; inline bool FieldOptions::has_deprecated() const { - return (_has_bits_[0] & 0x00000010u) != 0; + return (_has_bits_[0] & 0x00000008u) != 0; } inline void FieldOptions::set_has_deprecated() { - _has_bits_[0] |= 0x00000010u; + _has_bits_[0] |= 0x00000008u; } inline void FieldOptions::clear_has_deprecated() { - _has_bits_[0] &= ~0x00000010u; + _has_bits_[0] &= ~0x00000008u; } inline void FieldOptions::clear_deprecated() { deprecated_ = false; @@ -7416,13 +7372,13 @@ inline void FieldOptions::set_deprecated(bool value) { // optional bool weak = 10 [default = false]; inline bool FieldOptions::has_weak() const { - return (_has_bits_[0] & 0x00000020u) != 0; + return (_has_bits_[0] & 0x00000010u) != 0; } inline void FieldOptions::set_has_weak() { - _has_bits_[0] |= 0x00000020u; + _has_bits_[0] |= 0x00000010u; } inline void FieldOptions::clear_has_weak() { - _has_bits_[0] &= ~0x00000020u; + _has_bits_[0] &= ~0x00000010u; } inline void FieldOptions::clear_weak() { weak_ = false; @@ -7819,6 +7775,7 @@ inline void UninterpretedOption_NamePart::set_name_part(::std::string&& value) { } #endif inline void UninterpretedOption_NamePart::set_name_part(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_name_part(); name_part_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.UninterpretedOption.NamePart.name_part) @@ -7939,6 +7896,7 @@ inline void UninterpretedOption::set_identifier_value(::std::string&& value) { } #endif inline void UninterpretedOption::set_identifier_value(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_identifier_value(); identifier_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.UninterpretedOption.identifier_value) @@ -8073,6 +8031,7 @@ inline void UninterpretedOption::set_string_value(::std::string&& value) { } #endif inline void UninterpretedOption::set_string_value(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_string_value(); string_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.UninterpretedOption.string_value) @@ -8135,6 +8094,7 @@ inline void UninterpretedOption::set_aggregate_value(::std::string&& value) { } #endif inline void UninterpretedOption::set_aggregate_value(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_aggregate_value(); aggregate_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.UninterpretedOption.aggregate_value) @@ -8261,6 +8221,7 @@ inline void SourceCodeInfo_Location::set_leading_comments(::std::string&& value) } #endif inline void SourceCodeInfo_Location::set_leading_comments(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_leading_comments(); leading_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.SourceCodeInfo.Location.leading_comments) @@ -8323,6 +8284,7 @@ inline void SourceCodeInfo_Location::set_trailing_comments(::std::string&& value } #endif inline void SourceCodeInfo_Location::set_trailing_comments(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_trailing_comments(); trailing_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.SourceCodeInfo.Location.trailing_comments) @@ -8379,6 +8341,7 @@ inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, :: } #endif inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, const char* value) { + GOOGLE_DCHECK(value != NULL); leading_detached_comments_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } @@ -8397,11 +8360,12 @@ inline void SourceCodeInfo_Location::add_leading_detached_comments(const ::std:: } #if LANG_CXX11 inline void SourceCodeInfo_Location::add_leading_detached_comments(::std::string&& value) { - leading_detached_comments_.Add()->assign(std::move(value)); + leading_detached_comments_.Add(std::move(value)); // @@protoc_insertion_point(field_add:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } #endif inline void SourceCodeInfo_Location::add_leading_detached_comments(const char* value) { + GOOGLE_DCHECK(value != NULL); leading_detached_comments_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } @@ -8520,6 +8484,7 @@ inline void GeneratedCodeInfo_Annotation::set_source_file(::std::string&& value) } #endif inline void GeneratedCodeInfo_Annotation::set_source_file(const char* value) { + GOOGLE_DCHECK(value != NULL); set_has_source_file(); source_file_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.GeneratedCodeInfo.Annotation.source_file) diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/descriptor.proto b/third_party/protobuf/3.2.0/src/google/protobuf/descriptor.proto index be22368390..f859c42972 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/descriptor.proto +++ b/third_party/protobuf/3.2.0/src/google/protobuf/descriptor.proto @@ -445,7 +445,7 @@ message MessageOptions { optional bool map_entry = 7; reserved 8; // javalite_serializable - + reserved 9; // javanano_as_lite // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -565,6 +565,7 @@ message EnumOptions { // is a formalization for deprecating enums. optional bool deprecated = 3 [default=false]; + reserved 5; // javanano_as_lite // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/descriptor_database.cc b/third_party/protobuf/3.2.0/src/google/protobuf/descriptor_database.cc index 57ae960f9b..4e46b2a88a 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/descriptor_database.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/descriptor_database.cc @@ -199,7 +199,7 @@ template bool SimpleDescriptorDatabase::DescriptorIndex::FindAllExtensionNumbers( const string& containing_type, std::vector* output) { - typename std::map, Value>::const_iterator it = + typename std::map, Value>::const_iterator it = by_extension_.lower_bound(std::make_pair(containing_type, 0)); bool success = false; @@ -213,7 +213,7 @@ bool SimpleDescriptorDatabase::DescriptorIndex::FindAllExtensionNumbers( } template -typename map::iterator +typename std::map::iterator SimpleDescriptorDatabase::DescriptorIndex::FindLastLessOrEqual( const string& name) { // Find the last key in the map which sorts less than or equal to the diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/descriptor_database.h b/third_party/protobuf/3.2.0/src/google/protobuf/descriptor_database.h index be97a6d886..28f8af7a2d 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/descriptor_database.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/descriptor_database.h @@ -102,6 +102,18 @@ class LIBPROTOBUF_EXPORT DescriptorDatabase { } + // Finds the file names and appends them to the output in an + // undefined order. This method is best-effort: it's not guaranteed that the + // database will find all files. Returns true if the database supports + // searching all file names, otherwise returns false and leaves output + // unchanged. + // + // This method has a default implementation that always returns + // false. + virtual bool FindAllFileNames(std::vector* output) { + return false; + } + private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorDatabase); }; diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/descriptor_database_unittest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/descriptor_database_unittest.cc index 05d67656f6..7e81d70af2 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/descriptor_database_unittest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/descriptor_database_unittest.cc @@ -44,7 +44,6 @@ #include #include #include -#include #include #include diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/descriptor_unittest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/descriptor_unittest.cc index 7ec75156b8..7523893117 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/descriptor_unittest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/descriptor_unittest.cc @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -52,7 +53,6 @@ #include #include #include -#include #include #include @@ -501,7 +501,7 @@ void ExtractDebugString( for (int i = 0; i < file->dependency_count(); ++i) { ExtractDebugString(file->dependency(i), visited, debug_strings); } - debug_strings->push_back(make_pair(file->name(), file->DebugString())); + debug_strings->push_back(std::make_pair(file->name(), file->DebugString())); } class SimpleErrorCollector : public google::protobuf::io::ErrorCollector { @@ -6066,6 +6066,7 @@ TEST_F(ValidationErrorTest, ValidateProto3JsonName) { "conflicts with field \"ab\". This is not allowed in proto3.\n"); } + // =================================================================== // DescriptorDatabase @@ -6824,6 +6825,360 @@ TEST_F(CopySourceCodeInfoToTest, CopySourceCodeInfoTo) { // =================================================================== +class LazilyBuildDependenciesTest : public testing::Test { + public: + LazilyBuildDependenciesTest() : pool_(&db_, NULL) { + pool_.InternalSetLazilyBuildDependencies(); + } + + void ParseProtoAndAddToDb(const char* proto) { + FileDescriptorProto tmp; + ASSERT_TRUE(TextFormat::ParseFromString(proto, &tmp)); + db_.Add(tmp); + } + + void ParseProtoAndAddToDb(const string& proto) { + FileDescriptorProto tmp; + ASSERT_TRUE(TextFormat::ParseFromString(proto, &tmp)); + db_.Add(tmp); + } + + void AddSimpleMessageProtoFileToDb(const char* file_name, + const char* message_name) { + ParseProtoAndAddToDb("name: '" + string(file_name) + + ".proto' " + "package: \"protobuf_unittest\" " + "message_type { " + " name:'" + + string(message_name) + + "' " + " field { name:'a' number:1 " + " label:LABEL_OPTIONAL " + " type_name:'int32' } " + "}"); + } + + void AddSimpleEnumProtoFileToDb(const char* file_name, const char* enum_name, + const char* enum_value_name) { + ParseProtoAndAddToDb("name: '" + string(file_name) + + ".proto' " + "package: 'protobuf_unittest' " + "enum_type { " + " name:'" + + string(enum_name) + + "' " + " value { name:'" + + string(enum_value_name) + + "' number:1 } " + "}"); + } + + protected: + SimpleDescriptorDatabase db_; + DescriptorPool pool_; +}; + +TEST_F(LazilyBuildDependenciesTest, Message) { + ParseProtoAndAddToDb( + "name: 'foo.proto' " + "package: 'protobuf_unittest' " + "dependency: 'bar.proto' " + "message_type { " + " name:'Foo' " + " field { name:'bar' number:1 label:LABEL_OPTIONAL " + "type_name:'.protobuf_unittest.Bar' } " + "}"); + AddSimpleMessageProtoFileToDb("bar", "Bar"); + + // Verify neither has been built yet. + EXPECT_FALSE(pool_.InternalIsFileLoaded("foo.proto")); + EXPECT_FALSE(pool_.InternalIsFileLoaded("bar.proto")); + + const FileDescriptor* file = pool_.FindFileByName("foo.proto"); + + // Verify only foo gets built when asking for foo.proto + EXPECT_TRUE(file != NULL); + EXPECT_TRUE(pool_.InternalIsFileLoaded("foo.proto")); + EXPECT_FALSE(pool_.InternalIsFileLoaded("bar.proto")); + + // Verify calling FindFieldBy* works when the type of the field was + // not built at cross link time. Verify this doesn't build the file + // the field's type is defined in, as well. + const Descriptor* desc = file->FindMessageTypeByName("Foo"); + const FieldDescriptor* field = desc->FindFieldByName("bar"); + EXPECT_TRUE(field != NULL); + EXPECT_EQ(field, desc->FindFieldByNumber(1)); + EXPECT_EQ(field, desc->FindFieldByLowercaseName("bar")); + EXPECT_EQ(field, desc->FindFieldByCamelcaseName("bar")); + EXPECT_FALSE(pool_.InternalIsFileLoaded("bar.proto")); + + // Finally, verify that if we call message_type() on the field, we will + // buid the file where the message is defined, and get a valid descriptor + EXPECT_TRUE(field->message_type() != NULL); + EXPECT_TRUE(pool_.InternalIsFileLoaded("bar.proto")); +} + +TEST_F(LazilyBuildDependenciesTest, Enum) { + ParseProtoAndAddToDb( + "name: 'foo.proto' " + "package: 'protobuf_unittest' " + "dependency: 'enum1.proto' " + "dependency: 'enum2.proto' " + "message_type { " + " name:'Lazy' " + " field { name:'enum1' number:1 label:LABEL_OPTIONAL " + "type_name:'.protobuf_unittest.Enum1' } " + " field { name:'enum2' number:1 label:LABEL_OPTIONAL " + "type_name:'.protobuf_unittest.Enum2' } " + "}"); + AddSimpleEnumProtoFileToDb("enum1", "Enum1", "ENUM1"); + AddSimpleEnumProtoFileToDb("enum2", "Enum2", "ENUM2"); + + const FileDescriptor* file = pool_.FindFileByName("foo.proto"); + + // Verify calling enum_type() on a field whose definition is not + // yet built will build the file and return a descriptor. + EXPECT_FALSE(pool_.InternalIsFileLoaded("enum1.proto")); + const Descriptor* desc = file->FindMessageTypeByName("Lazy"); + EXPECT_TRUE(desc != NULL); + const FieldDescriptor* field = desc->FindFieldByName("enum1"); + EXPECT_TRUE(field != NULL); + EXPECT_TRUE(field->enum_type() != NULL); + EXPECT_TRUE(pool_.InternalIsFileLoaded("enum1.proto")); + + // Verify calling default_value_enum() on a field whose definition is not + // yet built will build the file and return a descriptor to the value. + EXPECT_FALSE(pool_.InternalIsFileLoaded("enum2.proto")); + field = desc->FindFieldByName("enum2"); + EXPECT_TRUE(field != NULL); + EXPECT_TRUE(field->default_value_enum() != NULL); + EXPECT_TRUE(pool_.InternalIsFileLoaded("enum2.proto")); +} + +TEST_F(LazilyBuildDependenciesTest, Type) { + ParseProtoAndAddToDb( + "name: 'foo.proto' " + "package: 'protobuf_unittest' " + "dependency: 'message1.proto' " + "dependency: 'message2.proto' " + "dependency: 'enum1.proto' " + "dependency: 'enum2.proto' " + "message_type { " + " name:'Lazy' " + " field { name:'message1' number:1 label:LABEL_OPTIONAL " + "type_name:'.protobuf_unittest.Message1' } " + " field { name:'message2' number:1 label:LABEL_OPTIONAL " + "type_name:'.protobuf_unittest.Message2' } " + " field { name:'enum1' number:1 label:LABEL_OPTIONAL " + "type_name:'.protobuf_unittest.Enum1' } " + " field { name:'enum2' number:1 label:LABEL_OPTIONAL " + "type_name:'.protobuf_unittest.Enum2' } " + "}"); + AddSimpleMessageProtoFileToDb("message1", "Message1"); + AddSimpleMessageProtoFileToDb("message2", "Message2"); + AddSimpleEnumProtoFileToDb("enum1", "Enum1", "ENUM1"); + AddSimpleEnumProtoFileToDb("enum2", "Enum2", "ENUM2"); + + const FileDescriptor* file = pool_.FindFileByName("foo.proto"); + + // Verify calling type() on a field that is a message type will + // build the type defined in another file. + EXPECT_FALSE(pool_.InternalIsFileLoaded("message1.proto")); + const Descriptor* desc = file->FindMessageTypeByName("Lazy"); + EXPECT_TRUE(desc != NULL); + const FieldDescriptor* field = desc->FindFieldByName("message1"); + EXPECT_TRUE(field != NULL); + EXPECT_EQ(field->type(), FieldDescriptor::TYPE_MESSAGE); + EXPECT_TRUE(pool_.InternalIsFileLoaded("message1.proto")); + + // Verify calling cpp_type() on a field that is a message type will + // build the type defined in another file. + EXPECT_FALSE(pool_.InternalIsFileLoaded("message2.proto")); + field = desc->FindFieldByName("message2"); + EXPECT_TRUE(field != NULL); + EXPECT_EQ(field->cpp_type(), FieldDescriptor::CPPTYPE_MESSAGE); + EXPECT_TRUE(pool_.InternalIsFileLoaded("message2.proto")); + + // Verify calling type() on a field that is an enum type will + // build the type defined in another file. + EXPECT_FALSE(pool_.InternalIsFileLoaded("enum1.proto")); + field = desc->FindFieldByName("enum1"); + EXPECT_TRUE(field != NULL); + EXPECT_EQ(field->type(), FieldDescriptor::TYPE_ENUM); + EXPECT_TRUE(pool_.InternalIsFileLoaded("enum1.proto")); + + // Verify calling cpp_type() on a field that is an enum type will + // build the type defined in another file. + EXPECT_FALSE(pool_.InternalIsFileLoaded("enum2.proto")); + field = desc->FindFieldByName("enum2"); + EXPECT_TRUE(field != NULL); + EXPECT_EQ(field->cpp_type(), FieldDescriptor::CPPTYPE_ENUM); + EXPECT_TRUE(pool_.InternalIsFileLoaded("enum2.proto")); +} + +TEST_F(LazilyBuildDependenciesTest, Extension) { + ParseProtoAndAddToDb( + "name: 'foo.proto' " + "package: 'protobuf_unittest' " + "dependency: 'bar.proto' " + "dependency: 'baz.proto' " + "extension { extendee: '.protobuf_unittest.Bar' name:'bar' number:11" + " label:LABEL_OPTIONAL type_name:'.protobuf_unittest.Baz' }"); + ParseProtoAndAddToDb( + "name: 'bar.proto' " + "package: 'protobuf_unittest' " + "message_type { " + " name:'Bar' " + " extension_range { start: 10 end: 20 }" + "}"); + AddSimpleMessageProtoFileToDb("baz", "Baz"); + + // Verify none have been built yet. + EXPECT_FALSE(pool_.InternalIsFileLoaded("foo.proto")); + EXPECT_FALSE(pool_.InternalIsFileLoaded("bar.proto")); + EXPECT_FALSE(pool_.InternalIsFileLoaded("baz.proto")); + + const FileDescriptor* file = pool_.FindFileByName("foo.proto"); + + // Verify foo.bar gets loaded, and bar.proto gets loaded + // to register the extension. baz.proto should not get loaded. + EXPECT_TRUE(file != NULL); + EXPECT_TRUE(pool_.InternalIsFileLoaded("foo.proto")); + EXPECT_TRUE(pool_.InternalIsFileLoaded("bar.proto")); + EXPECT_FALSE(pool_.InternalIsFileLoaded("baz.proto")); +} + +TEST_F(LazilyBuildDependenciesTest, Service) { + ParseProtoAndAddToDb( + "name: 'foo.proto' " + "package: 'protobuf_unittest' " + "dependency: 'message1.proto' " + "dependency: 'message2.proto' " + "dependency: 'message3.proto' " + "dependency: 'message4.proto' " + "service {" + " name: 'LazyService'" + " method { name: 'A' input_type: '.protobuf_unittest.Message1' " + " output_type: '.protobuf_unittest.Message2' }" + "}"); + AddSimpleMessageProtoFileToDb("message1", "Message1"); + AddSimpleMessageProtoFileToDb("message2", "Message2"); + AddSimpleMessageProtoFileToDb("message3", "Message3"); + AddSimpleMessageProtoFileToDb("message4", "Message4"); + + const FileDescriptor* file = pool_.FindFileByName("foo.proto"); + + // Verify calling FindServiceByName or FindMethodByName doesn't build the + // files defining the input and output type, and input_type() and + // output_type() does indeed build the appropriate files. + const ServiceDescriptor* service = file->FindServiceByName("LazyService"); + EXPECT_TRUE(service != NULL); + const MethodDescriptor* method = service->FindMethodByName("A"); + EXPECT_FALSE(pool_.InternalIsFileLoaded("message1.proto")); + EXPECT_FALSE(pool_.InternalIsFileLoaded("message2.proto")); + EXPECT_TRUE(method != NULL); + EXPECT_TRUE(method->input_type() != NULL); + EXPECT_TRUE(pool_.InternalIsFileLoaded("message1.proto")); + EXPECT_FALSE(pool_.InternalIsFileLoaded("message2.proto")); + EXPECT_TRUE(method->output_type() != NULL); + EXPECT_TRUE(pool_.InternalIsFileLoaded("message2.proto")); +} + + +TEST_F(LazilyBuildDependenciesTest, GeneratedFile) { + // Most testing is done with custom pools with lazy dependencies forced on, + // do some sanity checking that lazy imports is on by default for the + // generated pool, and do custom options testing with generated to + // be able to use the GetExtension ids for the custom options. + + // Verify none of the files are loaded yet. + EXPECT_FALSE(DescriptorPool::generated_pool()->InternalIsFileLoaded( + "google/protobuf/unittest_lazy_dependencies.proto")); + EXPECT_FALSE(DescriptorPool::generated_pool()->InternalIsFileLoaded( + "google/protobuf/unittest_lazy_dependencies_custom_option.proto")); + EXPECT_FALSE(DescriptorPool::generated_pool()->InternalIsFileLoaded( + "google/protobuf/unittest_lazy_dependencies_enum.proto")); + + // Verify calling autogenerated function to get a descriptor in the base + // file will build that file but none of it's imports. This verifies that + // lazily_build_dependencies_ is set on the generated pool, and also that + // the generated function "descriptor()" doesn't somehow subvert the laziness + // by manually loading the dependencies or something. + EXPECT_TRUE(protobuf_unittest::lazy_imports::ImportedMessage::descriptor() != + NULL); + EXPECT_TRUE(DescriptorPool::generated_pool()->InternalIsFileLoaded( + "google/protobuf/unittest_lazy_dependencies.proto")); + EXPECT_FALSE(DescriptorPool::generated_pool()->InternalIsFileLoaded( + "google/protobuf/unittest_lazy_dependencies_custom_option.proto")); + EXPECT_FALSE(DescriptorPool::generated_pool()->InternalIsFileLoaded( + "google/protobuf/unittest_lazy_dependencies_enum.proto")); + + // Verify custom options work when defined in an import that isn't loaded, + // and that a non-default value of a custom option doesn't load the file + // where that enum is defined. + const google::protobuf::MessageOptions& options = + protobuf_unittest::lazy_imports::MessageCustomOption::descriptor() + ->options(); + protobuf_unittest::lazy_imports::LazyEnum custom_option_value = + options.GetExtension(protobuf_unittest::lazy_imports::lazy_enum_option); + + EXPECT_FALSE(DescriptorPool::generated_pool()->InternalIsFileLoaded( + "google/protobuf/unittest_lazy_dependencies_custom_option.proto")); + EXPECT_FALSE(DescriptorPool::generated_pool()->InternalIsFileLoaded( + "google/protobuf/unittest_lazy_dependencies_enum.proto")); + EXPECT_EQ(custom_option_value, protobuf_unittest::lazy_imports::LAZY_ENUM_1); + + const google::protobuf::MessageOptions& options2 = + protobuf_unittest::lazy_imports::MessageCustomOption2::descriptor() + ->options(); + custom_option_value = + options2.GetExtension(protobuf_unittest::lazy_imports::lazy_enum_option); + + EXPECT_FALSE(DescriptorPool::generated_pool()->InternalIsFileLoaded( + "google/protobuf/unittest_lazy_dependencies_custom_option.proto")); + EXPECT_FALSE(DescriptorPool::generated_pool()->InternalIsFileLoaded( + "google/protobuf/unittest_lazy_dependencies_enum.proto")); + EXPECT_EQ(custom_option_value, protobuf_unittest::lazy_imports::LAZY_ENUM_0); +} + +TEST_F(LazilyBuildDependenciesTest, Dependency) { + ParseProtoAndAddToDb( + "name: 'foo.proto' " + "package: 'protobuf_unittest' " + "dependency: 'bar.proto' " + "message_type { " + " name:'Foo' " + " field { name:'bar' number:1 label:LABEL_OPTIONAL " + "type_name:'.protobuf_unittest.Bar' } " + "}"); + ParseProtoAndAddToDb( + "name: 'bar.proto' " + "package: 'protobuf_unittest' " + "dependency: 'baz.proto' " + "message_type { " + " name:'Bar' " + " field { name:'baz' number:1 label:LABEL_OPTIONAL " + "type_name:'.protobuf_unittest.Baz' } " + "}"); + AddSimpleMessageProtoFileToDb("baz", "Baz"); + + const FileDescriptor* foo_file = pool_.FindFileByName("foo.proto"); + EXPECT_TRUE(foo_file != NULL); + // As expected, requesting foo.proto shouldn't build it's dependencies + EXPECT_TRUE(pool_.InternalIsFileLoaded("foo.proto")); + EXPECT_FALSE(pool_.InternalIsFileLoaded("bar.proto")); + EXPECT_FALSE(pool_.InternalIsFileLoaded("baz.proto")); + + // Verify calling dependency(N) will build the dependency, but + // not that file's dependencies. + const FileDescriptor* bar_file = foo_file->dependency(0); + EXPECT_TRUE(bar_file != NULL); + EXPECT_TRUE(pool_.InternalIsFileLoaded("bar.proto")); + EXPECT_FALSE(pool_.InternalIsFileLoaded("baz.proto")); +} + +// =================================================================== + } // namespace descriptor_unittest } // namespace protobuf diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/duration.pb.cc b/third_party/protobuf/3.2.0/src/google/protobuf/duration.pb.cc index e046cc5a7f..ae1a5e08f5 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/duration.pb.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/duration.pb.cc @@ -31,11 +31,26 @@ namespace { } // namespace +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField + const TableStruct::entries[] = { + {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, +}; + +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField + const TableStruct::aux[] = { + ::google::protobuf::internal::AuxillaryParseTableField(), +}; +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const + TableStruct::schema[] = { + { NULL, NULL, 0, -1, -1, false }, +}; + const ::google::protobuf::uint32 TableStruct::offsets[] = { ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Duration, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Duration, seconds_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Duration, nanos_), }; @@ -186,7 +201,7 @@ void Duration::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* Duration::descriptor() { protobuf_google_2fprotobuf_2fduration_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fduration_2eproto::file_level_metadata[0].descriptor; + return protobuf_google_2fprotobuf_2fduration_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const Duration& Duration::default_instance() { @@ -266,6 +281,9 @@ failure: void Duration::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.Duration) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // int64 seconds = 1; if (this->seconds() != 0) { ::google::protobuf::internal::WireFormatLite::WriteInt64(1, this->seconds(), output); @@ -281,8 +299,10 @@ 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; + // int64 seconds = 1; if (this->seconds() != 0) { target = ::google::protobuf::internal::WireFormatLite::WriteInt64ToArray(1, this->seconds(), target); @@ -341,6 +361,9 @@ void Duration::MergeFrom(const Duration& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Duration) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + if (from.seconds() != 0) { set_seconds(from.seconds()); } @@ -394,7 +417,7 @@ void Duration::InternalSwap(Duration* other) { ::google::protobuf::Metadata Duration::GetMetadata() const { protobuf_google_2fprotobuf_2fduration_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fduration_2eproto::file_level_metadata[0]; + return protobuf_google_2fprotobuf_2fduration_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/duration.pb.h b/third_party/protobuf/3.2.0/src/google/protobuf/duration.pb.h index 591c11d1da..34873d9744 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/duration.pb.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/duration.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3002000 +#if GOOGLE_PROTOBUF_VERSION < 3003000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003000 < 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. @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,9 @@ namespace protobuf { namespace protobuf_google_2fprotobuf_2fduration_2eproto { // Internal implementation detail -- do not call these. struct LIBPROTOBUF_EXPORT TableStruct { + static const ::google::protobuf::internal::ParseTableField entries[]; + static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; + static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; static void InitDefaultsImpl(); static void Shutdown(); @@ -78,6 +82,8 @@ class LIBPROTOBUF_EXPORT Duration : public ::google::protobuf::Message /* @@prot return reinterpret_cast( &_Duration_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 0; void UnsafeArenaSwap(Duration* other); void Swap(Duration* other); @@ -101,11 +107,6 @@ class LIBPROTOBUF_EXPORT Duration : public ::google::protobuf::Message /* @@prot ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -154,7 +155,7 @@ class LIBPROTOBUF_EXPORT Duration : public ::google::protobuf::Message /* @@prot ::google::protobuf::int64 seconds_; ::google::protobuf::int32 nanos_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fduration_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2fduration_2eproto::TableStruct; }; // =================================================================== diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/duration.proto b/third_party/protobuf/3.2.0/src/google/protobuf/duration.proto index 7f461f408d..975fce41aa 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/duration.proto +++ b/third_party/protobuf/3.2.0/src/google/protobuf/duration.proto @@ -47,6 +47,8 @@ option objc_class_prefix = "GPB"; // two Timestamp values is a Duration and it can be added or subtracted // from a Timestamp. Range is approximately +-10,000 years. // +// # Examples +// // Example 1: Compute Duration from two Timestamps in pseudo code. // // Timestamp start = ...; @@ -87,11 +89,22 @@ option objc_class_prefix = "GPB"; // duration = Duration() // duration.FromTimedelta(td) // +// # JSON Mapping +// +// In JSON format, the Duration type is encoded as a string rather than an +// object, where the string ends in the suffix "s" (indicating seconds) and +// is preceded by the number of seconds, with nanoseconds expressed as +// fractional seconds. For example, 3 seconds with 0 nanoseconds should be +// encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should +// be expressed in JSON format as "3.000000001s", and 3 seconds and 1 +// microsecond should be expressed in JSON format as "3.000001s". +// // message Duration { // Signed seconds of the span of time. Must be from -315,576,000,000 - // to +315,576,000,000 inclusive. + // to +315,576,000,000 inclusive. Note: these bounds are computed from: + // 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years int64 seconds = 1; // Signed fractions of a second at nanosecond resolution of the span diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/dynamic_message.cc b/third_party/protobuf/3.2.0/src/google/protobuf/dynamic_message.cc index d6bde495ba..ee8113e31d 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/dynamic_message.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/dynamic_message.cc @@ -77,13 +77,14 @@ #include #include #include +#include +#include #include +#include #include #include -#include -#include #include -#include + namespace google { namespace protobuf { @@ -239,6 +240,7 @@ class DynamicMessage : public Message { // looking back at this field. This would assume details about the // implementation of scoped_ptr. const DynamicMessage* prototype; + int weak_field_map_offset; // The offset for the weak_field_map; TypeInfo() : prototype(NULL) {} @@ -323,7 +325,6 @@ void DynamicMessage::SharedCtor() { // constructor.) const Descriptor* descriptor = type_info_->type; - // Initialize oneof cases. for (int i = 0 ; i < descriptor->oneof_decl_count(); ++i) { new (OffsetToPointer(type_info_->oneof_case_offset + sizeof(uint32) * i)) @@ -336,7 +337,6 @@ void DynamicMessage::SharedCtor() { if (type_info_->extensions_offset != -1) { new (OffsetToPointer(type_info_->extensions_offset)) ExtensionSet; } - for (int i = 0; i < descriptor->field_count(); i++) { const FieldDescriptor* field = descriptor->field(i); void* field_ptr = OffsetToPointer(type_info_->offsets[i]); @@ -537,7 +537,6 @@ void DynamicMessage::CrossLinkPrototypes() { for (int i = 0; i < descriptor->field_count(); i++) { const FieldDescriptor* field = descriptor->field(i); void* field_ptr = OffsetToPointer(type_info_->offsets[i]); - if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && !field->is_repeated()) { // For fields with message types, we need to cross-link with the @@ -694,6 +693,7 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock( // All the fields. // // TODO(b/31226269): Optimize the order of fields to minimize padding. + int num_weak_fields = 0; for (int i = 0; i < type->field_count(); i++) { // Make sure field is aligned to avoid bus errors. // Oneof fields do not use any space. @@ -717,6 +717,8 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock( type_info->internal_metadata_offset = size; size += sizeof(InternalMetadataWithArena); + type_info->weak_field_map_offset = -1; + // Align the final size to make sure no clever allocators think that // alignment is not necessary. type_info->size = size; @@ -738,7 +740,6 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock( } } size = AlignOffset(size); - // Allocate the prototype + oneof fields. void* base = operator new(size); memset(base, 0, size); @@ -752,7 +753,7 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock( type_info->prototype = static_cast(base); DynamicMessage* prototype = new(base) DynamicMessage(type_info); - if (type->oneof_decl_count() > 0) { + if (type->oneof_decl_count() > 0 || num_weak_fields > 0) { // Construct default oneof instance. ConstructDefaultOneofInstance(type_info->type, type_info->offsets.get(), @@ -767,7 +768,8 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock( type_info->internal_metadata_offset, type_info->extensions_offset, type_info->oneof_case_offset, - type_info->size}; + type_info->size, + type_info->weak_field_map_offset}; type_info->reflection.reset(new GeneratedMessageReflection( type_info->type, schema, type_info->pool, this)); @@ -781,12 +783,12 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock( void DynamicMessageFactory::ConstructDefaultOneofInstance( const Descriptor* type, const uint32 offsets[], - void* default_oneof_instance) { + void* default_oneof_or_weak_instance) { for (int i = 0; i < type->oneof_decl_count(); i++) { for (int j = 0; j < type->oneof_decl(i)->field_count(); j++) { const FieldDescriptor* field = type->oneof_decl(i)->field(j); void* field_ptr = reinterpret_cast( - default_oneof_instance) + offsets[field->index()]; + default_oneof_or_weak_instance) + offsets[field->index()]; switch (field->cpp_type()) { #define HANDLE_TYPE(CPPTYPE, TYPE) \ case FieldDescriptor::CPPTYPE_##CPPTYPE: \ diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/empty.pb.cc b/third_party/protobuf/3.2.0/src/google/protobuf/empty.pb.cc index 31cba09716..71195056f7 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/empty.pb.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/empty.pb.cc @@ -31,11 +31,26 @@ namespace { } // namespace +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField + const TableStruct::entries[] = { + {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, +}; + +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField + const TableStruct::aux[] = { + ::google::protobuf::internal::AuxillaryParseTableField(), +}; +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const + TableStruct::schema[] = { + { NULL, NULL, 0, -1, -1, false }, +}; + const ::google::protobuf::uint32 TableStruct::offsets[] = { ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Empty, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ }; static const ::google::protobuf::internal::MigrationSchema schemas[] = { @@ -176,7 +191,7 @@ void Empty::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* Empty::descriptor() { protobuf_google_2fprotobuf_2fempty_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fempty_2eproto::file_level_metadata[0].descriptor; + return protobuf_google_2fprotobuf_2fempty_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const Empty& Empty::default_instance() { @@ -221,13 +236,18 @@ failure: void Empty::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.Empty) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // @@protoc_insertion_point(serialize_end:google.protobuf.Empty) } ::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; + // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Empty) return target; } @@ -262,6 +282,9 @@ void Empty::MergeFrom(const Empty& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Empty) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + } void Empty::CopyFrom(const ::google::protobuf::Message& from) { @@ -307,7 +330,7 @@ void Empty::InternalSwap(Empty* other) { ::google::protobuf::Metadata Empty::GetMetadata() const { protobuf_google_2fprotobuf_2fempty_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fempty_2eproto::file_level_metadata[0]; + return protobuf_google_2fprotobuf_2fempty_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/empty.pb.h b/third_party/protobuf/3.2.0/src/google/protobuf/empty.pb.h index a75d6dd695..f28dc19beb 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/empty.pb.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/empty.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3002000 +#if GOOGLE_PROTOBUF_VERSION < 3003000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003000 < 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. @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,9 @@ namespace protobuf { namespace protobuf_google_2fprotobuf_2fempty_2eproto { // Internal implementation detail -- do not call these. struct LIBPROTOBUF_EXPORT TableStruct { + static const ::google::protobuf::internal::ParseTableField entries[]; + static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; + static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; static void InitDefaultsImpl(); static void Shutdown(); @@ -78,6 +82,8 @@ class LIBPROTOBUF_EXPORT Empty : public ::google::protobuf::Message /* @@protoc_ return reinterpret_cast( &_Empty_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 0; void UnsafeArenaSwap(Empty* other); void Swap(Empty* other); @@ -101,11 +107,6 @@ class LIBPROTOBUF_EXPORT Empty : public ::google::protobuf::Message /* @@protoc_ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -140,7 +141,7 @@ class LIBPROTOBUF_EXPORT Empty : public ::google::protobuf::Message /* @@protoc_ typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fempty_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2fempty_2eproto::TableStruct; }; // =================================================================== diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/extension_set.h b/third_party/protobuf/3.2.0/src/google/protobuf/extension_set.h index f5aa8de959..cf5f652da9 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/extension_set.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/extension_set.h @@ -416,7 +416,8 @@ class LIBPROTOBUF_EXPORT ExtensionSet { uint8* target) const; // For backward-compatibility, versions of two of the above methods that - // are never forced to serialize deterministically. + // serialize deterministically iff SetDefaultSerializationDeterministic() + // has been called. uint8* SerializeWithCachedSizesToArray(int start_field_number, int end_field_number, uint8* target) const; @@ -435,6 +436,8 @@ class LIBPROTOBUF_EXPORT ExtensionSet { // be linked in). It's up to the protocol compiler to avoid calling this on // such ExtensionSets (easy enough since lite messages don't implement // SpaceUsed()). + size_t SpaceUsedExcludingSelfLong() const; + int SpaceUsedExcludingSelf() const; private: @@ -457,7 +460,7 @@ class LIBPROTOBUF_EXPORT ExtensionSet { virtual bool IsInitialized() const = 0; virtual int ByteSize() const = 0; - virtual int SpaceUsed() const = 0; + virtual size_t SpaceUsedLong() const = 0; virtual void MergeFrom(const LazyMessageExtension& other) = 0; virtual void Clear() = 0; @@ -556,7 +559,7 @@ class LIBPROTOBUF_EXPORT ExtensionSet { void Clear(); int GetSize() const; void Free(); - int SpaceUsedExcludingSelf() const; + size_t SpaceUsedExcludingSelfLong() const; }; typedef std::map ExtensionMap; @@ -620,7 +623,7 @@ class LIBPROTOBUF_EXPORT ExtensionSet { // class. // Defined in extension_set_heavy.cc. - static inline int RepeatedMessage_SpaceUsedExcludingSelf( + static inline size_t RepeatedMessage_SpaceUsedExcludingSelfLong( RepeatedPtrFieldBase* field); // The Extension struct is small enough to be passed by value, so we use it @@ -1100,7 +1103,7 @@ template inline // parameter, and thus make an instance of ExtensionIdentifier have no // actual contents. However, if we did that, then using at extension // identifier would not necessarily cause the compiler to output any sort -// of reference to any simple defined in the extension's .pb.o file. Some +// of reference to any symbol defined in the extension's .pb.o file. Some // linkers will actually drop object files that are not explicitly referenced, // but that would be bad because it would cause this extension to not be // registered at static initialization, and therefore using it would crash. diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/extension_set_heavy.cc b/third_party/protobuf/3.2.0/src/google/protobuf/extension_set_heavy.cc index 8f8f180a7e..f545fe30f9 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/extension_set_heavy.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/extension_set_heavy.cc @@ -341,31 +341,35 @@ bool ExtensionSet::ParseMessageSet(io::CodedInputStream* input, } int ExtensionSet::SpaceUsedExcludingSelf() const { - int total_size = + return internal::FromIntSize(SpaceUsedExcludingSelfLong()); +} + +size_t ExtensionSet::SpaceUsedExcludingSelfLong() const { + size_t total_size = extensions_.size() * sizeof(ExtensionMap::value_type); for (ExtensionMap::const_iterator iter = extensions_.begin(), end = extensions_.end(); iter != end; ++iter) { - total_size += iter->second.SpaceUsedExcludingSelf(); + total_size += iter->second.SpaceUsedExcludingSelfLong(); } return total_size; } -inline int ExtensionSet::RepeatedMessage_SpaceUsedExcludingSelf( +inline size_t ExtensionSet::RepeatedMessage_SpaceUsedExcludingSelfLong( RepeatedPtrFieldBase* field) { - return field->SpaceUsedExcludingSelf >(); + return field->SpaceUsedExcludingSelfLong >(); } -int ExtensionSet::Extension::SpaceUsedExcludingSelf() const { - int total_size = 0; +size_t ExtensionSet::Extension::SpaceUsedExcludingSelfLong() const { + size_t total_size = 0; if (is_repeated) { switch (cpp_type(type)) { -#define HANDLE_TYPE(UPPERCASE, LOWERCASE) \ - case FieldDescriptor::CPPTYPE_##UPPERCASE: \ - total_size += sizeof(*repeated_##LOWERCASE##_value) + \ - repeated_##LOWERCASE##_value->SpaceUsedExcludingSelf();\ - break +#define HANDLE_TYPE(UPPERCASE, LOWERCASE) \ + case FieldDescriptor::CPPTYPE_##UPPERCASE: \ + total_size += sizeof(*repeated_##LOWERCASE##_value) + \ + repeated_##LOWERCASE##_value->SpaceUsedExcludingSelfLong(); \ + break HANDLE_TYPE( INT32, int32); HANDLE_TYPE( INT64, int64); @@ -380,24 +384,25 @@ int ExtensionSet::Extension::SpaceUsedExcludingSelf() const { case FieldDescriptor::CPPTYPE_MESSAGE: // repeated_message_value is actually a RepeatedPtrField, - // but MessageLite has no SpaceUsed(), so we must directly call - // RepeatedPtrFieldBase::SpaceUsedExcludingSelf() with a different type - // handler. - total_size += sizeof(*repeated_message_value) + - RepeatedMessage_SpaceUsedExcludingSelf(repeated_message_value); + // but MessageLite has no SpaceUsedLong(), so we must directly call + // RepeatedPtrFieldBase::SpaceUsedExcludingSelfLong() with a different + // type handler. + total_size += + sizeof(*repeated_message_value) + + RepeatedMessage_SpaceUsedExcludingSelfLong(repeated_message_value); break; } } else { switch (cpp_type(type)) { case FieldDescriptor::CPPTYPE_STRING: total_size += sizeof(*string_value) + - StringSpaceUsedExcludingSelf(*string_value); + StringSpaceUsedExcludingSelfLong(*string_value); break; case FieldDescriptor::CPPTYPE_MESSAGE: if (is_lazy) { - total_size += lazymessage_value->SpaceUsed(); + total_size += lazymessage_value->SpaceUsedLong(); } else { - total_size += down_cast(message_value)->SpaceUsed(); + total_size += down_cast(message_value)->SpaceUsedLong(); } break; default: diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/extension_set_unittest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/extension_set_unittest.cc index d6b823c042..772d2734e9 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/extension_set_unittest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/extension_set_unittest.cc @@ -32,6 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. +#include #include #include #include @@ -46,7 +47,6 @@ #include #include -#include #include #include #include diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/field_mask.pb.cc b/third_party/protobuf/3.2.0/src/google/protobuf/field_mask.pb.cc index b054dffdd9..094c4cc9c2 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/field_mask.pb.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/field_mask.pb.cc @@ -31,11 +31,26 @@ namespace { } // namespace +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField + const TableStruct::entries[] = { + {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, +}; + +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField + const TableStruct::aux[] = { + ::google::protobuf::internal::AuxillaryParseTableField(), +}; +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const + TableStruct::schema[] = { + { NULL, NULL, 0, -1, -1, false }, +}; + const ::google::protobuf::uint32 TableStruct::offsets[] = { ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldMask, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldMask, paths_), }; @@ -159,7 +174,7 @@ void FieldMask::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* FieldMask::descriptor() { protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::file_level_metadata[0].descriptor; + return protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const FieldMask& FieldMask::default_instance() { @@ -231,6 +246,9 @@ failure: void FieldMask::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.FieldMask) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // repeated string paths = 1; for (int i = 0, n = this->paths_size(); i < n; i++) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -246,8 +264,10 @@ 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; + // repeated string paths = 1; for (int i = 0, n = this->paths_size(); i < n; i++) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -300,6 +320,9 @@ void FieldMask::MergeFrom(const FieldMask& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldMask) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + paths_.MergeFrom(from.paths_); } @@ -326,13 +349,13 @@ void FieldMask::Swap(FieldMask* other) { InternalSwap(other); } void FieldMask::InternalSwap(FieldMask* other) { - paths_.UnsafeArenaSwap(&other->paths_); + paths_.InternalSwap(&other->paths_); std::swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata FieldMask::GetMetadata() const { protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::file_level_metadata[0]; + return protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -364,6 +387,7 @@ void FieldMask::set_paths(int index, ::std::string&& value) { } #endif void FieldMask::set_paths(int index, const char* value) { + GOOGLE_DCHECK(value != NULL); paths_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.FieldMask.paths) } @@ -382,11 +406,12 @@ void FieldMask::add_paths(const ::std::string& value) { } #if LANG_CXX11 void FieldMask::add_paths(::std::string&& value) { - paths_.Add()->assign(std::move(value)); + paths_.Add(std::move(value)); // @@protoc_insertion_point(field_add:google.protobuf.FieldMask.paths) } #endif void FieldMask::add_paths(const char* value) { + GOOGLE_DCHECK(value != NULL); paths_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.FieldMask.paths) } diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/field_mask.pb.h b/third_party/protobuf/3.2.0/src/google/protobuf/field_mask.pb.h index b609f235b4..742c1cf9b8 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/field_mask.pb.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/field_mask.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3002000 +#if GOOGLE_PROTOBUF_VERSION < 3003000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003000 < 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. @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,9 @@ namespace protobuf { namespace protobuf_google_2fprotobuf_2ffield_5fmask_2eproto { // Internal implementation detail -- do not call these. struct LIBPROTOBUF_EXPORT TableStruct { + static const ::google::protobuf::internal::ParseTableField entries[]; + static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; + static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; static void InitDefaultsImpl(); static void Shutdown(); @@ -72,6 +76,8 @@ class LIBPROTOBUF_EXPORT FieldMask : public ::google::protobuf::Message /* @@pro return reinterpret_cast( &_FieldMask_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 0; void Swap(FieldMask* other); @@ -94,11 +100,6 @@ class LIBPROTOBUF_EXPORT FieldMask : public ::google::protobuf::Message /* @@pro ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -148,7 +149,7 @@ class LIBPROTOBUF_EXPORT FieldMask : public ::google::protobuf::Message /* @@pro ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::RepeatedPtrField< ::std::string> paths_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::TableStruct; }; // =================================================================== @@ -184,6 +185,7 @@ inline void FieldMask::set_paths(int index, ::std::string&& value) { } #endif inline void FieldMask::set_paths(int index, const char* value) { + GOOGLE_DCHECK(value != NULL); paths_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.FieldMask.paths) } @@ -202,11 +204,12 @@ inline void FieldMask::add_paths(const ::std::string& value) { } #if LANG_CXX11 inline void FieldMask::add_paths(::std::string&& value) { - paths_.Add()->assign(std::move(value)); + paths_.Add(std::move(value)); // @@protoc_insertion_point(field_add:google.protobuf.FieldMask.paths) } #endif inline void FieldMask::add_paths(const char* value) { + GOOGLE_DCHECK(value != NULL); paths_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.FieldMask.paths) } diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_reflection.cc b/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_reflection.cc index 2f8f8256b7..9aebd90126 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_reflection.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_reflection.cc @@ -190,7 +190,9 @@ GeneratedMessageReflection::GeneratedMessageReflection( schema_(schema), descriptor_pool_((pool == NULL) ? DescriptorPool::generated_pool() : pool), - message_factory_(factory) { + message_factory_(factory), + last_non_weak_field_index_(-1) { + last_non_weak_field_index_ = descriptor_->field_count() - 1; } GeneratedMessageReflection::~GeneratedMessageReflection() {} @@ -231,28 +233,25 @@ UnknownFieldSet* GeneratedMessageReflection::MutableUnknownFields( return MutableInternalMetadataWithArena(message)->mutable_unknown_fields(); } -int GeneratedMessageReflection::SpaceUsed(const Message& message) const { +size_t GeneratedMessageReflection::SpaceUsedLong(const Message& message) const { // object_size_ already includes the in-memory representation of each field // in the message, so we only need to account for additional memory used by // the fields. - int total_size = schema_.GetObjectSize(); + size_t total_size = schema_.GetObjectSize(); - total_size += GetUnknownFields(message).SpaceUsedExcludingSelf(); + total_size += GetUnknownFields(message).SpaceUsedExcludingSelfLong(); if (schema_.HasExtensionSet()) { - total_size += GetExtensionSet(message).SpaceUsedExcludingSelf(); + total_size += GetExtensionSet(message).SpaceUsedExcludingSelfLong(); } - - const int field_count = descriptor_->field_count(); - for (int i = 0; i < field_count; i++) { + for (int i = 0; i <= last_non_weak_field_index_; i++) { const FieldDescriptor* field = descriptor_->field(i); - if (field->is_repeated()) { switch (field->cpp_type()) { #define HANDLE_TYPE(UPPERCASE, LOWERCASE) \ case FieldDescriptor::CPPTYPE_##UPPERCASE : \ total_size += GetRaw >(message, field) \ - .SpaceUsedExcludingSelf(); \ + .SpaceUsedExcludingSelfLong(); \ break HANDLE_TYPE( INT32, int32); @@ -270,21 +269,21 @@ int GeneratedMessageReflection::SpaceUsed(const Message& message) const { default: // TODO(kenton): Support other string reps. case FieldOptions::STRING: total_size += GetRaw >(message, field) - .SpaceUsedExcludingSelf(); + .SpaceUsedExcludingSelfLong(); break; } break; case FieldDescriptor::CPPTYPE_MESSAGE: if (IsMapFieldInApi(field)) { - total_size += - GetRaw(message, field).SpaceUsedExcludingSelf(); + total_size += GetRaw(message, field) + .SpaceUsedExcludingSelfLong(); } else { // We don't know which subclass of RepeatedPtrFieldBase the type is, // so we use RepeatedPtrFieldBase directly. total_size += GetRaw(message, field) - .SpaceUsedExcludingSelf >(); + .SpaceUsedExcludingSelfLong >(); } break; @@ -320,7 +319,8 @@ int GeneratedMessageReflection::SpaceUsed(const Message& message) const { if (ptr != default_ptr) { // string fields are represented by just a pointer, so also // include sizeof(string) as well. - total_size += sizeof(*ptr) + StringSpaceUsedExcludingSelf(*ptr); + total_size += + sizeof(*ptr) + StringSpaceUsedExcludingSelfLong(*ptr); } break; } @@ -335,14 +335,13 @@ int GeneratedMessageReflection::SpaceUsed(const Message& message) const { } else { const Message* sub_message = GetRaw(message, field); if (sub_message != NULL) { - total_size += sub_message->SpaceUsed(); + total_size += sub_message->SpaceUsedLong(); } } break; } } } - return total_size; } @@ -643,14 +642,11 @@ void GeneratedMessageReflection::Swap( } } - const int field_count = descriptor_->field_count(); - for (int i = 0; i < field_count; i++) { + for (int i = 0; i <= last_non_weak_field_index_; i++) { const FieldDescriptor* field = descriptor_->field(i); - if (!field->containing_oneof()) { - SwapField(message1, message2, field); - } + if (field->containing_oneof()) continue; + SwapField(message1, message2, field); } - const int oneof_decl_count = descriptor_->oneof_decl_count(); for (int i = 0; i < oneof_decl_count; i++) { SwapOneofField(message1, message2, descriptor_->oneof_decl(i)); @@ -782,7 +778,6 @@ void GeneratedMessageReflection::ClearField( ClearOneofField(message, field); return; } - if (HasBit(*message, field)) { ClearBit(message, field); @@ -1026,10 +1021,8 @@ void GeneratedMessageReflection::ListFields( const uint32* const has_bits_indices = schema_.has_bit_indices_; const uint32* const oneof_case_array = &GetConstRefAtOffset(message, schema_.oneof_case_offset_); - - const int field_count = descriptor_->field_count(); - output->reserve(field_count); - for (int i = 0; i < field_count; i++) { + output->reserve(descriptor_->field_count()); + for (int i = 0; i <= last_non_weak_field_index_; i++) { const FieldDescriptor* field = descriptor_->field(i); if (field->is_repeated()) { if (FieldSize(message, field) > 0) { @@ -1052,7 +1045,6 @@ void GeneratedMessageReflection::ListFields( } } } - if (schema_.HasExtensionSet()) { GetExtensionSet(message).AppendToList(descriptor_, descriptor_pool_, output); @@ -1458,8 +1450,7 @@ const Message& GeneratedMessageReflection::GetMessage( GetExtensionSet(message).GetMessage( field->number(), field->message_type(), factory)); } else { - const Message* result; - result = GetRaw(message, field); + const Message* result = GetRaw(message, field); if (result == NULL) { result = DefaultRaw(field); } @@ -1479,6 +1470,7 @@ Message* GeneratedMessageReflection::MutableMessage( MutableExtensionSet(message)->MutableMessage(field, factory)); } else { Message* result; + Message** result_holder = MutableRaw(message, field); if (field->containing_oneof()) { @@ -1976,6 +1968,7 @@ inline const Type& GeneratedMessageReflection::DefaultRaw( // Simple accessors for manipulating has_bits_. inline bool GeneratedMessageReflection::HasBit( const Message& message, const FieldDescriptor* field) const { + GOOGLE_DCHECK(!field->options().weak()); if (schema_.HasHasbits()) { return IsIndexInHasBitSet(GetHasBits(message), schema_.HasBitIndex(field)); } @@ -2031,6 +2024,7 @@ inline bool GeneratedMessageReflection::HasBit( inline void GeneratedMessageReflection::SetBit( Message* message, const FieldDescriptor* field) const { + GOOGLE_DCHECK(!field->options().weak()); if (!schema_.HasHasbits()) { return; } @@ -2041,6 +2035,7 @@ inline void GeneratedMessageReflection::SetBit( inline void GeneratedMessageReflection::ClearBit( Message* message, const FieldDescriptor* field) const { + GOOGLE_DCHECK(!field->options().weak()); if (!schema_.HasHasbits()) { return; } @@ -2051,6 +2046,7 @@ inline void GeneratedMessageReflection::ClearBit( inline void GeneratedMessageReflection::SwapBit( Message* message1, Message* message2, const FieldDescriptor* field) const { + GOOGLE_DCHECK(!field->options().weak()); if (!schema_.HasHasbits()) { return; } @@ -2236,16 +2232,16 @@ ReflectionSchema MigrationToReflectionSchema( MigrationSchema migration_schema) { ReflectionSchema result; result.default_instance_ = *default_instance; - // First 5 offsets are offsets to the special fields. The following offsets + // First 6 offsets are offsets to the special fields. The following offsets // are the proto fields. - result.offsets_ = offsets + migration_schema.offsets_index + 4; + result.offsets_ = offsets + migration_schema.offsets_index + 5; result.has_bit_indices_ = offsets + migration_schema.has_bit_indices_index; result.has_bits_offset_ = offsets[migration_schema.offsets_index + 0]; result.metadata_offset_ = offsets[migration_schema.offsets_index + 1]; result.extensions_offset_ = offsets[migration_schema.offsets_index + 2]; result.oneof_case_offset_ = offsets[migration_schema.offsets_index + 3]; result.object_size_ = migration_schema.object_size; - result.weak_field_map_offset_ = 0; + result.weak_field_map_offset_ = offsets[migration_schema.offsets_index + 4]; return result; } @@ -2275,7 +2271,7 @@ class AssignDescriptorsHelper { if (!descriptor->options().map_entry()) { // Only set reflection for non map types. file_level_metadata_->reflection = new GeneratedMessageReflection( - descriptor, MigrationToReflectionSchema(default_instance_data_++, + descriptor, MigrationToReflectionSchema(default_instance_data_, offsets_, *schemas_), ::google::protobuf::DescriptorPool::generated_pool(), factory_); for (int i = 0; i < descriptor->enum_type_count(); i++) { @@ -2283,6 +2279,7 @@ class AssignDescriptorsHelper { } schemas_++; } + default_instance_data_++; file_level_metadata_++; } diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_reflection.h b/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_reflection.h index 8b1362a2a7..12b73ca3a7 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_reflection.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_reflection.h @@ -62,7 +62,15 @@ namespace protobuf { class DescriptorPool; class MapKey; class MapValueRef; -} +} // namespace protobuf + + +namespace protobuf { +namespace flat { +class MetadataBuilder; +} // namespace flat +} // namespace protobuf + namespace protobuf { namespace internal { @@ -73,6 +81,7 @@ class GeneratedMessageReflection; // Defined in other files. class ExtensionSet; // extension_set.h +class WeakFieldMap; // weak_field_map.h // This struct describes the internal layout of the message, hence this is // used to act on the message reflectively. @@ -83,17 +92,17 @@ class ExtensionSet; // extension_set.h // embedded message fields *must* have non-NULL pointers // in the default instance.) // offsets: An array of ints giving the byte offsets. -// For each oneof field, the offset is relative to the -// default_oneof_instance. These can be computed at compile -// time using the -// PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET() macro. -// For each none oneof field, the offset is related to -// the start of the message object. These can be computed -// at compile time using the +// For each oneof or weak field, the offset is relative to the +// default_instance. These can be computed at compile time +// using the +// GOOGLE_PROTOBUF_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET() +// macro. For each none oneof field, the offset is related to +// the start of the message object. These can be computed at +// compile time using the // GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET() macro. // Besides offsets for all fields, this array also contains -// offsets for oneof unions. The offset of the i-th oneof -// union is offsets[descriptor->field_count() + i]. +// offsets for oneof unions. The offset of the i-th oneof union +// is offsets[descriptor->field_count() + i]. // has_bit_indices: Mapping from field indexes to their index in the has // bit array. // has_bits_offset: Offset in the message of an array of uint32s of size @@ -114,6 +123,9 @@ class ExtensionSet; // extension_set.h // by sizeof(). // arena_offset: If a message doesn't have a unknown_field_set that stores // the arena, it must have a direct pointer to the arena. +// weak_field_map_offset: If the message proto has weak fields, this is the +// offset of _weak_field_map_ in the generated proto. Otherwise +// -1. struct ReflectionSchema { public: // Size of a google::protobuf::Message object of this type. @@ -187,6 +199,9 @@ struct ReflectionSchema { offsets_[field->index()]; } + + bool HasWeakFields() const { return weak_field_map_offset_ > 0; } + // These members are intended to be private, but we cannot actually make them // private because this prevents us from using aggregate initialization of // them, ie. @@ -240,8 +255,7 @@ struct MigrationSchema { // of whatever type the individual field would be. Strings and // Messages use RepeatedPtrFields while everything else uses // RepeatedFields. -class LIBPROTOBUF_EXPORT GeneratedMessageReflection PROTOBUF_FINAL - : public Reflection { +class LIBPROTOBUF_EXPORT GeneratedMessageReflection PROTOBUF_FINAL : public Reflection { public: // Constructs a GeneratedMessageReflection. // Parameters: @@ -263,7 +277,7 @@ class LIBPROTOBUF_EXPORT GeneratedMessageReflection PROTOBUF_FINAL const UnknownFieldSet& GetUnknownFields(const Message& message) const; UnknownFieldSet* MutableUnknownFields(Message* message) const; - int SpaceUsed(const Message& message) const; + size_t SpaceUsedLong(const Message& message) const; bool HasField(const Message& message, const FieldDescriptor* field) const; int FieldSize(const Message& message, const FieldDescriptor* field) const; @@ -481,7 +495,7 @@ class LIBPROTOBUF_EXPORT GeneratedMessageReflection PROTOBUF_FINAL const Descriptor* message_type) const; private: - friend class GeneratedMessage; + friend class google::protobuf::flat::MetadataBuilder; friend class upb::google_opensource::GMR_Handlers; const Descriptor* const descriptor_; @@ -489,6 +503,11 @@ class LIBPROTOBUF_EXPORT GeneratedMessageReflection PROTOBUF_FINAL const DescriptorPool* const descriptor_pool_; MessageFactory* const message_factory_; + // Last non weak field index. This is an optimization when most weak fields + // are at the end of the containing message. If a message proto doesn't + // contain weak fields, then this field equals descriptor_->field_count(). + int last_non_weak_field_index_; + template const T& GetRawNonOneof(const Message& message, const FieldDescriptor* field) const; @@ -614,40 +633,6 @@ class LIBPROTOBUF_EXPORT GeneratedMessageReflection PROTOBUF_FINAL GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GeneratedMessageReflection); }; -// Returns the offset of the given field within the given aggregate type. -// This is equivalent to the ANSI C offsetof() macro. However, according -// to the C++ standard, offsetof() only works on POD types, and GCC -// enforces this requirement with a warning. In practice, this rule is -// unnecessarily strict; there is probably no compiler or platform on -// which the offsets of the direct fields of a class are non-constant. -// Fields inherited from superclasses *can* have non-constant offsets, -// but that's not what this macro will be used for. -#if defined(__clang__) -// For Clang we use __builtin_offsetof() and suppress the warning, -// to avoid Control Flow Integrity and UBSan vptr sanitizers from -// crashing while trying to validate the invalid reinterpet_casts. -#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(TYPE, FIELD) \ - _Pragma("clang diagnostic push") \ - _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \ - __builtin_offsetof(TYPE, FIELD) \ - _Pragma("clang diagnostic pop") -#else -// Note that we calculate relative to the pointer value 16 here since if we -// just use zero, GCC complains about dereferencing a NULL pointer. We -// 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< ::google::protobuf::uint32>( \ - reinterpret_cast( \ - &reinterpret_cast(16)->FIELD) - \ - reinterpret_cast(16)) -#endif - -#define PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET(ONEOF, FIELD) \ - static_cast< ::google::protobuf::uint32>( \ - reinterpret_cast(&(ONEOF->FIELD)) \ - - reinterpret_cast(ONEOF)) - // There are some places in proto2 where dynamic_cast would be useful as an // optimization. For example, take Message::MergeFrom(const Message& other). // For a given generated message FooMessage, we generate these two methods: diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_table_driven.cc b/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_table_driven.cc new file mode 100644 index 0000000000..e281266dfe --- /dev/null +++ b/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_table_driven.cc @@ -0,0 +1,676 @@ +// 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. + +#include + +#include + +#include +#include +#include +#include +#include + + +namespace google { +namespace protobuf { +namespace internal { + + +namespace { + +enum StringType { + StringType_STRING = 0, + StringType_CORD = 1, + StringType_STRING_PIECE = 2 +}; + +template +inline Type* Raw(MessageLite* msg, int64 offset) { + return reinterpret_cast(reinterpret_cast(msg) + offset); +} + +template +inline const Type* Raw(const MessageLite* msg, int64 offset) { + return reinterpret_cast(reinterpret_cast(msg) + + offset); +} + +inline Arena* GetArena(MessageLite* msg, int64 arena_offset) { + if (GOOGLE_PREDICT_FALSE(arena_offset == -1)) { + return NULL; + } + + return Raw(msg, arena_offset)->arena(); +} + +template +inline Type* AddField(MessageLite* msg, int64 offset) { +#if LANG_CXX11 + static_assert(std::is_trivially_copy_assignable::value, + "Do not assign"); +#endif + + google::protobuf::RepeatedField* repeated = + Raw >(msg, offset); + return repeated->Add(); +} + +template <> +inline string* AddField(MessageLite* msg, int64 offset) { + google::protobuf::RepeatedPtrField* repeated = + Raw >(msg, offset); + return repeated->Add(); +} + + +template +inline void AddField(MessageLite* msg, int64 offset, Type value) { +#if LANG_CXX11 + static_assert(std::is_trivially_copy_assignable::value, + "Do not assign"); +#endif + *AddField(msg, offset) = value; +} + +inline void SetBit(uint32* has_bits, uint32 has_bit_index) { + GOOGLE_DCHECK(has_bits != NULL); + + uint32 mask = static_cast(1u) << (has_bit_index % 32); + has_bits[has_bit_index / 32u] |= mask; +} + +template +inline Type* MutableField(MessageLite* msg, uint32* has_bits, + uint32 has_bit_index, int64 offset) { + SetBit(has_bits, has_bit_index); + return Raw(msg, offset); +} + +template +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::value, + "Do not assign"); +#endif + *MutableField(msg, has_bits, has_bit_index, offset) = value; +} + +template +static inline bool HandleString(io::CodedInputStream* input, MessageLite* msg, + Arena* arena, uint32* has_bits, + uint32 has_bit_index, int64 offset, + const void* default_ptr, bool strict_utf8, + const char* field_name) { +#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED + const char* sdata; + size_t size; +#endif + + string* value; + if (repeated) { + value = AddField(msg, offset); + GOOGLE_DCHECK(value != NULL); + } else { + // TODO(ckennelly): Is this optimal? + value = MutableField(msg, has_bits, has_bit_index, offset) + ->Mutable(static_cast(default_ptr), arena); + GOOGLE_DCHECK(value != NULL); + } + + if (GOOGLE_PREDICT_FALSE(!WireFormatLite::ReadString(input, value))) { + return false; + } + +#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED + sdata = value->data(); + size = value->size(); +#endif + +#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED + if (validate) { + if (strict_utf8) { + if (GOOGLE_PREDICT_FALSE(!WireFormatLite::VerifyUtf8String( + sdata, size, WireFormatLite::PARSE, field_name))) { + return false; + } + } else { + WireFormatLite::VerifyUTF8String( + sdata, size, WireFormat::PARSE, field_name); + } + } +#endif + + return true; +} + +string* MutableUnknownFields(MessageLite* msg, int64 arena_offset) { + return Raw(msg, arena_offset) + ->mutable_unknown_fields(); +} + +// RepeatedMessageTypeHandler allows us to operate on RepeatedPtrField fields +// without instantiating the specific template. +class RepeatedMessageTypeHandler { + public: + typedef MessageLite Type; + static Arena* GetArena(Type* t) { return t->GetArena(); } + static void* GetMaybeArenaPointer(Type* t) { + return t->GetMaybeArenaPointer(); + } + static inline Type* NewFromPrototype(const Type* prototype, + Arena* arena = NULL) { + return prototype->New(arena); + } + static void Delete(Type* t, Arena* arena = NULL) { + if (arena == NULL) { + delete t; + } + } +}; + +inline bool ReadGroup(int field_number, io::CodedInputStream* input, + MessageLite* value, const ParseTable& table) { + if (GOOGLE_PREDICT_FALSE(!input->IncrementRecursionDepth())) { + return false; + } + + if (GOOGLE_PREDICT_FALSE(!MergePartialFromCodedStream(value, table, input))) { + return false; + } + + input->DecrementRecursionDepth(); + // Make sure the last thing read was an end tag for this group. + if (GOOGLE_PREDICT_FALSE(!input->LastTagWas(WireFormatLite::MakeTag( + field_number, WireFormatLite::WIRETYPE_END_GROUP)))) { + return false; + } + + return true; +} + +inline bool ReadMessage(io::CodedInputStream* input, MessageLite* value, + const ParseTable& table) { + int length; + if (GOOGLE_PREDICT_FALSE(!input->ReadVarintSizeAsInt(&length))) { + return false; + } + + std::pair p = + input->IncrementRecursionDepthAndPushLimit(length); + if (GOOGLE_PREDICT_FALSE(p.second < 0 || + !MergePartialFromCodedStream(value, table, input))) { + return false; + } + + // Make sure that parsing stopped when the limit was hit, not at an endgroup + // tag. + return input->DecrementRecursionDepthAndPopLimit(p.first); +} + +} // namespace + +class MergePartialFromCodedStreamHelper { + public: + static MessageLite* Add(RepeatedPtrFieldBase* field, + const MessageLite* prototype) { + return field->Add( + const_cast(prototype)); + } +}; + +bool MergePartialFromCodedStream(MessageLite* msg, const ParseTable& table, + io::CodedInputStream* input) { + // We require that has_bits are present, as to avoid having to check for them + // for every field. + // + // TODO(ckennelly): Make this a compile-time parameter with templates. + GOOGLE_DCHECK_GE(table.has_bits_offset, 0); + uint32* has_bits = Raw(msg, table.has_bits_offset); + GOOGLE_DCHECK(has_bits != NULL); + + while (true) { + uint32 tag = input->ReadTag(); + + const WireFormatLite::WireType wire_type = + WireFormatLite::GetTagWireType(tag); + const int field_number = WireFormatLite::GetTagFieldNumber(tag); + + if (GOOGLE_PREDICT_FALSE(field_number > table.max_field_number)) { + GOOGLE_DCHECK(!table.unknown_field_set); + ::google::protobuf::io::StringOutputStream unknown_fields_string( + MutableUnknownFields(msg, table.arena_offset)); + ::google::protobuf::io::CodedOutputStream unknown_fields_stream( + &unknown_fields_string, false); + + if (!::google::protobuf::internal::WireFormatLite::SkipField( + input, tag, &unknown_fields_stream)) { + return false; + } + + continue; + } + + // We implicitly verify that data points to a valid field as we check the + // wire types. Entries in table.fields[i] that do not correspond to valid + // field numbers have their normal_wiretype and packed_wiretype fields set + // with the kInvalidMask value. As wire_type cannot take on that value, we + // will never match. + const ParseTableField* data = table.fields + field_number; + + // TODO(ckennelly): Avoid sign extension + const int64 has_bit_index = data->has_bit_index; + const int64 offset = data->offset; + const unsigned char processing_type = data->processing_type; + + if (data->normal_wiretype == static_cast(wire_type)) { + // TODO(ckennelly): Use a computed goto on GCC/LLVM or otherwise eliminate + // the bounds check on processing_type. + + switch (processing_type) { +#define STR(S) #S +#define HANDLE_TYPE(TYPE, CPPTYPE) \ + case (WireFormatLite::TYPE_##TYPE): { \ + CPPTYPE value; \ + if (GOOGLE_PREDICT_FALSE( \ + (!WireFormatLite::ReadPrimitive< \ + CPPTYPE, WireFormatLite::TYPE_##TYPE>(input, &value)))) { \ + return false; \ + } \ + SetField(msg, has_bits, has_bit_index, offset, value); \ + break; \ + } \ + case (WireFormatLite::TYPE_##TYPE) | kRepeatedMask: { \ + google::protobuf::RepeatedField* values = \ + Raw >(msg, offset); \ + if (GOOGLE_PREDICT_FALSE((!WireFormatLite::ReadRepeatedPrimitive< \ + CPPTYPE, WireFormatLite::TYPE_##TYPE>( \ + data->tag_size, tag, input, values)))) { \ + return false; \ + } \ + break; \ + } + + HANDLE_TYPE(INT32, int32) + HANDLE_TYPE(INT64, int64) + HANDLE_TYPE(SINT32, int32) + HANDLE_TYPE(SINT64, int64) + HANDLE_TYPE(UINT32, uint32) + HANDLE_TYPE(UINT64, uint64) + + HANDLE_TYPE(FIXED32, uint32) + HANDLE_TYPE(FIXED64, uint64) + HANDLE_TYPE(SFIXED32, int32) + HANDLE_TYPE(SFIXED64, int64) + + HANDLE_TYPE(FLOAT, float) + HANDLE_TYPE(DOUBLE, double) + + HANDLE_TYPE(BOOL, bool) +#undef HANDLE_TYPE +#undef STR + case WireFormatLite::TYPE_BYTES: +#ifndef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED + case WireFormatLite::TYPE_STRING: +#endif + { + GOOGLE_DCHECK(!table.unknown_field_set); + Arena* const arena = GetArena(msg, table.arena_offset); + const void* default_ptr = table.aux[field_number].strings.default_ptr; + + if (GOOGLE_PREDICT_FALSE((!HandleString( + input, msg, arena, has_bits, has_bit_index, offset, + default_ptr, false, NULL)))) { + return false; + } + break; + } + case (WireFormatLite::TYPE_BYTES) | kRepeatedMask: +#ifndef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED + case (WireFormatLite::TYPE_STRING) | kRepeatedMask: +#endif + { + GOOGLE_DCHECK(!table.unknown_field_set); + Arena* const arena = GetArena(msg, table.arena_offset); + const void* default_ptr = + table.aux[field_number].strings.default_ptr; + + if (GOOGLE_PREDICT_FALSE((!HandleString( + input, msg, arena, has_bits, has_bit_index, offset, + default_ptr, false, NULL)))) { + return false; + } + break; + } +#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED + case (WireFormatLite::TYPE_STRING): { + GOOGLE_DCHECK(!table.unknown_field_set); + Arena* const arena = GetArena(msg, table.arena_offset); + const void* default_ptr = table.aux[field_number].strings.default_ptr; + const char* field_name = table.aux[field_number].strings.field_name; + const bool strict_utf8 = table.aux[field_number].strings.strict_utf8; + + if (GOOGLE_PREDICT_FALSE((!HandleString( + input, msg, arena, has_bits, has_bit_index, offset, + default_ptr, strict_utf8, field_name)))) { + return false; + } + break; + } + case (WireFormatLite::TYPE_STRING) | kRepeatedMask: { + GOOGLE_DCHECK(!table.unknown_field_set); + Arena* const arena = GetArena(msg, table.arena_offset); + const void* default_ptr = table.aux[field_number].strings.default_ptr; + const char* field_name = table.aux[field_number].strings.field_name; + const bool strict_utf8 = table.aux[field_number].strings.strict_utf8; + + if (GOOGLE_PREDICT_FALSE((!HandleString( + input, msg, arena, has_bits, has_bit_index, offset, + default_ptr, strict_utf8, field_name)))) { + return false; + } + break; + } +#endif + case WireFormatLite::TYPE_ENUM: { + int value; + if (GOOGLE_PREDICT_FALSE((!WireFormatLite::ReadPrimitive< + int, WireFormatLite::TYPE_ENUM>(input, &value)))) { + return false; + } + + AuxillaryParseTableField::EnumValidator validator = + table.aux[field_number].enums.validator; + if (validator(value)) { + SetField(msg, has_bits, has_bit_index, offset, value); + } else { + GOOGLE_DCHECK(!table.unknown_field_set); + + ::google::protobuf::io::StringOutputStream unknown_fields_string( + MutableUnknownFields(msg, table.arena_offset)); + ::google::protobuf::io::CodedOutputStream unknown_fields_stream( + &unknown_fields_string, false); + unknown_fields_stream.WriteVarint32(tag); + unknown_fields_stream.WriteVarint32(value); + } + break; + } + case WireFormatLite::TYPE_ENUM | kRepeatedMask: { + int value; + if (GOOGLE_PREDICT_FALSE((!WireFormatLite::ReadPrimitive< + int, WireFormatLite::TYPE_ENUM>(input, &value)))) { + return false; + } + + AuxillaryParseTableField::EnumValidator validator = + table.aux[field_number].enums.validator; + if (validator(value)) { + AddField(msg, offset, value); + } else { + GOOGLE_DCHECK(!table.unknown_field_set); + + ::google::protobuf::io::StringOutputStream unknown_fields_string( + MutableUnknownFields(msg, table.arena_offset)); + ::google::protobuf::io::CodedOutputStream unknown_fields_stream( + &unknown_fields_string, false); + unknown_fields_stream.WriteVarint32(tag); + unknown_fields_stream.WriteVarint32(value); + } + + break; + } + case WireFormatLite::TYPE_GROUP: { + MessageLite** submsg_holder = + MutableField(msg, has_bits, has_bit_index, offset); + MessageLite* submsg = *submsg_holder; + + if (submsg == NULL) { + GOOGLE_DCHECK(!table.unknown_field_set); + Arena* const arena = GetArena(msg, table.arena_offset); + const MessageLite* prototype = + table.aux[field_number].messages.default_message(); + submsg = prototype->New(arena); + *submsg_holder = submsg; + } + + const ParseTable* ptable = + table.aux[field_number].messages.parse_table; + + if (ptable) { + if (GOOGLE_PREDICT_FALSE( + !ReadGroup(field_number, input, submsg, *ptable))) { + return false; + } + } else if (!WireFormatLite::ReadGroup(field_number, input, submsg)) { + return false; + } + + break; + } + case WireFormatLite::TYPE_GROUP | kRepeatedMask: { + RepeatedPtrFieldBase* field = Raw(msg, offset); + const MessageLite* prototype = + table.aux[field_number].messages.default_message(); + GOOGLE_DCHECK(prototype != NULL); + + MessageLite* submsg = + MergePartialFromCodedStreamHelper::Add(field, prototype); + const ParseTable* ptable = + table.aux[field_number].messages.parse_table; + + if (ptable) { + if (GOOGLE_PREDICT_FALSE( + !ReadGroup(field_number, input, submsg, *ptable))) { + return false; + } + } else if (!WireFormatLite::ReadGroup(field_number, input, submsg)) { + return false; + } + + break; + } + case WireFormatLite::TYPE_MESSAGE: { + MessageLite** submsg_holder = + MutableField(msg, has_bits, has_bit_index, offset); + MessageLite* submsg = *submsg_holder; + + if (submsg == NULL) { + GOOGLE_DCHECK(!table.unknown_field_set); + Arena* const arena = GetArena(msg, table.arena_offset); + const MessageLite* prototype = + table.aux[field_number].messages.default_message(); + submsg = prototype->New(arena); + *submsg_holder = submsg; + } + + const ParseTable* ptable = + table.aux[field_number].messages.parse_table; + + if (ptable) { + if (GOOGLE_PREDICT_FALSE(!ReadMessage(input, submsg, *ptable))) { + return false; + } + } else if (!WireFormatLite::ReadMessage(input, submsg)) { + return false; + } + + break; + } + // TODO(ckennelly): Adapt ReadMessageNoVirtualNoRecursionDepth and + // manage input->IncrementRecursionDepth() here. + case WireFormatLite::TYPE_MESSAGE | kRepeatedMask: { + RepeatedPtrFieldBase* field = Raw(msg, offset); + const MessageLite* prototype = + table.aux[field_number].messages.default_message(); + GOOGLE_DCHECK(prototype != NULL); + + MessageLite* submsg = + MergePartialFromCodedStreamHelper::Add(field, prototype); + const ParseTable* ptable = + table.aux[field_number].messages.parse_table; + + if (ptable) { + if (GOOGLE_PREDICT_FALSE(!ReadMessage(input, submsg, *ptable))) { + return false; + } + } else if (!WireFormatLite::ReadMessage(input, submsg)) { + return false; + } + + break; + } + case 0: { + // Done. + return true; + } + default: + break; + } + } else if (data->packed_wiretype == static_cast(wire_type)) { + // Non-packable fields have their packed_wiretype masked with + // kNotPackedMask, which is impossible to match here. + GOOGLE_DCHECK(processing_type & kRepeatedMask); + GOOGLE_DCHECK_NE(processing_type, kRepeatedMask); + + + + // TODO(ckennelly): Use a computed goto on GCC/LLVM. + // + // Mask out kRepeatedMask bit, allowing the jump table to be smaller. + switch (static_cast( + processing_type ^ kRepeatedMask)) { +#define HANDLE_PACKED_TYPE(TYPE, CPPTYPE, CPPTYPE_METHOD) \ + case WireFormatLite::TYPE_##TYPE: { \ + google::protobuf::RepeatedField* values = \ + Raw >(msg, offset); \ + if (GOOGLE_PREDICT_FALSE( \ + (!WireFormatLite::ReadPackedPrimitive< \ + CPPTYPE, WireFormatLite::TYPE_##TYPE>(input, values)))) { \ + return false; \ + } \ + break; \ + } + + HANDLE_PACKED_TYPE(INT32, int32, Int32) + HANDLE_PACKED_TYPE(INT64, int64, Int64) + HANDLE_PACKED_TYPE(SINT32, int32, Int32) + HANDLE_PACKED_TYPE(SINT64, int64, Int64) + HANDLE_PACKED_TYPE(UINT32, uint32, UInt32) + HANDLE_PACKED_TYPE(UINT64, uint64, UInt64) + + HANDLE_PACKED_TYPE(FIXED32, uint32, UInt32) + HANDLE_PACKED_TYPE(FIXED64, uint64, UInt64) + HANDLE_PACKED_TYPE(SFIXED32, int32, Int32) + HANDLE_PACKED_TYPE(SFIXED64, int64, Int64) + + HANDLE_PACKED_TYPE(FLOAT, float, Float) + HANDLE_PACKED_TYPE(DOUBLE, double, Double) + + HANDLE_PACKED_TYPE(BOOL, bool, Bool) +#undef HANDLE_PACKED_TYPE + case WireFormatLite::TYPE_ENUM: { + // To avoid unnecessarily calling MutableUnknownFields (which mutates + // InternalMetadataWithArena) when all inputs in the repeated series + // are valid, we implement our own parser rather than call + // WireFormat::ReadPackedEnumPreserveUnknowns. + uint32 length; + if (GOOGLE_PREDICT_FALSE(!input->ReadVarint32(&length))) { + return false; + } + + AuxillaryParseTableField::EnumValidator validator = + table.aux[field_number].enums.validator; + google::protobuf::RepeatedField* values = + Raw >(msg, offset); + string* unknown_fields = NULL; + + io::CodedInputStream::Limit limit = input->PushLimit(length); + while (input->BytesUntilLimit() > 0) { + int value; + if (GOOGLE_PREDICT_FALSE( + (!google::protobuf::internal::WireFormatLite::ReadPrimitive< + int, WireFormatLite::TYPE_ENUM>(input, &value)))) { + return false; + } + + if (validator(value)) { + values->Add(value); + } else { + if (GOOGLE_PREDICT_FALSE(unknown_fields == NULL)) { + GOOGLE_DCHECK(!table.unknown_field_set); + unknown_fields = MutableUnknownFields(msg, table.arena_offset); + } + + ::google::protobuf::io::StringOutputStream unknown_fields_string( + unknown_fields); + ::google::protobuf::io::CodedOutputStream unknown_fields_stream( + &unknown_fields_string, false); + unknown_fields_stream.WriteVarint32(tag); + unknown_fields_stream.WriteVarint32(value); + } + } + input->PopLimit(limit); + + break; + } + case WireFormatLite::TYPE_STRING: + case WireFormatLite::TYPE_GROUP: + case WireFormatLite::TYPE_MESSAGE: + case WireFormatLite::TYPE_BYTES: + GOOGLE_DCHECK(false); + return false; + default: + break; + } + } else { + if (wire_type == WireFormatLite::WIRETYPE_END_GROUP) { + // Must be the end of the message. + return true; + } + + // process unknown field. + GOOGLE_DCHECK(!table.unknown_field_set); + ::google::protobuf::io::StringOutputStream unknown_fields_string( + MutableUnknownFields(msg, table.arena_offset)); + ::google::protobuf::io::CodedOutputStream unknown_fields_stream( + &unknown_fields_string, false); + + if (!::google::protobuf::internal::WireFormatLite::SkipField( + input, tag, &unknown_fields_stream)) { + return false; + } + } + } +} + +} // namespace internal +} // namespace protobuf +} // namespace google diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_table_driven.h b/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_table_driven.h new file mode 100644 index 0000000000..557c57d35c --- /dev/null +++ b/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_table_driven.h @@ -0,0 +1,173 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_TABLE_DRIVEN_H__ +#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_TABLE_DRIVEN_H__ + +#include + +#if LANG_CXX11 +#define PROTOBUF_CONSTEXPR constexpr + +// We require C++11 and Clang to use constexpr for variables, as GCC 4.8 +// requires constexpr to be consistent between declarations of variables +// unnecessarily (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58541). +#ifdef __clang__ +#define PROTOBUF_CONSTEXPR_VAR constexpr +#else // !__clang__ +#define PROTOBUF_CONSTEXPR_VAR +#endif // !_clang + +#else +#define PROTOBUF_CONSTEXPR +#define PROTOBUF_CONSTEXPR_VAR +#endif + +namespace google { +namespace protobuf { +namespace internal { + +static PROTOBUF_CONSTEXPR const unsigned char kOneofMask = 0x40; +static PROTOBUF_CONSTEXPR const unsigned char kRepeatedMask = 0x20; +// Check this against types. + +static PROTOBUF_CONSTEXPR const unsigned char kNotPackedMask = 0x10; +static PROTOBUF_CONSTEXPR const unsigned char kInvalidMask = 0x20; + +enum ProcessingTypes { + TYPE_STRING_CORD = 19, + TYPE_STRING_STRING_PIECE = 20, + TYPE_BYTES_CORD = 21, + TYPE_BYTES_STRING_PIECE = 22, +}; + +#if LANG_CXX11 +static_assert(TYPE_BYTES_STRING_PIECE < kRepeatedMask, "Invalid enum"); +#endif + +// TODO(ckennelly): Add a static assertion to ensure that these masks do not +// conflict with wiretypes. + +// ParseTableField is kept small to help simplify instructions for computing +// offsets, as we will always need this information to parse a field. +// Additional data, needed for some types, is stored in +// AuxillaryParseTableField. +struct ParseTableField { + uint32 offset; + uint32 has_bit_index; + unsigned char normal_wiretype; + unsigned char packed_wiretype; + + // processing_type is given by: + // (FieldDescriptor->type() << 1) | FieldDescriptor->is_packed() + unsigned char processing_type; + + unsigned char tag_size; +}; + +struct ParseTable; + +union AuxillaryParseTableField { + typedef bool (*EnumValidator)(int); + + // Enums + struct enum_aux { + EnumValidator validator; + const char* name; + }; + enum_aux enums; + // Group, messages + struct message_aux { + // ExplicitlyInitialized -> T requires a reinterpret_cast, which prevents + // the tables from being constructed as a constexpr. We use void to avoid + // the cast. + const void* default_message_void; + const MessageLite* default_message() const { + return static_cast(default_message_void); + } + const ParseTable* parse_table; + }; + message_aux messages; + // Strings + struct string_aux { + const void* default_ptr; + const char* field_name; + bool strict_utf8; + const char* name; + }; + string_aux strings; + +#if LANG_CXX11 + AuxillaryParseTableField() = default; +#else + AuxillaryParseTableField() { } +#endif + PROTOBUF_CONSTEXPR AuxillaryParseTableField( + AuxillaryParseTableField::enum_aux e) : enums(e) {} + PROTOBUF_CONSTEXPR AuxillaryParseTableField( + AuxillaryParseTableField::message_aux m) : messages(m) {} + PROTOBUF_CONSTEXPR AuxillaryParseTableField( + AuxillaryParseTableField::string_aux s) : strings(s) {} +}; + +struct ParseTable { + const ParseTableField* fields; + const AuxillaryParseTableField* aux; + int max_field_number; + // TODO(ckennelly): Do something with this padding. + + // TODO(ckennelly): Vet these for sign extension. + int64 has_bits_offset; + int64 arena_offset; + int unknown_field_set; +}; + +// TODO(jhen): Remove the __NVCC__ check when we get a version of nvcc that +// supports these checks. +#if LANG_CXX11 && !defined(__NVCC__) +static_assert(sizeof(ParseTableField) <= 16, "ParseTableField is too large"); +// The tables must be composed of POD components to ensure link-time +// initialization. +static_assert(std::is_pod::value, ""); +static_assert(std::is_pod::value, ""); +static_assert(std::is_pod::value, ""); +static_assert(std::is_pod::value, ""); +static_assert(std::is_pod::value, ""); +static_assert(std::is_pod::value, ""); +#endif + +bool MergePartialFromCodedStream(MessageLite* msg, const ParseTable& table, + io::CodedInputStream* input); + +} // namespace internal +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_TABLE_DRIVEN_H__ diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_util.cc b/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_util.cc index b4d2c9c150..35d8156ef3 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_util.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_util.cc @@ -58,7 +58,7 @@ void InitEmptyString() { OnShutdown(&DeleteEmptyString); } -int StringSpaceUsedExcludingSelf(const string& str) { +size_t StringSpaceUsedExcludingSelfLong(const string& str) { const void* start = &str; const void* end = &str + 1; if (start <= str.data() && str.data() < end) { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_util.h b/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_util.h index 14101832a2..44174466a8 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_util.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/generated_message_util.h @@ -39,14 +39,16 @@ #define GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__ #include +#include #include +#include #include #include #include #ifndef PROTOBUF_FINAL -#if LANG_CXX11 +#if LANG_CXX11 && !defined(__NVCC__) #define PROTOBUF_FINAL final #else #define PROTOBUF_FINAL @@ -75,6 +77,43 @@ namespace internal { #define GOOGLE_PROTOBUF_DEPRECATED_ATTR +// Returns the offset of the given field within the given aggregate type. +// This is equivalent to the ANSI C offsetof() macro. However, according +// to the C++ standard, offsetof() only works on POD types, and GCC +// enforces this requirement with a warning. In practice, this rule is +// unnecessarily strict; there is probably no compiler or platform on +// which the offsets of the direct fields of a class are non-constant. +// Fields inherited from superclasses *can* have non-constant offsets, +// but that's not what this macro will be used for. +#if defined(__clang__) +// For Clang we use __builtin_offsetof() and suppress the warning, +// to avoid Control Flow Integrity and UBSan vptr sanitizers from +// crashing while trying to validate the invalid reinterpet_casts. +#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(TYPE, FIELD) \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \ + __builtin_offsetof(TYPE, FIELD) \ + _Pragma("clang diagnostic pop") +#else +// Note that we calculate relative to the pointer value 16 here since if we +// just use zero, GCC complains about dereferencing a NULL pointer. We +// 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( \ + reinterpret_cast( \ + &reinterpret_cast(16)->FIELD) - \ + reinterpret_cast(16)) +#endif + +#define GOOGLE_PROTOBUF_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET(ONEOF, FIELD) \ + static_cast< ::google::protobuf::uint32>( \ + reinterpret_cast(&(ONEOF->FIELD)) \ + - reinterpret_cast(ONEOF)) +// TODO(acozzette): remove this transitional macro after updating generated code +#define PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET(ONEOF, FIELD) \ + GOOGLE_PROTOBUF_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET(ONEOF, FIELD) + // Constants for special floating point values. LIBPROTOBUF_EXPORT double Infinity(); LIBPROTOBUF_EXPORT double NaN(); @@ -125,7 +164,7 @@ class ExplicitlyConstructed { // Default empty string object. Don't use this directly. Instead, call // GetEmptyString() to get the reference. -LIBPROTOBUF_EXPORT extern ExplicitlyConstructed< ::std::string> fixed_address_empty_string; +extern ExplicitlyConstructed< ::std::string> fixed_address_empty_string; LIBPROTOBUF_EXPORT extern ProtobufOnceType empty_string_once_init_; LIBPROTOBUF_EXPORT void InitEmptyString(); @@ -139,7 +178,7 @@ LIBPROTOBUF_EXPORT inline const ::std::string& GetEmptyString() { return GetEmptyStringAlreadyInited(); } -LIBPROTOBUF_EXPORT int StringSpaceUsedExcludingSelf(const string& str); +LIBPROTOBUF_EXPORT size_t StringSpaceUsedExcludingSelfLong(const string& str); // True if IsInitialized() is true for all elements of t. Type is expected @@ -159,11 +198,21 @@ LIBPROTOBUF_EXPORT void InitProtobufDefaults(); // We compute sizes as size_t but cache them as int. This function converts a // computed size to a cached size. Since we don't proceed with serialization if // the total size was > INT_MAX, it is not important what this function returns -// for inputs > INT_MAX. +// for inputs > INT_MAX. However this case should not error or GOOGLE_CHECK-fail, +// because the full size_t resolution is still returned from ByteSizeLong() and +// checked against INT_MAX; we can catch the overflow there. inline int ToCachedSize(size_t size) { return static_cast(size); } +// For cases where a legacy function returns an integer size. We GOOGLE_DCHECK() that +// the conversion will fit within an integer; if this is false then we are +// losing information. +inline int ToIntSize(size_t size) { + GOOGLE_DCHECK_LE(size, static_cast(INT_MAX)); + return static_cast(size); +} + // We mainly calculate sizes in terms of size_t, but some functions that compute // sizes return "int". These int sizes are expected to always be positive. // This function is more efficient than casting an int to size_t directly on diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/io/coded_stream.cc b/third_party/protobuf/3.2.0/src/google/protobuf/io/coded_stream.cc index 3c2e0fbd2c..df4250e513 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/io/coded_stream.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/io/coded_stream.cc @@ -76,10 +76,6 @@ CodedInputStream::~CodedInputStream() { if (input_ != NULL) { BackUpInputToCurrentPosition(); } - - if (total_bytes_warning_threshold_ == -2) { - GOOGLE_LOG(WARNING) << "The total number of bytes read was " << total_bytes_read_; - } } // Static. @@ -123,21 +119,15 @@ CodedInputStream::Limit CodedInputStream::PushLimit(int byte_limit) { Limit old_limit = current_limit_; // security: byte_limit is possibly evil, so check for negative values - // and overflow. - if (byte_limit >= 0 && - byte_limit <= INT_MAX - current_position) { + // and overflow. Also check that the new requested limit is before the + // previous limit; otherwise we continue to enforce the previous limit. + if GOOGLE_PREDICT_TRUE(byte_limit >= 0 && + byte_limit <= INT_MAX - current_position && + byte_limit < current_limit_ - current_position) { current_limit_ = current_position + byte_limit; - } else { - // Negative or overflow. - current_limit_ = INT_MAX; + RecomputeBufferLimits(); } - // We need to enforce all limits, not just the new one, so if the previous - // limit was before the new requested limit, we continue to enforce the - // previous limit. - current_limit_ = std::min(current_limit_, old_limit); - - RecomputeBufferLimits(); return old_limit; } @@ -185,16 +175,12 @@ int CodedInputStream::BytesUntilLimit() const { void CodedInputStream::SetTotalBytesLimit( int total_bytes_limit, int warning_threshold) { + (void) warning_threshold; + // Make sure the limit isn't already past, since this could confuse other // code. int current_position = CurrentPosition(); total_bytes_limit_ = std::max(current_position, total_bytes_limit); - if (warning_threshold >= 0) { - total_bytes_warning_threshold_ = warning_threshold; - } else { - // warning_threshold is negative - total_bytes_warning_threshold_ = -1; - } RecomputeBufferLimits(); } @@ -605,20 +591,6 @@ bool CodedInputStream::Refresh() { return false; } - if (total_bytes_warning_threshold_ >= 0 && - total_bytes_read_ >= total_bytes_warning_threshold_) { - GOOGLE_LOG(INFO) << "Reading dangerously large protocol message. If the " - "message turns out to be larger than " - << total_bytes_limit_ << " bytes, parsing will be halted " - "for security reasons. To increase the limit (or to " - "disable these warnings), see " - "CodedInputStream::SetTotalBytesLimit() in " - "google/protobuf/io/coded_stream.h."; - - // Don't warn again for this stream, and print total size at the end. - total_bytes_warning_threshold_ = -2; - } - const void* void_buffer; int buffer_size; if (NextNonEmpty(input_, &void_buffer, &buffer_size)) { @@ -655,7 +627,7 @@ bool CodedInputStream::Refresh() { // CodedOutputStream ================================================= -bool CodedOutputStream::default_serialization_deterministic_ = false; +google::protobuf::internal::AtomicWord CodedOutputStream::default_serialization_deterministic_ = 0; CodedOutputStream::CodedOutputStream(ZeroCopyOutputStream* output) : output_(output), diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/io/coded_stream.h b/third_party/protobuf/3.2.0/src/google/protobuf/io/coded_stream.h index b71b4a989d..20d8614311 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/io/coded_stream.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/io/coded_stream.h @@ -131,7 +131,9 @@ #define PROTOBUF_LITTLE_ENDIAN 1 #endif #endif +#include #include +#include namespace google { @@ -371,11 +373,10 @@ class LIBPROTOBUF_EXPORT CodedInputStream { // maximum message length should be limited to the shortest length that // will not harm usability. The theoretical shortest message that could // cause integer overflows is 512MB. The default limit is 64MB. Apps - // should set shorter limits if possible. If warning_threshold is not -1, - // a warning will be printed to stderr after warning_threshold bytes are - // read. For backwards compatibility all negative values get squashed to -1, - // as other negative values might have special internal meanings. - // An error will always be printed to stderr if the limit is reached. + // should set shorter limits if possible. For backwards compatibility all + // negative values get squashed to -1, as other negative values might have + // special internal meanings. An error will always be printed to stderr if + // the limit is reached. // // This is unrelated to PushLimit()/PopLimit(). // @@ -568,12 +569,6 @@ class LIBPROTOBUF_EXPORT CodedInputStream { // current_limit_. Set using SetTotalBytesLimit(). int total_bytes_limit_; - // If positive/0: Limit for bytes read after which a warning due to size - // should be logged. - // If -1: Printing of warning disabled. Can be set by client. - // If -2: Internal: Limit has been reached, print full size when destructing. - int total_bytes_warning_threshold_; - // Current recursion budget, controlled by IncrementRecursionDepth() and // similar. Starts at recursion_limit_ and goes down: if this reaches // -1 we are over budget. @@ -581,6 +576,8 @@ class LIBPROTOBUF_EXPORT CodedInputStream { // Recursion depth limit, set by SetRecursionLimit(). int recursion_limit_; + bool disable_strict_correctness_enforcement_; + // See SetExtensionRegistry(). const DescriptorPool* extension_pool_; MessageFactory* extension_factory_; @@ -642,8 +639,6 @@ class LIBPROTOBUF_EXPORT CodedInputStream { static const int kDefaultTotalBytesLimit = INT_MAX; - static const int kDefaultTotalBytesWarningThreshold = 32 << 20; // 32MB - static int default_recursion_limit_; // 100 by default. }; @@ -870,7 +865,7 @@ class LIBPROTOBUF_EXPORT CodedOutputStream { } static bool IsDefaultSerializationDeterministic() { - return default_serialization_deterministic_; + return google::protobuf::internal::Acquire_Load(&default_serialization_deterministic_); } private: @@ -885,7 +880,8 @@ class LIBPROTOBUF_EXPORT CodedOutputStream { // See SetSerializationDeterministic() regarding these three fields. bool serialization_deterministic_is_overridden_; bool serialization_deterministic_override_; - static bool default_serialization_deterministic_; + // Conceptually, default_serialization_deterministic_ is an atomic bool. + static google::protobuf::internal::AtomicWord default_serialization_deterministic_; // Advance the buffer by a given number of bytes. void Advance(int amount); @@ -904,10 +900,15 @@ class LIBPROTOBUF_EXPORT CodedOutputStream { void WriteVarint64SlowPath(uint64 value); // See above. Other projects may use "friend" to allow them to call this. - // Requires: no protocol buffer serialization in progress. + // After SetDefaultSerializationDeterministic() completes, all protocol + // buffer serializations will be deterministic by default. Thread safe. + // However, the meaning of "after" is subtle here: to be safe, each thread + // that wants deterministic serialization by default needs to call + // SetDefaultSerializationDeterministic() or ensure on its own that another + // thread has done so. friend void ::google::protobuf::internal::MapTestForceDeterministic(); static void SetDefaultSerializationDeterministic() { - default_serialization_deterministic_ = true; + google::protobuf::internal::Release_Store(&default_serialization_deterministic_, 1); } }; @@ -1395,9 +1396,9 @@ inline CodedInputStream::CodedInputStream(ZeroCopyInputStream* input) current_limit_(kint32max), buffer_size_after_limit_(0), total_bytes_limit_(kDefaultTotalBytesLimit), - total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold), recursion_budget_(default_recursion_limit_), recursion_limit_(default_recursion_limit_), + disable_strict_correctness_enforcement_(true), extension_pool_(NULL), extension_factory_(NULL) { // Eagerly Refresh() so buffer space is immediately available. @@ -1416,9 +1417,9 @@ inline CodedInputStream::CodedInputStream(const uint8* buffer, int size) current_limit_(size), buffer_size_after_limit_(0), total_bytes_limit_(kDefaultTotalBytesLimit), - total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold), recursion_budget_(default_recursion_limit_), recursion_limit_(default_recursion_limit_), + disable_strict_correctness_enforcement_(true), extension_pool_(NULL), extension_factory_(NULL) { // Note that setting current_limit_ == size is important to prevent some diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/io/coded_stream_unittest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/io/coded_stream_unittest.cc index 31574d5be3..96f91ae91c 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/io/coded_stream_unittest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/io/coded_stream_unittest.cc @@ -63,6 +63,7 @@ namespace protobuf { namespace io { namespace { + // =================================================================== // Data-Driven Test Infrastructure @@ -1296,35 +1297,6 @@ void CodedStreamTest::SetupTotalBytesLimitWarningTest( *out_warnings = scoped_log.GetMessages(WARNING); } -TEST_F(CodedStreamTest, TotalBytesLimitWarning) { - std::vector errors; - std::vector warnings; - SetupTotalBytesLimitWarningTest(10240, 1024, &errors, &warnings); - - EXPECT_EQ(0, errors.size()); - - EXPECT_EQ(1, warnings.size()); - EXPECT_PRED_FORMAT2(testing::IsSubstring, - "The total number of bytes read was 2048", - warnings[0]); -} - -TEST_F(CodedStreamTest, TotalBytesLimitWarningDisabled) { - std::vector errors; - std::vector warnings; - - // Test with -1 - SetupTotalBytesLimitWarningTest(10240, -1, &errors, &warnings); - EXPECT_EQ(0, errors.size()); - EXPECT_EQ(0, warnings.size()); - - // Test again with -2, expecting the same result - SetupTotalBytesLimitWarningTest(10240, -2, &errors, &warnings); - EXPECT_EQ(0, errors.size()); - EXPECT_EQ(0, warnings.size()); -} - - TEST_F(CodedStreamTest, RecursionLimit) { ArrayInputStream input(buffer_, sizeof(buffer_)); CodedInputStream coded_input(&input); @@ -1425,9 +1397,6 @@ TEST_F(CodedStreamTest, InputOver2G) { EXPECT_EQ(0, errors.size()); } -// =================================================================== - - } // namespace } // namespace io } // namespace protobuf diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/io/gzip_stream.h b/third_party/protobuf/3.2.0/src/google/protobuf/io/gzip_stream.h index df1a446ebc..15b02fe3d7 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/io/gzip_stream.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/io/gzip_stream.h @@ -118,7 +118,7 @@ class LIBPROTOBUF_EXPORT GzipOutputStream : public ZeroCopyOutputStream { ZLIB = 2, }; - struct LIBPROTOBUF_EXPORT Options { + struct Options { // Defaults to GZIP. Format format; diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/io/zero_copy_stream_impl.cc b/third_party/protobuf/3.2.0/src/google/protobuf/io/zero_copy_stream_impl.cc index 3ab5224a64..02619d7bed 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/io/zero_copy_stream_impl.cc +++ b/third_party/protobuf/3.2.0/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 -#else +#ifndef _MSC_VER #include #include #include @@ -43,7 +41,6 @@ #include #include #include - #include #include #include @@ -59,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 , instead create functions in io_win32.{h,cc} and import +// them like we do below. +using google::protobuf::stubs::access; +using google::protobuf::stubs::close; +using google::protobuf::stubs::open; +using google::protobuf::stubs::read; +using google::protobuf::stubs::write; #endif namespace { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/io/zero_copy_stream_impl_lite.h b/third_party/protobuf/3.2.0/src/google/protobuf/io/zero_copy_stream_impl_lite.h index e4d6a024dd..6db1d69595 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/io/zero_copy_stream_impl_lite.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/io/zero_copy_stream_impl_lite.h @@ -399,7 +399,7 @@ inline std::pair as_string_data(string* s) { #ifdef LANG_CXX11 return std::make_pair(p, true); #else - return make_pair(p, p != NULL); + return std::make_pair(p, p != NULL); #endif } diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/io/zero_copy_stream_unittest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/io/zero_copy_stream_unittest.cc index a83e2b738e..5904b0d9ed 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/io/zero_copy_stream_unittest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/io/zero_copy_stream_unittest.cc @@ -47,9 +47,7 @@ // implementations. -#ifdef _MSC_VER -#include -#else +#ifndef _MSC_VER #include #endif #include @@ -85,6 +83,12 @@ namespace { #ifdef _WIN32 #define pipe(fds) _pipe(fds, 4096, O_BINARY) +// DO NOT include , instead create functions in io_win32.{h,cc} and import +// them like we do below. +using google::protobuf::stubs::access; +using google::protobuf::stubs::mkdir; +using google::protobuf::stubs::open; +using google::protobuf::stubs::close; #endif #ifndef O_BINARY diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/lite_unittest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/lite_unittest.cc index 3ca3fbaf6e..2f5268af15 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/lite_unittest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/lite_unittest.cc @@ -36,24 +36,24 @@ #include #include #include -#include #include +#include #include #include #include #include #include #include -#include +#include -using namespace std; +#include namespace { // Helper methods to test parsing merge behavior. void ExpectMessageMerged(const google::protobuf::unittest::TestAllTypesLite& message) { - GOOGLE_CHECK(message.optional_int32() == 3); - GOOGLE_CHECK(message.optional_int64() == 2); - GOOGLE_CHECK(message.optional_string() == "hello"); + EXPECT_EQ(message.optional_int32(), 3); + EXPECT_EQ(message.optional_int64(), 2); + EXPECT_EQ(message.optional_string(), "hello"); } void AssignParsingMergeMessages( @@ -71,7 +71,7 @@ void SetAllTypesInEmptyMessageUnknownFields( protobuf_unittest::TestAllTypesLite message; google::protobuf::TestUtilLite::ExpectClear(message); google::protobuf::TestUtilLite::SetAllFields(&message); - string data = message.SerializeAsString(); + std::string data = message.SerializeAsString(); empty_message->ParseFromString(data); } @@ -83,20 +83,14 @@ void SetSomeTypesInEmptyMessageUnknownFields( message.set_optional_int64(102); message.set_optional_uint32(103); message.set_optional_uint64(104); - string data = message.SerializeAsString(); + std::string data = message.SerializeAsString(); empty_message->ParseFromString(data); } } // namespace -#define EXPECT_TRUE GOOGLE_CHECK -#define ASSERT_TRUE GOOGLE_CHECK -#define EXPECT_FALSE(COND) GOOGLE_CHECK(!(COND)) -#define EXPECT_EQ GOOGLE_CHECK_EQ -#define ASSERT_EQ GOOGLE_CHECK_EQ - -int main(int argc, char* argv[]) { - string data, data2, packed_data; +TEST(Lite, AllLite1) { + std::string data; { protobuf_unittest::TestAllTypesLite message, message2, message3; @@ -113,13 +107,16 @@ int main(int argc, char* argv[]) { message.Clear(); google::protobuf::TestUtilLite::ExpectClear(message); } +} +TEST(Lite, AllLite2) { + std::string data; { protobuf_unittest::TestAllExtensionsLite message, message2, message3; google::protobuf::TestUtilLite::ExpectExtensionsClear(message); google::protobuf::TestUtilLite::SetAllExtensions(&message); message2.CopyFrom(message); - string extensions_data = message.SerializeAsString(); + std::string extensions_data = message.SerializeAsString(); message3.ParseFromString(extensions_data); google::protobuf::TestUtilLite::ExpectAllExtensionsSet(message); google::protobuf::TestUtilLite::ExpectAllExtensionsSet(message2); @@ -129,6 +126,10 @@ int main(int argc, char* argv[]) { message.Clear(); google::protobuf::TestUtilLite::ExpectExtensionsClear(message); } +} + +TEST(Lite, AllLite3) { + std::string data, packed_data; { protobuf_unittest::TestPackedTypesLite message, message2, message3; @@ -151,8 +152,8 @@ int main(int argc, char* argv[]) { google::protobuf::TestUtilLite::ExpectPackedExtensionsClear(message); google::protobuf::TestUtilLite::SetPackedExtensions(&message); message2.CopyFrom(message); - string packed_extensions_data = message.SerializeAsString(); - GOOGLE_CHECK(packed_extensions_data == packed_data); + std::string packed_extensions_data = message.SerializeAsString(); + EXPECT_EQ(packed_extensions_data, packed_data); message3.ParseFromString(packed_extensions_data); google::protobuf::TestUtilLite::ExpectPackedExtensionsSet(message); google::protobuf::TestUtilLite::ExpectPackedExtensionsSet(message2); @@ -162,6 +163,10 @@ int main(int argc, char* argv[]) { message.Clear(); google::protobuf::TestUtilLite::ExpectPackedExtensionsClear(message); } +} + +TEST(Lite, AllLite5) { + std::string data; { // Test that if an optional or required message/group field appears multiple @@ -195,7 +200,7 @@ int main(int argc, char* argv[]) { #undef ASSIGN_REPEATED_GROUP - string buffer; + std::string buffer; generator.SerializeToString(&buffer); google::protobuf::unittest::TestParsingMergeLite parsing_merge; parsing_merge.ParseFromString(buffer); @@ -209,11 +214,16 @@ int main(int argc, char* argv[]) { google::protobuf::unittest::TestParsingMergeLite::optional_ext)); // Repeated fields should not be merged. - GOOGLE_CHECK(parsing_merge.repeated_all_types_size() == 3); - GOOGLE_CHECK(parsing_merge.repeatedgroup_size() == 3); - GOOGLE_CHECK(parsing_merge.ExtensionSize( - google::protobuf::unittest::TestParsingMergeLite::repeated_ext) == 3); + EXPECT_EQ(parsing_merge.repeated_all_types_size(), 3); + EXPECT_EQ(parsing_merge.repeatedgroup_size(), 3); + EXPECT_EQ(parsing_merge.ExtensionSize( + google::protobuf::unittest::TestParsingMergeLite::repeated_ext), + 3); } +} + +TEST(Lite, AllLite6) { + std::string data; // Test unknown fields support for lite messages. { @@ -231,6 +241,10 @@ int main(int argc, char* argv[]) { message.Clear(); google::protobuf::TestUtilLite::ExpectClear(message); } +} + +TEST(Lite, AllLite7) { + std::string data; { protobuf_unittest::TestAllExtensionsLite message, message2; @@ -247,6 +261,10 @@ int main(int argc, char* argv[]) { message.Clear(); google::protobuf::TestUtilLite::ExpectExtensionsClear(message); } +} + +TEST(Lite, AllLite8) { + std::string data; { protobuf_unittest::TestPackedTypesLite message, message2; @@ -263,6 +281,10 @@ int main(int argc, char* argv[]) { message.Clear(); google::protobuf::TestUtilLite::ExpectPackedClear(message); } +} + +TEST(Lite, AllLite9) { + std::string data; { protobuf_unittest::TestPackedExtensionsLite message, message2; @@ -279,6 +301,10 @@ int main(int argc, char* argv[]) { message.Clear(); google::protobuf::TestUtilLite::ExpectPackedExtensionsClear(message); } +} + +TEST(Lite, AllLite10) { + std::string data; { // Test Unknown fields swap @@ -286,11 +312,15 @@ int main(int argc, char* argv[]) { SetAllTypesInEmptyMessageUnknownFields(&empty_message); SetSomeTypesInEmptyMessageUnknownFields(&empty_message2); data = empty_message.SerializeAsString(); - data2 = empty_message2.SerializeAsString(); + std::string data2 = empty_message2.SerializeAsString(); empty_message.Swap(&empty_message2); - GOOGLE_CHECK_EQ(data, empty_message2.SerializeAsString()); - GOOGLE_CHECK_EQ(data2, empty_message.SerializeAsString()); + EXPECT_EQ(data, empty_message2.SerializeAsString()); + EXPECT_EQ(data2, empty_message.SerializeAsString()); } +} + +TEST(Lite, AllLite11) { + std::string data; { // Test unknown fields swap with self @@ -298,8 +328,12 @@ int main(int argc, char* argv[]) { SetAllTypesInEmptyMessageUnknownFields(&empty_message); data = empty_message.SerializeAsString(); empty_message.Swap(&empty_message); - GOOGLE_CHECK_EQ(data, empty_message.SerializeAsString()); + EXPECT_EQ(data, empty_message.SerializeAsString()); } +} + +TEST(Lite, AllLite12) { + std::string data; { // Test MergeFrom with unknown fields @@ -324,13 +358,17 @@ int main(int argc, char* argv[]) { // We do not compare the serialized output of a normal message and a lite // message because the order of fields do not match. We convert lite message // back into normal message, then compare. - GOOGLE_CHECK_EQ(message.SerializeAsString(), message2.SerializeAsString()); + EXPECT_EQ(message.SerializeAsString(), message2.SerializeAsString()); } +} + +TEST(Lite, AllLite13) { + std::string data; { // Test unknown enum value protobuf_unittest::TestAllTypesLite message; - string buffer; + std::string buffer; { google::protobuf::io::StringOutputStream output_stream(&buffer); google::protobuf::io::CodedOutputStream coded_output(&output_stream); @@ -345,18 +383,26 @@ int main(int argc, char* argv[]) { } message.ParseFromString(buffer); data = message.SerializeAsString(); - GOOGLE_CHECK_EQ(data, buffer); + EXPECT_EQ(data, buffer); } +} + +TEST(Lite, AllLite14) { + std::string data; { // Test Clear with unknown fields protobuf_unittest::TestEmptyMessageLite empty_message; SetAllTypesInEmptyMessageUnknownFields(&empty_message); empty_message.Clear(); - GOOGLE_CHECK_EQ(0, empty_message.unknown_fields().size()); + EXPECT_EQ(0, empty_message.unknown_fields().size()); } +} + +// Tests for map lite ============================================= - // Tests for map lite ============================================= +TEST(Lite, AllLite15) { + std::string data; { // Accessors @@ -368,6 +414,10 @@ int main(int argc, char* argv[]) { google::protobuf::MapLiteTestUtil::ModifyMapFields(&message); google::protobuf::MapLiteTestUtil::ExpectMapFieldsModified(message); } +} + +TEST(Lite, AllLite16) { + std::string data; { // SetMapFieldsInitialized @@ -376,6 +426,10 @@ int main(int argc, char* argv[]) { google::protobuf::MapLiteTestUtil::SetMapFieldsInitialized(&message); google::protobuf::MapLiteTestUtil::ExpectMapFieldsSetInitialized(message); } +} + +TEST(Lite, AllLite17) { + std::string data; { // Clear @@ -385,6 +439,10 @@ int main(int argc, char* argv[]) { message.Clear(); google::protobuf::MapLiteTestUtil::ExpectClear(message); } +} + +TEST(Lite, AllLite18) { + std::string data; { // ClearMessageMap @@ -394,6 +452,10 @@ int main(int argc, char* argv[]) { google::protobuf::TestUtilLite::ExpectClear( (*message.mutable_map_int32_message())[0]); } +} + +TEST(Lite, AllLite19) { + std::string data; { // CopyFrom @@ -407,6 +469,10 @@ int main(int argc, char* argv[]) { message2.CopyFrom(message2); google::protobuf::MapLiteTestUtil::ExpectMapFieldsSet(message2); } +} + +TEST(Lite, AllLite20) { + std::string data; { // CopyFromMessageMap @@ -421,6 +487,10 @@ int main(int argc, char* argv[]) { EXPECT_EQ(1, message1.map_int32_message().at(0).repeated_int32_size()); EXPECT_EQ(101, message1.map_int32_message().at(0).repeated_int32(0)); } +} + +TEST(Lite, AllLite21) { + std::string data; { // SwapWithEmpty @@ -434,6 +504,10 @@ int main(int argc, char* argv[]) { google::protobuf::MapLiteTestUtil::ExpectMapFieldsSet(message2); google::protobuf::MapLiteTestUtil::ExpectClear(message1); } +} + +TEST(Lite, AllLite22) { + std::string data; { // SwapWithSelf @@ -445,6 +519,10 @@ int main(int argc, char* argv[]) { message.Swap(&message); google::protobuf::MapLiteTestUtil::ExpectMapFieldsSet(message); } +} + +TEST(Lite, AllLite23) { + std::string data; { // SwapWithOther @@ -458,6 +536,10 @@ int main(int argc, char* argv[]) { google::protobuf::MapLiteTestUtil::ExpectMapFieldsModified(message1); google::protobuf::MapLiteTestUtil::ExpectMapFieldsSet(message2); } +} + +TEST(Lite, AllLite24) { + std::string data; { // CopyConstructor @@ -467,6 +549,10 @@ int main(int argc, char* argv[]) { protobuf_unittest::TestMapLite message2(message1); google::protobuf::MapLiteTestUtil::ExpectMapFieldsSet(message2); } +} + +TEST(Lite, AllLite25) { + std::string data; { // CopyAssignmentOperator @@ -481,6 +567,10 @@ int main(int argc, char* argv[]) { message2.operator=(message2); google::protobuf::MapLiteTestUtil::ExpectMapFieldsSet(message2); } +} + +TEST(Lite, AllLite26) { + std::string data; { // NonEmptyMergeFrom @@ -499,6 +589,10 @@ int main(int argc, char* argv[]) { message1.MergeFrom(message2); google::protobuf::MapLiteTestUtil::ExpectMapFieldsSet(message1); } +} + +TEST(Lite, AllLite27) { + std::string data; { // MergeFromMessageMap @@ -513,11 +607,15 @@ int main(int argc, char* argv[]) { EXPECT_EQ(1, message1.map_int32_message().at(0).repeated_int32_size()); EXPECT_EQ(101, message1.map_int32_message().at(0).repeated_int32(0)); } +} + +TEST(Lite, AllLite28) { + std::string data; { // Test the generated SerializeWithCachedSizesToArray() protobuf_unittest::TestMapLite message1, message2; - string data; + std::string data; google::protobuf::MapLiteTestUtil::SetMapFields(&message1); int size = message1.ByteSize(); data.resize(size); @@ -527,13 +625,17 @@ int main(int argc, char* argv[]) { EXPECT_TRUE(message2.ParseFromString(data)); google::protobuf::MapLiteTestUtil::ExpectMapFieldsSet(message2); } +} + +TEST(Lite, AllLite29) { + std::string data; { // Test the generated SerializeWithCachedSizes() protobuf_unittest::TestMapLite message1, message2; google::protobuf::MapLiteTestUtil::SetMapFields(&message1); int size = message1.ByteSize(); - string data; + std::string data; data.resize(size); { // Allow the output stream to buffer only one byte at a time. @@ -547,7 +649,11 @@ int main(int argc, char* argv[]) { EXPECT_TRUE(message2.ParseFromString(data)); google::protobuf::MapLiteTestUtil::ExpectMapFieldsSet(message2); } +} + +TEST(Lite, AllLite32) { + std::string data; { // Proto2UnknownEnum @@ -556,7 +662,7 @@ int main(int argc, char* argv[]) { protobuf_unittest::E_PROTO2_MAP_ENUM_FOO_LITE; (*from.mutable_unknown_map_field())[0] = protobuf_unittest::E_PROTO2_MAP_ENUM_EXTRA_LITE; - string data; + std::string data; from.SerializeToString(&data); protobuf_unittest::TestEnumMapLite to; @@ -578,98 +684,134 @@ int main(int argc, char* argv[]) { EXPECT_EQ(protobuf_unittest::E_PROTO2_MAP_ENUM_EXTRA_LITE, from.unknown_map_field().at(0)); } +} + +TEST(Lite, AllLite33) { + std::string data; { // StandardWireFormat protobuf_unittest::TestMapLite message; - string data = "\x0A\x04\x08\x01\x10\x01"; + std::string data = "\x0A\x04\x08\x01\x10\x01"; EXPECT_TRUE(message.ParseFromString(data)); EXPECT_EQ(1, message.map_int32_int32().size()); EXPECT_EQ(1, message.map_int32_int32().at(1)); } +} + +TEST(Lite, AllLite34) { + std::string data; { // UnorderedWireFormat protobuf_unittest::TestMapLite message; // put value before key in wire format - string data = "\x0A\x04\x10\x01\x08\x02"; + std::string data = "\x0A\x04\x10\x01\x08\x02"; EXPECT_TRUE(message.ParseFromString(data)); EXPECT_EQ(1, message.map_int32_int32().size()); EXPECT_EQ(1, message.map_int32_int32().at(2)); } +} + +TEST(Lite, AllLite35) { + std::string data; { // DuplicatedKeyWireFormat protobuf_unittest::TestMapLite message; // Two key fields in wire format - string data = "\x0A\x06\x08\x01\x08\x02\x10\x01"; + std::string data = "\x0A\x06\x08\x01\x08\x02\x10\x01"; EXPECT_TRUE(message.ParseFromString(data)); EXPECT_EQ(1, message.map_int32_int32().size()); EXPECT_EQ(1, message.map_int32_int32().at(2)); } +} + +TEST(Lite, AllLite36) { + std::string data; { // DuplicatedValueWireFormat protobuf_unittest::TestMapLite message; // Two value fields in wire format - string data = "\x0A\x06\x08\x01\x10\x01\x10\x02"; + std::string data = "\x0A\x06\x08\x01\x10\x01\x10\x02"; EXPECT_TRUE(message.ParseFromString(data)); EXPECT_EQ(1, message.map_int32_int32().size()); EXPECT_EQ(2, message.map_int32_int32().at(1)); } +} + +TEST(Lite, AllLite37) { + std::string data; { // MissedKeyWireFormat protobuf_unittest::TestMapLite message; // No key field in wire format - string data = "\x0A\x02\x10\x01"; + std::string data = "\x0A\x02\x10\x01"; EXPECT_TRUE(message.ParseFromString(data)); EXPECT_EQ(1, message.map_int32_int32().size()); EXPECT_EQ(1, message.map_int32_int32().at(0)); } +} + +TEST(Lite, AllLite38) { + std::string data; { // MissedValueWireFormat protobuf_unittest::TestMapLite message; // No value field in wire format - string data = "\x0A\x02\x08\x01"; + std::string data = "\x0A\x02\x08\x01"; EXPECT_TRUE(message.ParseFromString(data)); EXPECT_EQ(1, message.map_int32_int32().size()); EXPECT_EQ(0, message.map_int32_int32().at(1)); } +} + +TEST(Lite, AllLite39) { + std::string data; { // UnknownFieldWireFormat protobuf_unittest::TestMapLite message; // Unknown field in wire format - string data = "\x0A\x06\x08\x02\x10\x03\x18\x01"; + std::string data = "\x0A\x06\x08\x02\x10\x03\x18\x01"; EXPECT_TRUE(message.ParseFromString(data)); EXPECT_EQ(1, message.map_int32_int32().size()); EXPECT_EQ(3, message.map_int32_int32().at(2)); } +} + +TEST(Lite, AllLite40) { + std::string data; { // CorruptedWireFormat protobuf_unittest::TestMapLite message; // corrupted data in wire format - string data = "\x0A\x06\x08\x02\x11\x03"; + std::string data = "\x0A\x06\x08\x02\x11\x03"; EXPECT_FALSE(message.ParseFromString(data)); } +} + +TEST(Lite, AllLite41) { + std::string data; { // IsInitialized @@ -685,6 +827,10 @@ int main(int argc, char* argv[]) { (*map_message.mutable_map_field())[0].set_c(0); EXPECT_TRUE(map_message.IsInitialized()); } +} + +TEST(Lite, AllLite42) { + std::string data; { // Check that adding more values to enum does not corrupt message @@ -693,7 +839,7 @@ int main(int argc, char* argv[]) { v2_message.set_int_field(800); // Set enum field to the value not understood by the old client. v2_message.set_enum_field(protobuf_unittest::V2_SECOND); - string v2_bytes = v2_message.SerializeAsString(); + std::string v2_bytes = v2_message.SerializeAsString(); protobuf_unittest::V1MessageLite v1_message; v1_message.ParseFromString(v2_bytes); @@ -704,7 +850,7 @@ int main(int argc, char* argv[]) { EXPECT_EQ(v1_message.enum_field(), protobuf_unittest::V1_FIRST); // However, when re-serialized, it should preserve enum value. - string v1_bytes = v1_message.SerializeAsString(); + std::string v1_bytes = v1_message.SerializeAsString(); protobuf_unittest::V2MessageLite same_v2_message; same_v2_message.ParseFromString(v1_bytes); @@ -714,5 +860,4 @@ int main(int argc, char* argv[]) { } std::cout << "PASS" << std::endl; - return 0; } diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/map.h b/third_party/protobuf/3.2.0/src/google/protobuf/map.h index e6d78b2069..18ee365276 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/map.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/map.h @@ -37,7 +37,6 @@ #ifndef GOOGLE_PROTOBUF_MAP_H__ #define GOOGLE_PROTOBUF_MAP_H__ -#include #include #include // To support Visual Studio 2008 #include @@ -47,8 +46,7 @@ #include #include #include -#include -#include +#include #if __cpp_exceptions && LANG_CXX11 #include #endif @@ -64,16 +62,14 @@ class MapIterator; template struct is_proto_enum; namespace internal { -template + WireFormatLite::FieldType value_wire_type, int default_enum_value> class MapFieldLite; -template + WireFormatLite::FieldType value_wire_type, int default_enum_value> class MapField; template @@ -84,389 +80,6 @@ class DynamicMapField; class GeneratedMessageReflection; } // namespace internal -#define TYPE_CHECK(EXPECTEDTYPE, METHOD) \ - if (type() != EXPECTEDTYPE) { \ - GOOGLE_LOG(FATAL) \ - << "Protocol Buffer map usage error:\n" \ - << METHOD << " type does not match\n" \ - << " Expected : " \ - << FieldDescriptor::CppTypeName(EXPECTEDTYPE) << "\n" \ - << " Actual : " \ - << FieldDescriptor::CppTypeName(type()); \ - } - -// MapKey is an union type for representing any possible -// map key. -class LIBPROTOBUF_EXPORT MapKey { - public: - MapKey() : type_(0) { - } - MapKey(const MapKey& other) : type_(0) { - CopyFrom(other); - } - - ~MapKey() { - if (type_ == FieldDescriptor::CPPTYPE_STRING) { - delete val_.string_value_; - } - } - - FieldDescriptor::CppType type() const { - if (type_ == 0) { - GOOGLE_LOG(FATAL) - << "Protocol Buffer map usage error:\n" - << "MapKey::type MapKey is not initialized. " - << "Call set methods to initialize MapKey."; - } - return (FieldDescriptor::CppType)type_; - } - - void SetInt64Value(int64 value) { - SetType(FieldDescriptor::CPPTYPE_INT64); - val_.int64_value_ = value; - } - void SetUInt64Value(uint64 value) { - SetType(FieldDescriptor::CPPTYPE_UINT64); - val_.uint64_value_ = value; - } - void SetInt32Value(int32 value) { - SetType(FieldDescriptor::CPPTYPE_INT32); - val_.int32_value_ = value; - } - void SetUInt32Value(uint32 value) { - SetType(FieldDescriptor::CPPTYPE_UINT32); - val_.uint32_value_ = value; - } - void SetBoolValue(bool value) { - SetType(FieldDescriptor::CPPTYPE_BOOL); - val_.bool_value_ = value; - } - void SetStringValue(const string& val) { - SetType(FieldDescriptor::CPPTYPE_STRING); - *val_.string_value_ = val; - } - - int64 GetInt64Value() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_INT64, - "MapKey::GetInt64Value"); - return val_.int64_value_; - } - uint64 GetUInt64Value() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT64, - "MapKey::GetUInt64Value"); - return val_.uint64_value_; - } - int32 GetInt32Value() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_INT32, - "MapKey::GetInt32Value"); - return val_.int32_value_; - } - uint32 GetUInt32Value() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT32, - "MapKey::GetUInt32Value"); - return val_.uint32_value_; - } - bool GetBoolValue() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_BOOL, - "MapKey::GetBoolValue"); - return val_.bool_value_; - } - const string& GetStringValue() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_STRING, - "MapKey::GetStringValue"); - return *val_.string_value_; - } - - bool operator<(const MapKey& other) const { - if (type_ != other.type_) { - // We could define a total order that handles this case, but - // there currently no need. So, for now, fail. - GOOGLE_LOG(FATAL) << "Unsupported: type mismatch"; - } - switch (type()) { - case FieldDescriptor::CPPTYPE_DOUBLE: - case FieldDescriptor::CPPTYPE_FLOAT: - case FieldDescriptor::CPPTYPE_ENUM: - case FieldDescriptor::CPPTYPE_MESSAGE: - GOOGLE_LOG(FATAL) << "Unsupported"; - return false; - case FieldDescriptor::CPPTYPE_STRING: - return *val_.string_value_ < *other.val_.string_value_; - case FieldDescriptor::CPPTYPE_INT64: - return val_.int64_value_ < other.val_.int64_value_; - case FieldDescriptor::CPPTYPE_INT32: - return val_.int32_value_ < other.val_.int32_value_; - case FieldDescriptor::CPPTYPE_UINT64: - return val_.uint64_value_ < other.val_.uint64_value_; - case FieldDescriptor::CPPTYPE_UINT32: - return val_.uint32_value_ < other.val_.uint32_value_; - case FieldDescriptor::CPPTYPE_BOOL: - return val_.bool_value_ < other.val_.bool_value_; - } - return false; - } - - bool operator==(const MapKey& other) const { - if (type_ != other.type_) { - // To be consistent with operator<, we don't allow this either. - GOOGLE_LOG(FATAL) << "Unsupported: type mismatch"; - } - switch (type()) { - case FieldDescriptor::CPPTYPE_DOUBLE: - case FieldDescriptor::CPPTYPE_FLOAT: - case FieldDescriptor::CPPTYPE_ENUM: - case FieldDescriptor::CPPTYPE_MESSAGE: - GOOGLE_LOG(FATAL) << "Unsupported"; - break; - case FieldDescriptor::CPPTYPE_STRING: - return *val_.string_value_ == *other.val_.string_value_; - case FieldDescriptor::CPPTYPE_INT64: - return val_.int64_value_ == other.val_.int64_value_; - case FieldDescriptor::CPPTYPE_INT32: - return val_.int32_value_ == other.val_.int32_value_; - case FieldDescriptor::CPPTYPE_UINT64: - return val_.uint64_value_ == other.val_.uint64_value_; - case FieldDescriptor::CPPTYPE_UINT32: - return val_.uint32_value_ == other.val_.uint32_value_; - case FieldDescriptor::CPPTYPE_BOOL: - return val_.bool_value_ == other.val_.bool_value_; - } - GOOGLE_LOG(FATAL) << "Can't get here."; - return false; - } - - void CopyFrom(const MapKey& other) { - SetType(other.type()); - switch (type_) { - case FieldDescriptor::CPPTYPE_DOUBLE: - case FieldDescriptor::CPPTYPE_FLOAT: - case FieldDescriptor::CPPTYPE_ENUM: - case FieldDescriptor::CPPTYPE_MESSAGE: - GOOGLE_LOG(FATAL) << "Unsupported"; - break; - case FieldDescriptor::CPPTYPE_STRING: - *val_.string_value_ = *other.val_.string_value_; - break; - case FieldDescriptor::CPPTYPE_INT64: - val_.int64_value_ = other.val_.int64_value_; - break; - case FieldDescriptor::CPPTYPE_INT32: - val_.int32_value_ = other.val_.int32_value_; - break; - case FieldDescriptor::CPPTYPE_UINT64: - val_.uint64_value_ = other.val_.uint64_value_; - break; - case FieldDescriptor::CPPTYPE_UINT32: - val_.uint32_value_ = other.val_.uint32_value_; - break; - case FieldDescriptor::CPPTYPE_BOOL: - val_.bool_value_ = other.val_.bool_value_; - break; - } - } - - private: - template - friend class internal::TypeDefinedMapFieldBase; - friend class MapIterator; - friend class internal::DynamicMapField; - - union KeyValue { - KeyValue() {} - string* string_value_; - int64 int64_value_; - int32 int32_value_; - uint64 uint64_value_; - uint32 uint32_value_; - bool bool_value_; - } val_; - - void SetType(FieldDescriptor::CppType type) { - if (type_ == type) return; - if (type_ == FieldDescriptor::CPPTYPE_STRING) { - delete val_.string_value_; - } - type_ = type; - if (type_ == FieldDescriptor::CPPTYPE_STRING) { - val_.string_value_ = new string; - } - } - - // type_ is 0 or a valid FieldDescriptor::CppType. - int type_; -}; - -// MapValueRef points to a map value. -class LIBPROTOBUF_EXPORT MapValueRef { - public: - MapValueRef() : data_(NULL), type_(0) {} - - void SetInt64Value(int64 value) { - TYPE_CHECK(FieldDescriptor::CPPTYPE_INT64, - "MapValueRef::SetInt64Value"); - *reinterpret_cast(data_) = value; - } - void SetUInt64Value(uint64 value) { - TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT64, - "MapValueRef::SetUInt64Value"); - *reinterpret_cast(data_) = value; - } - void SetInt32Value(int32 value) { - TYPE_CHECK(FieldDescriptor::CPPTYPE_INT32, - "MapValueRef::SetInt32Value"); - *reinterpret_cast(data_) = value; - } - void SetUInt32Value(uint32 value) { - TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT32, - "MapValueRef::SetUInt32Value"); - *reinterpret_cast(data_) = value; - } - void SetBoolValue(bool value) { - TYPE_CHECK(FieldDescriptor::CPPTYPE_BOOL, - "MapValueRef::SetBoolValue"); - *reinterpret_cast(data_) = value; - } - // TODO(jieluo) - Checks that enum is member. - void SetEnumValue(int value) { - TYPE_CHECK(FieldDescriptor::CPPTYPE_ENUM, - "MapValueRef::SetEnumValue"); - *reinterpret_cast(data_) = value; - } - void SetStringValue(const string& value) { - TYPE_CHECK(FieldDescriptor::CPPTYPE_STRING, - "MapValueRef::SetStringValue"); - *reinterpret_cast(data_) = value; - } - void SetFloatValue(float value) { - TYPE_CHECK(FieldDescriptor::CPPTYPE_FLOAT, - "MapValueRef::SetFloatValue"); - *reinterpret_cast(data_) = value; - } - void SetDoubleValue(double value) { - TYPE_CHECK(FieldDescriptor::CPPTYPE_DOUBLE, - "MapValueRef::SetDoubleValue"); - *reinterpret_cast(data_) = value; - } - - int64 GetInt64Value() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_INT64, - "MapValueRef::GetInt64Value"); - return *reinterpret_cast(data_); - } - uint64 GetUInt64Value() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT64, - "MapValueRef::GetUInt64Value"); - return *reinterpret_cast(data_); - } - int32 GetInt32Value() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_INT32, - "MapValueRef::GetInt32Value"); - return *reinterpret_cast(data_); - } - uint32 GetUInt32Value() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT32, - "MapValueRef::GetUInt32Value"); - return *reinterpret_cast(data_); - } - bool GetBoolValue() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_BOOL, - "MapValueRef::GetBoolValue"); - return *reinterpret_cast(data_); - } - int GetEnumValue() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_ENUM, - "MapValueRef::GetEnumValue"); - return *reinterpret_cast(data_); - } - const string& GetStringValue() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_STRING, - "MapValueRef::GetStringValue"); - return *reinterpret_cast(data_); - } - float GetFloatValue() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_FLOAT, - "MapValueRef::GetFloatValue"); - return *reinterpret_cast(data_); - } - double GetDoubleValue() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_DOUBLE, - "MapValueRef::GetDoubleValue"); - return *reinterpret_cast(data_); - } - - const Message& GetMessageValue() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_MESSAGE, - "MapValueRef::GetMessageValue"); - return *reinterpret_cast(data_); - } - - Message* MutableMessageValue() { - TYPE_CHECK(FieldDescriptor::CPPTYPE_MESSAGE, - "MapValueRef::MutableMessageValue"); - return reinterpret_cast(data_); - } - - private: - template - friend class internal::MapField; - template - friend class internal::TypeDefinedMapFieldBase; - friend class MapIterator; - friend class internal::GeneratedMessageReflection; - friend class internal::DynamicMapField; - - void SetType(FieldDescriptor::CppType type) { - type_ = type; - } - - FieldDescriptor::CppType type() const { - if (type_ == 0 || data_ == NULL) { - GOOGLE_LOG(FATAL) - << "Protocol Buffer map usage error:\n" - << "MapValueRef::type MapValueRef is not initialized."; - } - return (FieldDescriptor::CppType)type_; - } - void SetValue(const void* val) { - data_ = const_cast(val); - } - void CopyFrom(const MapValueRef& other) { - type_ = other.type_; - data_ = other.data_; - } - // Only used in DynamicMapField - void DeleteData() { - switch (type_) { -#define HANDLE_TYPE(CPPTYPE, TYPE) \ - case google::protobuf::FieldDescriptor::CPPTYPE_##CPPTYPE: { \ - delete reinterpret_cast(data_); \ - break; \ - } - HANDLE_TYPE(INT32, int32); - HANDLE_TYPE(INT64, int64); - HANDLE_TYPE(UINT32, uint32); - HANDLE_TYPE(UINT64, uint64); - HANDLE_TYPE(DOUBLE, double); - HANDLE_TYPE(FLOAT, float); - HANDLE_TYPE(BOOL, bool); - HANDLE_TYPE(STRING, string); - HANDLE_TYPE(ENUM, int32); - HANDLE_TYPE(MESSAGE, Message); -#undef HANDLE_TYPE - } - } - // data_ point to a map value. MapValueRef does not - // own this value. - void* data_; - // type_ is 0 or a valid FieldDescriptor::CppType. - int type_; -}; - -#undef TYPE_CHECK - // This is the class for google::protobuf::Map's internal value_type. Instead of using // std::pair as value_type, we use this class which provides us more control of // its process of construction and destruction. @@ -523,30 +136,18 @@ class Map { typedef size_t size_type; typedef hash hasher; - explicit Map(bool old_style = false) - : arena_(NULL), - default_enum_value_(0), - old_style_(old_style) { - Init(); - } - explicit Map(Arena* arena, bool old_style = false) - : arena_(arena), - default_enum_value_(0), - old_style_(old_style) { - Init(); - } + Map() : arena_(NULL), default_enum_value_(0) { Init(); } + explicit Map(Arena* arena) : arena_(arena), default_enum_value_(0) { Init(); } + Map(const Map& other) - : arena_(NULL), - default_enum_value_(other.default_enum_value_), - old_style_(other.old_style_) { + : arena_(NULL), default_enum_value_(other.default_enum_value_) { Init(); insert(other.begin(), other.end()); } + template - Map(const InputIt& first, const InputIt& last, bool old_style = false) - : arena_(NULL), - default_enum_value_(0), - old_style_(old_style) { + Map(const InputIt& first, const InputIt& last) + : arena_(NULL), default_enum_value_(0) { Init(); insert(first, last); } @@ -554,22 +155,13 @@ class Map { ~Map() { clear(); if (arena_ == NULL) { - if (old_style_) - delete deprecated_elements_; - else - delete elements_; + delete elements_; } } private: void Init() { - if (old_style_) - deprecated_elements_ = Arena::Create( - arena_, 0, hasher(), std::equal_to(), - MapAllocator*> >(arena_)); - else - elements_ = - Arena::Create(arena_, 0, hasher(), Allocator(arena_)); + elements_ = Arena::Create(arena_, 0, hasher(), Allocator(arena_)); } // re-implement std::allocator to use arena allocator for memory allocation. @@ -678,7 +270,7 @@ class Map { const Key& key() const { return k_; } Key& key() { return k_; } - value_type* const value() const { return v_; } + value_type* value() const { return v_; } value_type*& value() { return v_; } private: @@ -764,14 +356,13 @@ class Map { }; typedef typename Allocator::template rebind::other KeyPtrAllocator; typedef std::set Tree; + typedef typename Tree::iterator TreeIterator; // iterator and const_iterator are instantiations of iterator_base. template - class iterator_base { - public: + struct iterator_base { typedef KeyValueType& reference; typedef KeyValueType* pointer; - typedef typename Tree::iterator TreeIterator; // Invariants: // node_ is always correct. This is handy because the most common @@ -780,7 +371,7 @@ class Map { // are updated to be correct also, but those fields can become stale // if the underlying map is modified. When those fields are needed they // are rechecked, and updated if necessary. - iterator_base() : node_(NULL) {} + iterator_base() : node_(NULL), m_(NULL), bucket_index_(0) {} explicit iterator_base(const InnerMap* m) : m_(m) { SearchFrom(m->index_of_first_non_null_); @@ -791,22 +382,15 @@ class Map { // can convert to const_iterator" is OK but the reverse direction is not. template explicit iterator_base(const iterator_base& it) - : node_(it.node_), - m_(it.m_), - bucket_index_(it.bucket_index_), - tree_it_(it.tree_it_) {} + : node_(it.node_), m_(it.m_), bucket_index_(it.bucket_index_) {} iterator_base(Node* n, const InnerMap* m, size_type index) - : node_(n), - m_(m), - bucket_index_(index) {} + : node_(n), m_(m), bucket_index_(index) {} iterator_base(TreeIterator tree_it, const InnerMap* m, size_type index) - : node_(NodePtrFromKeyPtr(*tree_it)), - m_(m), - bucket_index_(index), - tree_it_(tree_it) { - // Invariant: iterators that use tree_it_ have an even bucket_index_. + : node_(NodePtrFromKeyPtr(*tree_it)), m_(m), bucket_index_(index) { + // Invariant: iterators that use buckets with trees have an even + // bucket_index_. GOOGLE_DCHECK_EQ(bucket_index_ % 2, 0); } @@ -824,8 +408,7 @@ class Map { } else if (m_->TableEntryIsTree(bucket_index_)) { Tree* tree = static_cast(m_->table_[bucket_index_]); GOOGLE_DCHECK(!tree->empty()); - tree_it_ = tree->begin(); - node_ = NodePtrFromKeyPtr(*tree_it_); + node_ = NodePtrFromKeyPtr(*tree->begin()); break; } } @@ -843,16 +426,17 @@ class Map { iterator_base& operator++() { if (node_->next == NULL) { - const bool is_list = revalidate_if_necessary(); + TreeIterator tree_it; + const bool is_list = revalidate_if_necessary(&tree_it); if (is_list) { SearchFrom(bucket_index_ + 1); } else { GOOGLE_DCHECK_EQ(bucket_index_ & 1, 0); Tree* tree = static_cast(m_->table_[bucket_index_]); - if (++tree_it_ == tree->end()) { + if (++tree_it == tree->end()) { SearchFrom(bucket_index_ + 2); } else { - node_ = NodePtrFromKeyPtr(*tree_it_); + node_ = NodePtrFromKeyPtr(*tree_it); } } } else { @@ -869,8 +453,9 @@ class Map { // Assumes node_ and m_ are correct and non-NULL, but other fields may be // stale. Fix them as needed. Then return true iff node_ points to a - // Node in a list. - bool revalidate_if_necessary() { + // Node in a list. If false is returned then *it is modified to be + // a valid iterator for node_. + bool revalidate_if_necessary(TreeIterator* it) { GOOGLE_DCHECK(node_ != NULL && m_ != NULL); // Force bucket_index_ to be in range. bucket_index_ &= (m_->num_buckets_ - 1); @@ -891,16 +476,14 @@ class Map { // not. Revalidate just to be sure. This case is rare enough that we // don't worry about potential optimizations, such as having a custom // find-like method that compares Node* instead of const Key&. - iterator_base i(m_->find(*KeyPtrFromNodePtr(node_))); + iterator_base i(m_->find(*KeyPtrFromNodePtr(node_), it)); bucket_index_ = i.bucket_index_; - tree_it_ = i.tree_it_; return m_->TableEntryIsList(bucket_index_); } Node* node_; const InnerMap* m_; size_type bucket_index_; - TreeIterator tree_it_; }; public: @@ -952,7 +535,7 @@ class Map { bool empty() const { return size() == 0; } iterator find(const Key& k) { return iterator(FindHelper(k).first); } - const_iterator find(const Key& k) const { return FindHelper(k).first; } + const_iterator find(const Key& k) const { return find(k, NULL); } // In traditional C++ style, this performs "insert if not present." std::pair insert(const KeyValuePair& kv) { @@ -999,7 +582,8 @@ class Map { void erase(iterator it) { GOOGLE_DCHECK_EQ(it.m_, this); - const bool is_list = it.revalidate_if_necessary(); + typename Tree::iterator tree_it; + const bool is_list = it.revalidate_if_necessary(&tree_it); size_type b = it.bucket_index_; Node* const item = it.node_; if (is_list) { @@ -1010,7 +594,7 @@ class Map { } else { GOOGLE_DCHECK(TableEntryIsTree(b)); Tree* tree = static_cast(table_[b]); - tree->erase(it.tree_it_); + tree->erase(*tree_it); if (tree->empty()) { // Force b to be the minimum of b and b ^ 1. This is important // only because we want index_of_first_non_null_ to be correct. @@ -1030,7 +614,14 @@ class Map { } private: + const_iterator find(const Key& k, TreeIterator* it) const { + return FindHelper(k, it).first; + } std::pair FindHelper(const Key& k) const { + return FindHelper(k, NULL); + } + std::pair FindHelper(const Key& k, + TreeIterator* it) const { size_type b = BucketNumber(k); if (TableEntryIsNonEmptyList(b)) { Node* node = static_cast(table_[b]); @@ -1048,6 +639,7 @@ class Map { Key* key = const_cast(&k); typename Tree::iterator tree_it = tree->find(key); if (tree_it != tree->end()) { + if (it != NULL) *it = tree_it; return std::make_pair(const_iterator(tree_it, this, b), b); } } @@ -1358,72 +950,30 @@ class Map { GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(InnerMap); }; // end of class InnerMap - typedef hash_map, std::equal_to, - MapAllocator*> > > - DeprecatedInnerMap; - public: // Iterators - class iterator_base { - public: - // We support "old style" and "new style" iterators for now. This is - // temporary. Also, for "iterator()" we have an unknown category. - // TODO(gpike): get rid of this. - enum IteratorStyle { kUnknown, kOld, kNew }; - explicit iterator_base(IteratorStyle style) : iterator_style_(style) {} - - bool OldStyle() const { - GOOGLE_DCHECK_NE(iterator_style_, kUnknown); - return iterator_style_ == kOld; - } - bool UnknownStyle() const { - return iterator_style_ == kUnknown; - } - bool SameStyle(const iterator_base& other) const { - return iterator_style_ == other.iterator_style_; - } - - private: - IteratorStyle iterator_style_; - }; - class const_iterator - : private iterator_base, - public std::iterator { typedef typename InnerMap::const_iterator InnerIt; - typedef typename DeprecatedInnerMap::const_iterator DeprecatedInnerIt; public: - const_iterator() : iterator_base(iterator_base::kUnknown) {} - explicit const_iterator(const DeprecatedInnerIt& dit) - : iterator_base(iterator_base::kOld), dit_(dit) {} - explicit const_iterator(const InnerIt& it) - : iterator_base(iterator_base::kNew), it_(it) {} - - const_iterator(const const_iterator& other) - : iterator_base(other), it_(other.it_), dit_(other.dit_) {} + const_iterator() {} + explicit const_iterator(const InnerIt& it) : it_(it) {} const_reference operator*() const { - return this->OldStyle() ? *dit_->second : *it_->value(); + return *it_->value(); } const_pointer operator->() const { return &(operator*()); } const_iterator& operator++() { - if (this->OldStyle()) - ++dit_; - else - ++it_; + ++it_; return *this; } - const_iterator operator++(int) { - return this->OldStyle() ? const_iterator(dit_++) : const_iterator(it_++); - } + const_iterator operator++(int) { return const_iterator(it_++); } friend bool operator==(const const_iterator& a, const const_iterator& b) { - if (!a.SameStyle(b)) return false; - if (a.UnknownStyle()) return true; - return a.OldStyle() ? (a.dit_ == b.dit_) : (a.it_ == b.it_); + return a.it_ == b.it_; } friend bool operator!=(const const_iterator& a, const const_iterator& b) { return !(a == b); @@ -1431,48 +981,31 @@ class Map { private: InnerIt it_; - DeprecatedInnerIt dit_; }; - class iterator : private iterator_base, - public std::iterator { + class iterator : public std::iterator { typedef typename InnerMap::iterator InnerIt; - typedef typename DeprecatedInnerMap::iterator DeprecatedInnerIt; public: - iterator() : iterator_base(iterator_base::kUnknown) {} - explicit iterator(const DeprecatedInnerIt& dit) - : iterator_base(iterator_base::kOld), dit_(dit) {} - explicit iterator(const InnerIt& it) - : iterator_base(iterator_base::kNew), it_(it) {} + iterator() {} + explicit iterator(const InnerIt& it) : it_(it) {} - reference operator*() const { - return this->OldStyle() ? *dit_->second : *it_->value(); - } + reference operator*() const { return *it_->value(); } pointer operator->() const { return &(operator*()); } iterator& operator++() { - if (this->OldStyle()) - ++dit_; - else - ++it_; + ++it_; return *this; } - iterator operator++(int) { - return this->OldStyle() ? iterator(dit_++) : iterator(it_++); - } + iterator operator++(int) { return iterator(it_++); } // Allow implicit conversion to const_iterator. operator const_iterator() const { - return this->OldStyle() ? - const_iterator(typename DeprecatedInnerMap::const_iterator(dit_)) : - const_iterator(typename InnerMap::const_iterator(it_)); + return const_iterator(typename InnerMap::const_iterator(it_)); } friend bool operator==(const iterator& a, const iterator& b) { - if (!a.SameStyle(b)) return false; - if (a.UnknownStyle()) return true; - return a.OldStyle() ? a.dit_ == b.dit_ : a.it_ == b.it_; + return a.it_ == b.it_; } friend bool operator!=(const iterator& a, const iterator& b) { return !(a == b); @@ -1482,38 +1015,26 @@ class Map { friend class Map; InnerIt it_; - DeprecatedInnerIt dit_; }; - iterator begin() { - return old_style_ ? iterator(deprecated_elements_->begin()) - : iterator(elements_->begin()); - } - iterator end() { - return old_style_ ? iterator(deprecated_elements_->end()) - : iterator(elements_->end()); - } + iterator begin() { return iterator(elements_->begin()); } + iterator end() { return iterator(elements_->end()); } const_iterator begin() const { - return old_style_ ? const_iterator(deprecated_elements_->begin()) - : const_iterator(iterator(elements_->begin())); + return const_iterator(iterator(elements_->begin())); } const_iterator end() const { - return old_style_ ? const_iterator(deprecated_elements_->end()) - : const_iterator(iterator(elements_->end())); + return const_iterator(iterator(elements_->end())); } const_iterator cbegin() const { return begin(); } const_iterator cend() const { return end(); } // Capacity - size_type size() const { - return old_style_ ? deprecated_elements_->size() : elements_->size(); - } + size_type size() const { return elements_->size(); } bool empty() const { return size() == 0; } // Element access T& operator[](const key_type& key) { - value_type** value = - old_style_ ? &(*deprecated_elements_)[key] : &(*elements_)[key]; + value_type** value = &(*elements_)[key]; if (*value == NULL) { *value = CreateValueTypeInternal(key); internal::MapValueInitializer::value, @@ -1540,13 +1061,9 @@ class Map { return it == end() ? 0 : 1; } const_iterator find(const key_type& key) const { - return old_style_ ? const_iterator(deprecated_elements_->find(key)) - : const_iterator(iterator(elements_->find(key))); - } - iterator find(const key_type& key) { - return old_style_ ? iterator(deprecated_elements_->find(key)) - : iterator(elements_->find(key)); + return const_iterator(iterator(elements_->find(key))); } + iterator find(const key_type& key) { return iterator(elements_->find(key)); } std::pair equal_range( const key_type& key) const { const_iterator it = find(key); @@ -1569,23 +1086,12 @@ class Map { // insert std::pair insert(const value_type& value) { - if (old_style_) { - iterator it = find(value.first); - if (it != end()) { - return std::pair(it, false); - } else { - return std::pair( - iterator(deprecated_elements_->insert(std::pair( - value.first, CreateValueTypeInternal(value))).first), true); - } - } else { - std::pair p = - elements_->insert(value.first); - if (p.second) { - p.first->value() = CreateValueTypeInternal(value); - } - return std::pair(iterator(p.first), p.second); + std::pair p = + elements_->insert(value.first); + if (p.second) { + p.first->value() = CreateValueTypeInternal(value); } + return std::pair(iterator(p.first), p.second); } template void insert(InputIt first, InputIt last) { @@ -1610,10 +1116,7 @@ class Map { iterator erase(iterator pos) { if (arena_ == NULL) delete pos.operator->(); iterator i = pos++; - if (old_style_) - deprecated_elements_->erase(i.dit_); - else - elements_->erase(i.it_); + elements_->erase(i.it_); return pos; } void erase(iterator first, iterator last) { @@ -1633,13 +1136,9 @@ class Map { } void swap(Map& other) { - if (arena_ == other.arena_ && old_style_ == other.old_style_) { + if (arena_ == other.arena_) { std::swap(default_enum_value_, other.default_enum_value_); - if (old_style_) { - std::swap(deprecated_elements_, other.deprecated_elements_); - } else { - std::swap(elements_, other.elements_); - } + std::swap(elements_, other.elements_); } else { // TODO(zuguang): optimize this. The temporary copy can be allocated // in the same arena as the other message, and the "other = copy" can @@ -1653,8 +1152,7 @@ class Map { // Access to hasher. Currently this returns a copy, but it may // be modified to return a const reference in the future. hasher hash_function() const { - return old_style_ ? deprecated_elements_->hash_function() - : elements_->hash_function(); + return elements_->hash_function(); } private: @@ -1692,19 +1190,12 @@ class Map { Arena* arena_; int default_enum_value_; - // The following is a tagged union because we support two map styles - // for now. - // TODO(gpike): get rid of the old style. - const bool old_style_; - union { - InnerMap* elements_; - DeprecatedInnerMap* deprecated_elements_; - }; + InnerMap* elements_; friend class ::google::protobuf::Arena; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; - template @@ -1712,49 +1203,6 @@ class Map { }; } // namespace protobuf -} // namespace google - -GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_START -template<> -struct hash { - size_t - operator()(const google::protobuf::MapKey& map_key) const { - switch (map_key.type()) { - case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE: - case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT: - case google::protobuf::FieldDescriptor::CPPTYPE_ENUM: - case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE: - GOOGLE_LOG(FATAL) << "Unsupported"; - break; - case google::protobuf::FieldDescriptor::CPPTYPE_STRING: - return hash()(map_key.GetStringValue()); -#if defined(GOOGLE_PROTOBUF_HAVE_64BIT_HASH) - case google::protobuf::FieldDescriptor::CPPTYPE_INT64: - return hash< ::google::protobuf::int64>()(map_key.GetInt64Value()); - case google::protobuf::FieldDescriptor::CPPTYPE_UINT64: - return hash< ::google::protobuf::uint64>()(map_key.GetUInt64Value()); -#else - case google::protobuf::FieldDescriptor::CPPTYPE_INT64: - case google::protobuf::FieldDescriptor::CPPTYPE_UINT64: - GOOGLE_LOG(FATAL) << "Unsupported on this platform."; - break; -#endif - case google::protobuf::FieldDescriptor::CPPTYPE_INT32: - return hash< ::google::protobuf::int32>()(map_key.GetInt32Value()); - case google::protobuf::FieldDescriptor::CPPTYPE_UINT32: - return hash< ::google::protobuf::uint32>()(map_key.GetUInt32Value()); - case google::protobuf::FieldDescriptor::CPPTYPE_BOOL: - return hash()(map_key.GetBoolValue()); - } - GOOGLE_LOG(FATAL) << "Can't get here."; - return 0; - } - bool - operator()(const google::protobuf::MapKey& map_key1, - const google::protobuf::MapKey& map_key2) const { - return map_key1 < map_key2; - } -}; -GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_END +} // namespace google #endif // GOOGLE_PROTOBUF_MAP_H__ diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/map_entry.h b/third_party/protobuf/3.2.0/src/google/protobuf/map_entry.h index d7db9b0f72..7c6755687f 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/map_entry.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/map_entry.h @@ -43,10 +43,9 @@ namespace google { namespace protobuf { class Arena; namespace internal { -template + WireFormatLite::FieldType kValueFieldType, int default_enum_value> class MapField; } } @@ -54,30 +53,6 @@ class MapField; namespace protobuf { namespace internal { -// Register all MapEntry default instances so we can delete them in -// ShutdownProtobufLibrary(). -void LIBPROTOBUF_EXPORT RegisterMapEntryDefaultInstance( - MessageLite* default_instance); - -// This is the common base class for MapEntry. It is used by MapFieldBase in -// reflection api, in which the static type of key and value is unknown. -class LIBPROTOBUF_EXPORT MapEntryBase : public Message { - public: - ::google::protobuf::Metadata GetMetadata() const { - ::google::protobuf::Metadata metadata; - metadata.descriptor = descriptor_; - metadata.reflection = reflection_; - return metadata; - } - - protected: - MapEntryBase() : descriptor_(NULL), reflection_(NULL) { } - virtual ~MapEntryBase() {} - - const Descriptor* descriptor_; - const Reflection* reflection_; -}; - // MapEntry is the returned google::protobuf::Message when calling AddMessage of // google::protobuf::Reflection. In order to let it work with generated message // reflection, its in-memory type is the same as generated message with the same @@ -105,212 +80,72 @@ class LIBPROTOBUF_EXPORT MapEntryBase : public Message { // while we need to explicitly specify the cpp type if proto type is // TYPE_MESSAGE to infer the in-memory type. Moreover, default_enum_value is // used to initialize enum field in proto2. -template -class MapEntry : public MapEntryBase { - // Provide utilities to parse/serialize key/value. Provide utilities to - // manipulate internal stored type. - typedef MapTypeHandler KeyTypeHandler; - typedef MapTypeHandler ValueTypeHandler; - - // Enum type cannot be used for MapTypeHandler::Read. Define a type - // which will replace Enum with int. - typedef typename KeyTypeHandler::MapEntryAccessorType KeyMapEntryAccessorType; - typedef typename ValueTypeHandler::MapEntryAccessorType - ValueMapEntryAccessorType; - - // Abbreviation for MapEntry - typedef typename google::protobuf::internal::MapEntry< - Key, Value, kKeyFieldType, kValueFieldType, default_enum_value> EntryType; - - // Abbreviation for MapEntryLite - typedef typename google::protobuf::internal::MapEntryLite< - Key, Value, kKeyFieldType, kValueFieldType, default_enum_value> - EntryLiteType; - + WireFormatLite::FieldType kValueFieldType, int default_enum_value> +class MapEntry + : public MapEntryImpl { public: - ~MapEntry() { - if (this == default_instance_) { - delete reflection_; - } - } - - // accessors ====================================================== - - virtual inline const KeyMapEntryAccessorType& key() const { - return entry_lite_.key(); - } - inline KeyMapEntryAccessorType* mutable_key() { - return entry_lite_.mutable_key(); - } - virtual inline const ValueMapEntryAccessorType& value() const { - return entry_lite_.value(); - } - inline ValueMapEntryAccessorType* mutable_value() { - return entry_lite_.mutable_value(); - } - - // implements Message ============================================= - - bool MergePartialFromCodedStream(::google::protobuf::io::CodedInputStream* input) { - return entry_lite_.MergePartialFromCodedStream(input); - } - - size_t ByteSizeLong() const { - return entry_lite_.ByteSizeLong(); - } - - void SerializeWithCachedSizes(::google::protobuf::io::CodedOutputStream* output) const { - entry_lite_.SerializeWithCachedSizes(output); - } - - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(bool deterministic, - ::google::protobuf::uint8* output) const { - return entry_lite_.InternalSerializeWithCachedSizesToArray(deterministic, - output); - } - - int GetCachedSize() const { - return entry_lite_.GetCachedSize(); - } - - bool IsInitialized() const { - return entry_lite_.IsInitialized(); - } - - Message* New() const { - MapEntry* entry = new MapEntry; - entry->descriptor_ = descriptor_; - entry->reflection_ = reflection_; - entry->set_default_instance(default_instance_); - return entry; - } - - Message* New(Arena* arena) const { - MapEntry* entry = Arena::CreateMessage(arena); - entry->descriptor_ = descriptor_; - entry->reflection_ = reflection_; - entry->set_default_instance(default_instance_); - return entry; - } - - int SpaceUsed() const { - int size = sizeof(MapEntry); - size += entry_lite_.SpaceUsed(); - return size; - } - - void CopyFrom(const ::google::protobuf::Message& from) { - Clear(); - MergeFrom(from); - } - - void MergeFrom(const ::google::protobuf::Message& from) { - GOOGLE_CHECK_NE(&from, this); - const MapEntry* source = dynamic_cast_if_available(&from); - if (source == NULL) { - ReflectionOps::Merge(from, this); - } else { - MergeFrom(*source); - } - } - - void CopyFrom(const MapEntry& from) { - Clear(); - MergeFrom(from); - } - - void MergeFrom(const MapEntry& from) { - entry_lite_.MergeFrom(from.entry_lite_); - } - - void Clear() { - entry_lite_.Clear(); - } - - void InitAsDefaultInstance() { - entry_lite_.InitAsDefaultInstance(); - } - - Arena* GetArena() const { - return entry_lite_.GetArena(); - } - // Create default MapEntry instance for given descriptor. Descriptor has to be // given when creating default MapEntry instance because different map field // may have the same type and MapEntry class. The given descriptor is needed // to distinguish instances of the same MapEntry class. - static MapEntry* CreateDefaultInstance(const Descriptor* descriptor) { - MapEntry* entry = new MapEntry; + static const Reflection* CreateReflection(const Descriptor* descriptor, + const Derived* entry) { ReflectionSchema schema = { entry, offsets_, has_bits_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_._has_bits_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, _internal_metadata_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, _has_bits_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, + _internal_metadata_), -1, -1, sizeof(MapEntry)}; const Reflection* reflection = new GeneratedMessageReflection( descriptor, schema, DescriptorPool::generated_pool(), MessageFactory::generated_factory()); - entry->descriptor_ = descriptor; - entry->reflection_ = reflection; - entry->set_default_instance(entry); - entry->InitAsDefaultInstance(); - RegisterMapEntryDefaultInstance(entry); - return entry; + return reflection; } - private: - MapEntry() - : _internal_metadata_(NULL), default_instance_(NULL), entry_lite_() {} - + MapEntry() : _internal_metadata_(NULL) {} explicit MapEntry(Arena* arena) - : _internal_metadata_(arena), - default_instance_(NULL), - entry_lite_(arena) {} - - inline Arena* GetArenaNoVirtual() const { - return entry_lite_.GetArenaNoVirtual(); - } - - void set_default_instance(MapEntry* default_instance) { - default_instance_ = default_instance; - entry_lite_.set_default_instance(&default_instance->entry_lite_); - } + : MapEntryImpl(arena), + _internal_metadata_(arena) {} + typedef void InternalArenaConstructable_; + typedef void DestructorSkippable_; + private: static uint32 offsets_[2]; static uint32 has_bits_[2]; InternalMetadataWithArena _internal_metadata_; - MapEntry* default_instance_; - EntryLiteType entry_lite_; friend class ::google::protobuf::Arena; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - template + template friend class internal::MapField; friend class internal::GeneratedMessageReflection; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntry); }; -template -uint32 MapEntry::offsets_[2] = { - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_.key_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_.value_), +uint32 MapEntry::offsets_[2] = { + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, key_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, value_), }; -template -uint32 MapEntry::has_bits_[2] = {0, 1}; +uint32 MapEntry::has_bits_[2] = {0, 1}; } // namespace internal } // namespace protobuf diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/map_entry_lite.h b/third_party/protobuf/3.2.0/src/google/protobuf/map_entry_lite.h index 1243911bcb..c466cc7b87 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/map_entry_lite.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/map_entry_lite.h @@ -32,22 +32,21 @@ #define GOOGLE_PROTOBUF_MAP_ENTRY_LITE_H__ #include + +#include #include #include namespace google { namespace protobuf { -class Arena; namespace internal { -template + WireFormatLite::FieldType kValueFieldType, int default_enum_value> class MapEntry; -template + WireFormatLite::FieldType kValueFieldType, int default_enum_value> class MapFieldLite; } // namespace internal } // namespace protobuf @@ -87,13 +86,14 @@ struct MoveHelper { // strings and similar } }; -// MapEntryLite is used to implement parsing and serialization of map for lite -// runtime. -template -class MapEntryLite : public MessageLite { + WireFormatLite::FieldType kValueFieldType, int default_enum_value> +class MapEntryImpl : public Base { + protected: // Provide utilities to parse/serialize key/value. Provide utilities to // manipulate internal stored type. typedef MapTypeHandler KeyTypeHandler; @@ -122,7 +122,30 @@ class MapEntryLite : public MessageLite { static const size_t kTagSize = 1; public: - ~MapEntryLite() { + // Work-around for a compiler bug (see repeated_field.h). + typedef void MapEntryHasMergeTypeTrait; + typedef Derived EntryType; + typedef Key EntryKeyType; + typedef Value EntryValueType; + static const WireFormatLite::FieldType kEntryKeyFieldType = kKeyFieldType; + static const WireFormatLite::FieldType kEntryValueFieldType = kValueFieldType; + static const int kEntryDefaultEnumValue = default_enum_value; + + MapEntryImpl() : default_instance_(NULL), arena_(NULL) { + KeyTypeHandler::Initialize(&key_, NULL); + ValueTypeHandler::InitializeMaybeByDefaultEnum(&value_, default_enum_value, + NULL); + _has_bits_[0] = 0; + } + + explicit MapEntryImpl(Arena* arena) : default_instance_(NULL), arena_(arena) { + KeyTypeHandler::Initialize(&key_, arena); + ValueTypeHandler::InitializeMaybeByDefaultEnum(&value_, default_enum_value, + arena); + _has_bits_[0] = 0; + } + + ~MapEntryImpl() { if (this != default_instance_) { if (GetArenaNoVirtual() != NULL) return; KeyTypeHandler::DeleteNoArena(key_); @@ -151,12 +174,12 @@ class MapEntryLite : public MessageLite { // implements MessageLite ========================================= - // MapEntryLite is for implementation only and this function isn't called + // MapEntryImpl is for implementation only and this function isn't called // anywhere. Just provide a fake implementation here for MessageLite. string GetTypeName() const { return ""; } void CheckTypeAndMergeFrom(const MessageLite& other) { - MergeFrom(*::google::protobuf::down_cast(&other)); + MergeFromInternal(*::google::protobuf::down_cast(&other)); } bool MergePartialFromCodedStream(::google::protobuf::io::CodedInputStream* input) { @@ -238,26 +261,29 @@ class MapEntryLite : public MessageLite { bool IsInitialized() const { return ValueTypeHandler::IsInitialized(value_); } - MessageLite* New() const { - MapEntryLite* entry = new MapEntryLite; + Base* New() const { + Derived* entry = new Derived; entry->default_instance_ = default_instance_; return entry; } - MessageLite* New(Arena* arena) const { - MapEntryLite* entry = Arena::CreateMessage(arena); + Base* New(Arena* arena) const { + Derived* entry = Arena::CreateMessage(arena); entry->default_instance_ = default_instance_; return entry; } - int SpaceUsed() const { - int size = sizeof(MapEntryLite); - size += KeyTypeHandler::SpaceUsedInMapEntry(key_); - size += ValueTypeHandler::SpaceUsedInMapEntry(value_); + size_t SpaceUsedLong() const { + size_t size = sizeof(Derived); + size += KeyTypeHandler::SpaceUsedInMapEntryLong(key_); + size += ValueTypeHandler::SpaceUsedInMapEntryLong(value_); return size; } - void MergeFrom(const MapEntryLite& from) { + protected: + // We can't declare this function directly here as it would hide the other + // overload (const Message&). + void MergeFromInternal(const MapEntryImpl& from) { if (from._has_bits_[0]) { if (from.has_key()) { KeyTypeHandler::EnsureMutable(&key_, GetArenaNoVirtual()); @@ -272,6 +298,7 @@ class MapEntryLite : public MessageLite { } } + public: void Clear() { KeyTypeHandler::Clear(&key_, GetArenaNoVirtual()); ValueTypeHandler::ClearMaybeByDefaultEnum( @@ -280,6 +307,10 @@ class MapEntryLite : public MessageLite { clear_has_value(); } + void set_default_instance(MapEntryImpl* default_instance) { + default_instance_ = default_instance; + } + void InitAsDefaultInstance() { KeyTypeHandler::AssignDefaultValue(&key_); ValueTypeHandler::AssignDefaultValue(&value_); @@ -289,24 +320,18 @@ class MapEntryLite : public MessageLite { return GetArenaNoVirtual(); } - // Create a MapEntryLite for given key and value from google::protobuf::Map in + // Create a MapEntryImpl for given key and value from google::protobuf::Map in // serialization. This function is only called when value is enum. Enum is // treated differently because its type in MapEntry is int and its type in // google::protobuf::Map is enum. We cannot create a reference to int from an enum. - static MapEntryLite* EnumWrap(const Key& key, const Value value, - Arena* arena) { - return Arena::CreateMessage >( - arena, key, value); + static Derived* EnumWrap(const Key& key, const Value value, Arena* arena) { + return Arena::CreateMessage(arena, key, value); } // Like above, but for all the other types. This avoids value copy to create - // MapEntryLite from google::protobuf::Map in serialization. - static MapEntryLite* Wrap(const Key& key, const Value& value, Arena* arena) { - return Arena::CreateMessage >( - arena, key, value); + // MapEntryImpl from google::protobuf::Map in serialization. + static Derived* Wrap(const Key& key, const Value& value, Arena* arena) { + return Arena::CreateMessage(arena, key, value); } // Parsing using MergePartialFromCodedStream, above, is not as @@ -411,7 +436,7 @@ class MapEntryLite : public MessageLite { Value* value_ptr_; // On the fast path entry_ is not used. And, when entry_ is used, it's set // to mf_->NewEntry(), so in the arena case we must call entry_.release. - google::protobuf::scoped_ptr entry_; + google::protobuf::scoped_ptr entry_; }; protected: @@ -433,21 +458,17 @@ class MapEntryLite : public MessageLite { // involves copy of key and value to construct a MapEntry. In order to avoid // this copy in constructing a MapEntry, we need the following class which // only takes references of given key and value. - template - class MapEntryWrapper - : public MapEntryLite { - typedef MapEntryLite Base; - typedef typename Base::KeyMapEntryAccessorType KeyMapEntryAccessorType; - typedef typename Base::ValueMapEntryAccessorType ValueMapEntryAccessorType; + class MapEntryWrapper : public Derived { + typedef Derived BaseClass; + typedef typename BaseClass::KeyMapEntryAccessorType KeyMapEntryAccessorType; + typedef + typename BaseClass::ValueMapEntryAccessorType ValueMapEntryAccessorType; public: - MapEntryWrapper(Arena* arena, const K& key, const V& value) - : MapEntryLite(arena), - key_(key), - value_(value) { - Base::set_has_key(); - Base::set_has_value(); + MapEntryWrapper(Arena* arena, const Key& key, const Value& value) + : Derived(arena), key_(key), value_(value) { + BaseClass::set_has_key(); + BaseClass::set_has_value(); } inline const KeyMapEntryAccessorType& key() const { return key_; } inline const ValueMapEntryAccessorType& value() const { return value_; } @@ -467,21 +488,17 @@ class MapEntryLite : public MessageLite { // initialize a reference to int with a reference to enum, compiler will // generate a temporary int from enum and initialize the reference to int with // the temporary. - template - class MapEnumEntryWrapper - : public MapEntryLite { - typedef MapEntryLite Base; - typedef typename Base::KeyMapEntryAccessorType KeyMapEntryAccessorType; - typedef typename Base::ValueMapEntryAccessorType ValueMapEntryAccessorType; + class MapEnumEntryWrapper : public Derived { + typedef Derived BaseClass; + typedef typename BaseClass::KeyMapEntryAccessorType KeyMapEntryAccessorType; + typedef + typename BaseClass::ValueMapEntryAccessorType ValueMapEntryAccessorType; public: - MapEnumEntryWrapper(Arena* arena, const K& key, const V& value) - : MapEntryLite(arena), - key_(key), - value_(value) { - Base::set_has_key(); - Base::set_has_value(); + MapEnumEntryWrapper(Arena* arena, const Key& key, const Value& value) + : Derived(arena), key_(key), value_(value) { + BaseClass::set_has_key(); + BaseClass::set_has_value(); } inline const KeyMapEntryAccessorType& key() const { return key_; } inline const ValueMapEntryAccessorType& value() const { return value_; } @@ -494,30 +511,11 @@ class MapEntryLite : public MessageLite { typedef void DestructorSkippable_; }; - MapEntryLite() : default_instance_(NULL), arena_(NULL) { - KeyTypeHandler::Initialize(&key_, NULL); - ValueTypeHandler::InitializeMaybeByDefaultEnum( - &value_, default_enum_value, NULL); - _has_bits_[0] = 0; - } - - explicit MapEntryLite(Arena* arena) - : default_instance_(NULL), arena_(arena) { - KeyTypeHandler::Initialize(&key_, arena); - ValueTypeHandler::InitializeMaybeByDefaultEnum( - &value_, default_enum_value, arena); - _has_bits_[0] = 0; - } - inline Arena* GetArenaNoVirtual() const { return arena_; } - void set_default_instance(MapEntryLite* default_instance) { - default_instance_ = default_instance; - } - - MapEntryLite* default_instance_; + MapEntryImpl* default_instance_; KeyOnMemory key_; ValueOnMemory value_; @@ -527,14 +525,33 @@ class MapEntryLite : public MessageLite { friend class ::google::protobuf::Arena; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; - template friend class internal::MapEntry; - template friend class internal::MapFieldLite; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntryLite); + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntryImpl); +}; + +template +class MapEntryLite + : public MapEntryImpl, + MessageLite, Key, Value, kKeyFieldType, + kValueFieldType, default_enum_value> { + public: + typedef MapEntryImpl + SuperType; + MapEntryLite() {} + explicit MapEntryLite(Arena* arena) : SuperType(arena) {} + void MergeFrom(const MapEntryLite& other) { + MergeFromInternal(other); + } }; // Helpers for deterministic serialization ============================= diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/map_field.cc b/third_party/protobuf/3.2.0/src/google/protobuf/map_field.cc index 49f918181f..64dcc990ff 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/map_field.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/map_field.cc @@ -37,31 +37,6 @@ namespace google { namespace protobuf { namespace internal { -ProtobufOnceType map_entry_default_instances_once_; -Mutex* map_entry_default_instances_mutex_; -vector* map_entry_default_instances_; - -void DeleteMapEntryDefaultInstances() { - for (int i = 0; i < map_entry_default_instances_->size(); ++i) { - delete map_entry_default_instances_->at(i); - } - delete map_entry_default_instances_mutex_; - delete map_entry_default_instances_; -} - -void InitMapEntryDefaultInstances() { - map_entry_default_instances_mutex_ = new Mutex(); - map_entry_default_instances_ = new vector(); - OnShutdown(&DeleteMapEntryDefaultInstances); -} - -void RegisterMapEntryDefaultInstance(MessageLite* default_instance) { - ::google::protobuf::GoogleOnceInit(&map_entry_default_instances_once_, - &InitMapEntryDefaultInstances); - MutexLock lock(map_entry_default_instances_mutex_); - map_entry_default_instances_->push_back(default_instance); -} - MapFieldBase::~MapFieldBase() { if (repeated_field_ != NULL && arena_ == NULL) delete repeated_field_; } @@ -77,25 +52,26 @@ RepeatedPtrFieldBase* MapFieldBase::MutableRepeatedField() { return repeated_field_; } -int MapFieldBase::SpaceUsedExcludingSelf() const { +size_t MapFieldBase::SpaceUsedExcludingSelfLong() const { mutex_.Lock(); - int size = SpaceUsedExcludingSelfNoLock(); + size_t size = SpaceUsedExcludingSelfNoLock(); mutex_.Unlock(); return size; } -int MapFieldBase::SpaceUsedExcludingSelfNoLock() const { +size_t MapFieldBase::SpaceUsedExcludingSelfNoLock() const { if (repeated_field_ != NULL) { - return repeated_field_->SpaceUsedExcludingSelf(); + return repeated_field_->SpaceUsedExcludingSelfLong(); } else { return 0; } } -void MapFieldBase::InitMetadataOnce() const { - GOOGLE_CHECK(entry_descriptor_ != NULL); - GOOGLE_CHECK(assign_descriptor_callback_ != NULL); - (*assign_descriptor_callback_)(); +bool MapFieldBase::IsMapValid() const { + // "Acquire" insures the operation after SyncRepeatedFieldWithMap won't get + // executed before state_ is checked. + Atomic32 state = google::protobuf::internal::Acquire_Load(&state_); + return state != STATE_MODIFIED_REPEATED; } void MapFieldBase::SetMapDirty() { state_ = STATE_MODIFIED_MAP; } @@ -390,6 +366,13 @@ void DynamicMapField::SyncMapWithRepeatedFieldNoLock() const { GOOGLE_LOG(FATAL) << "Can't get here."; break; } + + // Remove existing map value with same key. + Map::iterator iter = map->find(map_key); + if (iter != map->end()) { + iter->second.DeleteData(); + } + MapValueRef& map_val = (*map)[map_key]; map_val.SetType(val_des->cpp_type()); switch (val_des->cpp_type()) { @@ -421,13 +404,13 @@ void DynamicMapField::SyncMapWithRepeatedFieldNoLock() const { } } -int DynamicMapField::SpaceUsedExcludingSelfNoLock() const { - int size = 0; +size_t DynamicMapField::SpaceUsedExcludingSelfNoLock() const { + size_t size = 0; if (MapFieldBase::repeated_field_ != NULL) { - size += MapFieldBase::repeated_field_->SpaceUsedExcludingSelf(); + size += MapFieldBase::repeated_field_->SpaceUsedExcludingSelfLong(); } size += sizeof(map_); - int map_size = map_.size(); + size_t map_size = map_.size(); if (map_size) { Map::const_iterator it = map_.begin(); size += sizeof(it->first) * map_size; @@ -456,7 +439,7 @@ int DynamicMapField::SpaceUsedExcludingSelfNoLock() const { case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE: { while (it != map_.end()) { const Message& message = it->second.GetMessageValue(); - size += message.GetReflection()->SpaceUsed(message); + size += message.GetReflection()->SpaceUsedLong(message); ++it; } break; diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/map_field.h b/third_party/protobuf/3.2.0/src/google/protobuf/map_field.h index d6af8532d2..9d5a328eb5 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/map_field.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/map_field.h @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -62,14 +63,10 @@ class LIBPROTOBUF_EXPORT MapFieldBase { MapFieldBase() : arena_(NULL), repeated_field_(NULL), - entry_descriptor_(NULL), - assign_descriptor_callback_(NULL), state_(STATE_MODIFIED_MAP) {} explicit MapFieldBase(Arena* arena) : arena_(arena), repeated_field_(NULL), - entry_descriptor_(NULL), - assign_descriptor_callback_(NULL), state_(STATE_MODIFIED_MAP) { // Mutex's destructor needs to be called explicitly to release resources // acquired in its constructor. @@ -89,6 +86,8 @@ class LIBPROTOBUF_EXPORT MapFieldBase { virtual bool ContainsMapKey(const MapKey& map_key) const = 0; virtual bool InsertOrLookupMapValue( const MapKey& map_key, MapValueRef* val) = 0; + // Insures operations after won't get executed before calling this. + bool IsMapValid() const; virtual bool DeleteMapValue(const MapKey& map_key) = 0; virtual bool EqualIterator(const MapIterator& a, const MapIterator& b) const = 0; @@ -99,11 +98,15 @@ class LIBPROTOBUF_EXPORT MapFieldBase { // Returns the number of bytes used by the repeated field, excluding // sizeof(*this) - int SpaceUsedExcludingSelf() const; + size_t SpaceUsedExcludingSelfLong() const; + + int SpaceUsedExcludingSelf() const { + return internal::ToIntSize(SpaceUsedExcludingSelfLong()); + } protected: // Gets the size of space used by map field. - virtual int SpaceUsedExcludingSelfNoLock() const; + virtual size_t SpaceUsedExcludingSelfNoLock() const; // Synchronizes the content in Map to RepeatedPtrField if there is any change // to Map after last synchronization. @@ -124,9 +127,6 @@ class LIBPROTOBUF_EXPORT MapFieldBase { // Provides derived class the access to repeated field. void* MutableRepeatedPtrField() const; - // Creates descriptor for only one time. - void InitMetadataOnce() const; - enum State { STATE_MODIFIED_MAP = 0, // map has newly added data that has not been // synchronized to repeated field @@ -137,13 +137,6 @@ class LIBPROTOBUF_EXPORT MapFieldBase { Arena* arena_; mutable RepeatedPtrField* repeated_field_; - // MapEntry can only be created from MapField. To create MapEntry, MapField - // needs to know its descriptor, because MapEntry is not generated class which - // cannot initialize its own descriptor by calling generated - // descriptor-assign-function. Thus, we need to register a callback to - // initialize MapEntry's descriptor. - const Descriptor** entry_descriptor_; - void (*assign_descriptor_callback_)(); mutable Mutex mutex_; // The thread to synchronize map and repeated field // needs to get lock first; @@ -211,27 +204,24 @@ class TypeDefinedMapFieldBase : public MapFieldBase { // This class provides access to map field using generated api. It is used for // internal generated message implentation only. Users should never use this // directly. -template -class MapField : public TypeDefinedMapFieldBase, - public MapFieldLite { + WireFormatLite::FieldType kValueFieldType, int default_enum_value = 0> +class MapField : public TypeDefinedMapFieldBase { // Provide utilities to parse/serialize key/value. Provide utilities to // manipulate internal stored type. typedef MapTypeHandler KeyTypeHandler; typedef MapTypeHandler ValueTypeHandler; // Define message type for internal repeated field. - typedef MapEntry - EntryType; + typedef Derived EntryType; typedef MapEntryLite EntryLiteType; // Define abbreviation for parent MapFieldLite - typedef MapFieldLite MapFieldLiteType; + typedef MapFieldLite + MapFieldLiteType; // Enum needs to be handled differently from other types because it has // different exposed type in google::protobuf::Map's api and repeated field's api. For @@ -241,58 +231,62 @@ class MapField : public TypeDefinedMapFieldBase, typedef typename MapIf::type CastValueType; public: - MapField(); - explicit MapField(Arena* arena); - // MapField doesn't own the default_entry, which means default_entry must - // outlive the lifetime of MapField. - MapField(const Message* default_entry); - // For tests only. - MapField(Arena* arena, const Message* default_entry); - ~MapField(); + MapField() {} + explicit MapField(Arena* arena) + : TypeDefinedMapFieldBase(arena), impl_(arena) {} // Implement MapFieldBase bool ContainsMapKey(const MapKey& map_key) const; bool InsertOrLookupMapValue(const MapKey& map_key, MapValueRef* val); bool DeleteMapValue(const MapKey& map_key); - // Accessors - const Map& GetMap() const; - Map* MutableMap(); + const Map& GetMap() const { + MapFieldBase::SyncMapWithRepeatedField(); + return impl_.GetMap(); + } + + Map* MutableMap() { + MapFieldBase::SyncMapWithRepeatedField(); + Map* result = impl_.MutableMap(); + MapFieldBase::SetMapDirty(); + return result; + } // Convenient methods for generated message implementation. int size() const; void Clear(); - void MergeFrom(const MapFieldLiteType& other); - void Swap(MapFieldLiteType* other); - - // Allocates metadata only if this MapField is part of a generated message. - void SetEntryDescriptor(const Descriptor** descriptor); - void SetAssignDescriptorCallback(void (*callback)()); + void MergeFrom(const MapField& other); + void Swap(MapField* other); + + // Used in the implementation of parsing. Caller should take the ownership iff + // arena_ is NULL. + EntryType* NewEntry() const { return impl_.NewEntry(); } + // Used in the implementation of serializing enum value type. Caller should + // take the ownership iff arena_ is NULL. + EntryType* NewEnumEntryWrapper(const Key& key, const T t) const { + return impl_.NewEnumEntryWrapper(key, t); + } + // Used in the implementation of serializing other value types. Caller should + // take the ownership iff arena_ is NULL. + EntryType* NewEntryWrapper(const Key& key, const T& t) const { + return impl_.NewEntryWrapper(key, t); + } private: + MapFieldLiteType impl_; + typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; - // MapField needs MapEntry's default instance to create new MapEntry. - void InitDefaultEntryOnce() const; - - // Manually set default entry instance. For test only. - void SetDefaultEntryOnce(const EntryType* default_entry) const; - - // Convenient methods to get internal google::protobuf::Map - const Map& GetInternalMap() const; - Map* MutableInternalMap(); - // Implements MapFieldBase void SyncRepeatedFieldWithMapNoLock() const; void SyncMapWithRepeatedFieldNoLock() const; - int SpaceUsedExcludingSelfNoLock() const; + size_t SpaceUsedExcludingSelfNoLock() const; void SetMapIteratorValue(MapIterator* map_iter) const; - mutable const EntryType* default_entry_; - friend class ::google::protobuf::Arena; + friend class MapFieldStateTest; // For testing, it needs raw access to impl_ }; class LIBPROTOBUF_EXPORT DynamicMapField: public TypeDefinedMapFieldBase { @@ -318,12 +312,395 @@ class LIBPROTOBUF_EXPORT DynamicMapField: public TypeDefinedMapFieldBase + friend class internal::TypeDefinedMapFieldBase; + friend class MapIterator; + friend class internal::DynamicMapField; + + union KeyValue { + KeyValue() {} + string* string_value_; + int64 int64_value_; + int32 int32_value_; + uint64 uint64_value_; + uint32 uint32_value_; + bool bool_value_; + } val_; + + void SetType(FieldDescriptor::CppType type) { + if (type_ == type) return; + if (type_ == FieldDescriptor::CPPTYPE_STRING) { + delete val_.string_value_; + } + type_ = type; + if (type_ == FieldDescriptor::CPPTYPE_STRING) { + val_.string_value_ = new string; + } + } + + // type_ is 0 or a valid FieldDescriptor::CppType. + int type_; +}; + +// MapValueRef points to a map value. +class LIBPROTOBUF_EXPORT MapValueRef { + public: + MapValueRef() : data_(NULL), type_(0) {} + + void SetInt64Value(int64 value) { + TYPE_CHECK(FieldDescriptor::CPPTYPE_INT64, + "MapValueRef::SetInt64Value"); + *reinterpret_cast(data_) = value; + } + void SetUInt64Value(uint64 value) { + TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT64, + "MapValueRef::SetUInt64Value"); + *reinterpret_cast(data_) = value; + } + void SetInt32Value(int32 value) { + TYPE_CHECK(FieldDescriptor::CPPTYPE_INT32, + "MapValueRef::SetInt32Value"); + *reinterpret_cast(data_) = value; + } + void SetUInt32Value(uint32 value) { + TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT32, + "MapValueRef::SetUInt32Value"); + *reinterpret_cast(data_) = value; + } + void SetBoolValue(bool value) { + TYPE_CHECK(FieldDescriptor::CPPTYPE_BOOL, + "MapValueRef::SetBoolValue"); + *reinterpret_cast(data_) = value; + } + // TODO(jieluo) - Checks that enum is member. + void SetEnumValue(int value) { + TYPE_CHECK(FieldDescriptor::CPPTYPE_ENUM, + "MapValueRef::SetEnumValue"); + *reinterpret_cast(data_) = value; + } + void SetStringValue(const string& value) { + TYPE_CHECK(FieldDescriptor::CPPTYPE_STRING, + "MapValueRef::SetStringValue"); + *reinterpret_cast(data_) = value; + } + void SetFloatValue(float value) { + TYPE_CHECK(FieldDescriptor::CPPTYPE_FLOAT, + "MapValueRef::SetFloatValue"); + *reinterpret_cast(data_) = value; + } + void SetDoubleValue(double value) { + TYPE_CHECK(FieldDescriptor::CPPTYPE_DOUBLE, + "MapValueRef::SetDoubleValue"); + *reinterpret_cast(data_) = value; + } + + int64 GetInt64Value() const { + TYPE_CHECK(FieldDescriptor::CPPTYPE_INT64, + "MapValueRef::GetInt64Value"); + return *reinterpret_cast(data_); + } + uint64 GetUInt64Value() const { + TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT64, + "MapValueRef::GetUInt64Value"); + return *reinterpret_cast(data_); + } + int32 GetInt32Value() const { + TYPE_CHECK(FieldDescriptor::CPPTYPE_INT32, + "MapValueRef::GetInt32Value"); + return *reinterpret_cast(data_); + } + uint32 GetUInt32Value() const { + TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT32, + "MapValueRef::GetUInt32Value"); + return *reinterpret_cast(data_); + } + bool GetBoolValue() const { + TYPE_CHECK(FieldDescriptor::CPPTYPE_BOOL, + "MapValueRef::GetBoolValue"); + return *reinterpret_cast(data_); + } + int GetEnumValue() const { + TYPE_CHECK(FieldDescriptor::CPPTYPE_ENUM, + "MapValueRef::GetEnumValue"); + return *reinterpret_cast(data_); + } + const string& GetStringValue() const { + TYPE_CHECK(FieldDescriptor::CPPTYPE_STRING, + "MapValueRef::GetStringValue"); + return *reinterpret_cast(data_); + } + float GetFloatValue() const { + TYPE_CHECK(FieldDescriptor::CPPTYPE_FLOAT, + "MapValueRef::GetFloatValue"); + return *reinterpret_cast(data_); + } + double GetDoubleValue() const { + TYPE_CHECK(FieldDescriptor::CPPTYPE_DOUBLE, + "MapValueRef::GetDoubleValue"); + return *reinterpret_cast(data_); + } + + const Message& GetMessageValue() const { + TYPE_CHECK(FieldDescriptor::CPPTYPE_MESSAGE, + "MapValueRef::GetMessageValue"); + return *reinterpret_cast(data_); + } + + Message* MutableMessageValue() { + TYPE_CHECK(FieldDescriptor::CPPTYPE_MESSAGE, + "MapValueRef::MutableMessageValue"); + return reinterpret_cast(data_); + } + + private: + template + friend class internal::MapField; + template + friend class internal::TypeDefinedMapFieldBase; + friend class MapIterator; + friend class internal::GeneratedMessageReflection; + friend class internal::DynamicMapField; + + void SetType(FieldDescriptor::CppType type) { + type_ = type; + } + + FieldDescriptor::CppType type() const { + if (type_ == 0 || data_ == NULL) { + GOOGLE_LOG(FATAL) + << "Protocol Buffer map usage error:\n" + << "MapValueRef::type MapValueRef is not initialized."; + } + return (FieldDescriptor::CppType)type_; + } + void SetValue(const void* val) { + data_ = const_cast(val); + } + void CopyFrom(const MapValueRef& other) { + type_ = other.type_; + data_ = other.data_; + } + // Only used in DynamicMapField + void DeleteData() { + switch (type_) { +#define HANDLE_TYPE(CPPTYPE, TYPE) \ + case google::protobuf::FieldDescriptor::CPPTYPE_##CPPTYPE: { \ + delete reinterpret_cast(data_); \ + break; \ + } + HANDLE_TYPE(INT32, int32); + HANDLE_TYPE(INT64, int64); + HANDLE_TYPE(UINT32, uint32); + HANDLE_TYPE(UINT64, uint64); + HANDLE_TYPE(DOUBLE, double); + HANDLE_TYPE(FLOAT, float); + HANDLE_TYPE(BOOL, bool); + HANDLE_TYPE(STRING, string); + HANDLE_TYPE(ENUM, int32); + HANDLE_TYPE(MESSAGE, Message); +#undef HANDLE_TYPE + } + } + // data_ point to a map value. MapValueRef does not + // own this value. + void* data_; + // type_ is 0 or a valid FieldDescriptor::CppType. + int type_; +}; + +#undef TYPE_CHECK + class LIBPROTOBUF_EXPORT MapIterator { public: MapIterator(Message* message, const FieldDescriptor* field) { @@ -373,7 +750,7 @@ class LIBPROTOBUF_EXPORT MapIterator { template friend class internal::TypeDefinedMapFieldBase; friend class internal::DynamicMapField; - template @@ -392,6 +769,42 @@ class LIBPROTOBUF_EXPORT MapIterator { }; } // namespace protobuf - } // namespace google + +GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_START +template<> +struct hash { + size_t + operator()(const google::protobuf::MapKey& map_key) const { + switch (map_key.type()) { + case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE: + case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT: + case google::protobuf::FieldDescriptor::CPPTYPE_ENUM: + case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE: + GOOGLE_LOG(FATAL) << "Unsupported"; + break; + case google::protobuf::FieldDescriptor::CPPTYPE_STRING: + return hash()(map_key.GetStringValue()); + case google::protobuf::FieldDescriptor::CPPTYPE_INT64: + return hash< ::google::protobuf::int64>()(map_key.GetInt64Value()); + case google::protobuf::FieldDescriptor::CPPTYPE_INT32: + return hash< ::google::protobuf::int32>()(map_key.GetInt32Value()); + case google::protobuf::FieldDescriptor::CPPTYPE_UINT64: + return hash< ::google::protobuf::uint64>()(map_key.GetUInt64Value()); + case google::protobuf::FieldDescriptor::CPPTYPE_UINT32: + return hash< ::google::protobuf::uint32>()(map_key.GetUInt32Value()); + case google::protobuf::FieldDescriptor::CPPTYPE_BOOL: + return hash()(map_key.GetBoolValue()); + } + GOOGLE_LOG(FATAL) << "Can't get here."; + return 0; + } + bool + operator()(const google::protobuf::MapKey& map_key1, + const google::protobuf::MapKey& map_key2) const { + return map_key1 < map_key2; + } +}; +GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_END + #endif // GOOGLE_PROTOBUF_MAP_FIELD_H__ diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/map_field_inl.h b/third_party/protobuf/3.2.0/src/google/protobuf/map_field_inl.h index 2d84b0a3c2..8c5da3c683 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/map_field_inl.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/map_field_inl.h @@ -162,81 +162,32 @@ void TypeDefinedMapFieldBase::CopyIterator( // ---------------------------------------------------------------------- -template -MapField::MapField() - : default_entry_(NULL) {} - -template -MapField::MapField( - Arena* arena) - : TypeDefinedMapFieldBase(arena), - MapFieldLite( - arena), - default_entry_(NULL) {} - -template -MapField::MapField( - const Message* default_entry) - : default_entry_(down_cast(default_entry)) {} - -template -MapField::MapField( - Arena* arena, const Message* default_entry) - : TypeDefinedMapFieldBase(arena), - MapFieldLite( - arena), - default_entry_(down_cast(default_entry)) {} - -template -MapField::~MapField() {} - -template -int -MapField::size() const { + WireFormatLite::FieldType kValueFieldType, int default_enum_value> +int MapField::size() const { MapFieldBase::SyncMapWithRepeatedField(); - return MapFieldLiteType::GetInternalMap().size(); + return impl_.GetMap().size(); } -template -void -MapField::Clear() { + WireFormatLite::FieldType kValueFieldType, int default_enum_value> +void MapField::Clear() { MapFieldBase::SyncMapWithRepeatedField(); - MapFieldLiteType::MutableInternalMap()->clear(); + impl_.MutableMap()->clear(); MapFieldBase::SetMapDirty(); } -template -void MapField::SetMapIteratorValue( - MapIterator* map_iter) const { - const Map& map = GetMap(); + WireFormatLite::FieldType kValueFieldType, int default_enum_value> +void MapField::SetMapIteratorValue(MapIterator* map_iter) + const { + const Map& map = impl_.GetMap(); typename Map::const_iterator iter = TypeDefinedMapFieldBase::InternalGetIterator(map_iter); if (iter == map.end()) return; @@ -244,27 +195,23 @@ void MapFieldvalue_.SetValue(&iter->second); } -template -bool MapField::ContainsMapKey( - const MapKey& map_key) const { - const Map& map = GetMap(); + WireFormatLite::FieldType kValueFieldType, int default_enum_value> +bool MapField::ContainsMapKey(const MapKey& map_key) const { + const Map& map = impl_.GetMap(); const Key& key = UnwrapMapKey(map_key); typename Map::const_iterator iter = map.find(key); return iter != map.end(); } -template -bool MapField::InsertOrLookupMapValue( - const MapKey& map_key, - MapValueRef* val) { + WireFormatLite::FieldType kValueFieldType, int default_enum_value> +bool MapField::InsertOrLookupMapValue(const MapKey& map_key, + MapValueRef* val) { // Always use mutable map because users may change the map value by // MapValueRef. Map* map = MutableMap(); @@ -280,118 +227,41 @@ bool MapField -bool MapField::DeleteMapValue( - const MapKey& map_key) { + WireFormatLite::FieldType kValueFieldType, int default_enum_value> +bool MapField::DeleteMapValue(const MapKey& map_key) { const Key& key = UnwrapMapKey(map_key); return MutableMap()->erase(key); } -template -const Map& -MapField::GetMap() const { - MapFieldBase::SyncMapWithRepeatedField(); - return MapFieldLiteType::GetInternalMap(); -} - -template -Map* -MapField::MutableMap() { - MapFieldBase::SyncMapWithRepeatedField(); - Map* result = MapFieldLiteType::MutableInternalMap(); - MapFieldBase::SetMapDirty(); - return result; -} - -template -void -MapField::MergeFrom( - const MapFieldLiteType& other) { - const MapField& down_other = down_cast(other); + WireFormatLite::FieldType kValueFieldType, int default_enum_value> +void MapField::MergeFrom(const MapField& other) { MapFieldBase::SyncMapWithRepeatedField(); - down_other.SyncMapWithRepeatedField(); - MapFieldLiteType::MergeFrom(other); + other.SyncMapWithRepeatedField(); + impl_.MergeFrom(other.impl_); MapFieldBase::SetMapDirty(); } -template -void -MapField::Swap( - MapFieldLiteType* other) { - MapField* down_other = down_cast(other); - std::swap(this->MapFieldBase::repeated_field_, down_other->repeated_field_); - MapFieldLiteType::Swap(other); - std::swap(this->MapFieldBase::state_, down_other->state_); -} - -template -void -MapField::SetEntryDescriptor( - const Descriptor** descriptor) { - this->MapFieldBase::entry_descriptor_ = descriptor; -} - -template -void -MapField::SetAssignDescriptorCallback(void (*callback)()) { - this->MapFieldBase::assign_descriptor_callback_ = callback; -} - -template -const Map& -MapField::GetInternalMap() const { - return MapFieldLiteType::GetInternalMap(); + WireFormatLite::FieldType kValueFieldType, int default_enum_value> +void MapField::Swap(MapField* other) { + std::swap(MapFieldBase::repeated_field_, other->repeated_field_); + impl_.Swap(&other->impl_); + std::swap(MapFieldBase::state_, other->state_); } -template -Map* -MapField::MutableInternalMap() { - return MapFieldLiteType::MutableInternalMap(); -} - -template -void -MapField::SyncRepeatedFieldWithMapNoLock() const { + WireFormatLite::FieldType kValueFieldType, int default_enum_value> +void MapField::SyncRepeatedFieldWithMapNoLock() const { if (this->MapFieldBase::repeated_field_ == NULL) { if (this->MapFieldBase::arena_ == NULL) { this->MapFieldBase::repeated_field_ = new RepeatedPtrField(); @@ -401,33 +271,35 @@ MapFieldMapFieldBase::arena_); } } - const Map& map = GetInternalMap(); + const Map& map = impl_.GetMap(); RepeatedPtrField* repeated_field = reinterpret_cast*>( this->MapFieldBase::repeated_field_); repeated_field->Clear(); + // The only way we can get at this point is through reflection and the + // only way we can get the reflection object is by having called GetReflection + // on the encompassing field. So that type must have existed and hence we + // know that this MapEntry default_type has also already been constructed. + // So it's safe to just call internal_default_instance(). + const Message* default_entry = Derived::internal_default_instance(); for (typename Map::const_iterator it = map.begin(); it != map.end(); ++it) { - InitDefaultEntryOnce(); - GOOGLE_CHECK(default_entry_ != NULL); EntryType* new_entry = - down_cast(default_entry_->New(this->MapFieldBase::arena_)); + down_cast(default_entry->New(this->MapFieldBase::arena_)); repeated_field->AddAllocated(new_entry); (*new_entry->mutable_key()) = it->first; (*new_entry->mutable_value()) = it->second; } } -template -void -MapField::SyncMapWithRepeatedFieldNoLock() const { - Map* map = const_cast(this)->MutableInternalMap(); + WireFormatLite::FieldType kValueFieldType, int default_enum_value> +void MapField::SyncMapWithRepeatedFieldNoLock() const { + Map* map = const_cast(this)->impl_.MutableMap(); RepeatedPtrField* repeated_field = reinterpret_cast*>( this->MapFieldBase::repeated_field_); @@ -444,44 +316,24 @@ MapField -int -MapField::SpaceUsedExcludingSelfNoLock() const { - int size = 0; + WireFormatLite::FieldType kValueFieldType, int default_enum_value> +size_t MapField::SpaceUsedExcludingSelfNoLock() const { + size_t size = 0; if (this->MapFieldBase::repeated_field_ != NULL) { - size += this->MapFieldBase::repeated_field_->SpaceUsedExcludingSelf(); + size += this->MapFieldBase::repeated_field_->SpaceUsedExcludingSelfLong(); } - Map* map = const_cast(this)->MutableInternalMap(); + Map* map = const_cast(this)->impl_.MutableMap(); size += sizeof(*map); - for (typename Map::iterator it = map->begin(); - it != map->end(); ++it) { - size += KeyTypeHandler::SpaceUsedInMap(it->first); - size += ValueTypeHandler::SpaceUsedInMap(it->second); + for (typename Map::iterator it = map->begin(); it != map->end(); + ++it) { + size += KeyTypeHandler::SpaceUsedInMapLong(it->first); + size += ValueTypeHandler::SpaceUsedInMapLong(it->second); } return size; } - -template -void -MapField::InitDefaultEntryOnce() - const { - if (default_entry_ == NULL) { - MapFieldBase::InitMetadataOnce(); - GOOGLE_CHECK(*this->MapFieldBase::entry_descriptor_ != NULL); - default_entry_ = down_cast( - MessageFactory::generated_factory()->GetPrototype( - *this->MapFieldBase::entry_descriptor_)); - } -} - } // namespace internal } // namespace protobuf diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/map_field_lite.h b/third_party/protobuf/3.2.0/src/google/protobuf/map_field_lite.h index cb0a4a450b..2d1023925d 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/map_field_lite.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/map_field_lite.h @@ -41,223 +41,69 @@ namespace internal { // This class provides access to map field using generated api. It is used for // internal generated message implentation only. Users should never use this // directly. -template + WireFormatLite::FieldType value_wire_type, int default_enum_value = 0> class MapFieldLite { // Define message type for internal repeated field. - typedef MapEntryLite EntryType; + typedef Derived EntryType; public: - MapFieldLite(); - explicit MapFieldLite(Arena* arena); - virtual ~MapFieldLite(); + MapFieldLite() : arena_(NULL) { SetDefaultEnumValue(); } + + explicit MapFieldLite(Arena* arena) : arena_(arena), map_(arena) { + SetDefaultEnumValue(); + } // Accessors - virtual const Map& GetMap() const; - virtual Map* MutableMap(); + const Map& GetMap() const { return map_; } + Map* MutableMap() { return &map_; } // Convenient methods for generated message implementation. - virtual int size() const; - virtual void Clear(); - virtual void MergeFrom(const MapFieldLite& other); - virtual void Swap(MapFieldLite* other); + int size() const { return map_.size(); } + void Clear() { return map_.clear(); } + void MergeFrom(const MapFieldLite& other) { + for (typename Map::const_iterator it = other.map_.begin(); + it != other.map_.end(); ++it) { + map_[it->first] = it->second; + } + } + void Swap(MapFieldLite* other) { map_.swap(other->map_); } // Set default enum value only for proto2 map field whose value is enum type. - void SetDefaultEnumValue(); + void SetDefaultEnumValue() { + MutableMap()->SetDefaultEnumValue(default_enum_value); + } // Used in the implementation of parsing. Caller should take the ownership iff // arena_ is NULL. - EntryType* NewEntry() const; + EntryType* NewEntry() const { + if (arena_ == NULL) { + return new EntryType(); + } else { + return Arena::CreateMessage(arena_); + } + } // Used in the implementation of serializing enum value type. Caller should // take the ownership iff arena_ is NULL. - EntryType* NewEnumEntryWrapper(const Key& key, const T t) const; + EntryType* NewEnumEntryWrapper(const Key& key, const T t) const { + return EntryType::EnumWrap(key, t, arena_); + } // Used in the implementation of serializing other value types. Caller should // take the ownership iff arena_ is NULL. - EntryType* NewEntryWrapper(const Key& key, const T& t) const; - - protected: - // Convenient methods to get internal google::protobuf::Map - virtual const Map& GetInternalMap() const; - virtual Map* MutableInternalMap(); + EntryType* NewEntryWrapper(const Key& key, const T& t) const { + return EntryType::Wrap(key, t, arena_); + } private: typedef void DestructorSkippable_; Arena* arena_; - Map* map_; + Map map_; friend class ::google::protobuf::Arena; }; -template -MapFieldLite::MapFieldLite() - : arena_(NULL) { - map_ = new Map; - SetDefaultEnumValue(); -} - -template -MapFieldLite::MapFieldLite(Arena* arena) - : arena_(arena) { - map_ = Arena::CreateMessage >(arena); - SetDefaultEnumValue(); -} - -template -MapFieldLite::~MapFieldLite() { - delete map_; -} - -template -const Map& -MapFieldLite::GetMap() const { - return *map_; -} - -template -Map* -MapFieldLite::MutableMap() { - return map_; -} - -template -int -MapFieldLite::size() const { - return map_->size(); -} - -template -void -MapFieldLite::Clear() { - map_->clear(); -} - -template -void -MapFieldLite::MergeFrom( - const MapFieldLite& other) { - for (typename Map::const_iterator it = other.map_->begin(); - it != other.map_->end(); ++it) { - (*map_)[it->first] = it->second; - } -} - -template -void -MapFieldLite::Swap( - MapFieldLite* other) { - std::swap(map_, other->map_); -} - -template -void -MapFieldLite::SetDefaultEnumValue() { - MutableInternalMap()->SetDefaultEnumValue(default_enum_value); -} - -template -const Map& -MapFieldLite::GetInternalMap() const { - return *map_; -} - -template -Map* -MapFieldLite::MutableInternalMap() { - return map_; -} - -#define EntryType \ - MapEntryLite - -template -EntryType* -MapFieldLite::NewEntry() const { - if (arena_ == NULL) { - return new EntryType(); - } else { - return Arena::CreateMessage(arena_); - } -} - -template -EntryType* -MapFieldLite::NewEnumEntryWrapper(const Key& key, - const T t) const { - return EntryType::EnumWrap(key, t, arena_); -} - -template -EntryType* -MapFieldLite::NewEntryWrapper(const Key& key, - const T& t) const { - return EntryType::Wrap(key, t, arena_); -} - -#undef EntryType // True if IsInitialized() is true for value field in all elements of t. T is // expected to be message. It's useful to have this helper here to keep the diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/map_field_test.cc b/third_party/protobuf/3.2.0/src/google/protobuf/map_field_test.cc index dd5061c498..8617a366af 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/map_field_test.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/map_field_test.cc @@ -101,8 +101,10 @@ class MapFieldBaseStub : public MapFieldBase { class MapFieldBasePrimitiveTest : public ::testing::Test { protected: - typedef MapField MapFieldType; + typedef unittest::TestMap::TestMap_MapInt32Int32Entry EntryType; + typedef MapField + MapFieldType; MapFieldBasePrimitiveTest() { // Get descriptors @@ -113,9 +115,7 @@ class MapFieldBasePrimitiveTest : public ::testing::Test { value_descriptor_ = map_descriptor_->FindFieldByName("value"); // Build map field - default_entry_ = - MessageFactory::generated_factory()->GetPrototype(map_descriptor_); - map_field_.reset(new MapFieldType(default_entry_)); + map_field_.reset(new MapFieldType); map_field_base_ = map_field_.get(); map_ = map_field_->MutableMap(); initial_value_map_[0] = 100; @@ -130,7 +130,6 @@ class MapFieldBasePrimitiveTest : public ::testing::Test { const Descriptor* map_descriptor_; const FieldDescriptor* key_descriptor_; const FieldDescriptor* value_descriptor_; - const Message* default_entry_; std::map initial_value_map_; // copy of initial values inserted }; @@ -177,8 +176,7 @@ TEST_F(MapFieldBasePrimitiveTest, Arena) { // repeated fields are allocated from arenas. // NoHeapChecker no_heap; - MapFieldType* map_field = - Arena::CreateMessage(&arena, default_entry_); + MapFieldType* map_field = Arena::CreateMessage(&arena); // Set content in map (*map_field->MutableMap())[100] = 101; @@ -208,19 +206,13 @@ class MapFieldStateTest : public testing::TestWithParam { public: protected: - typedef MapField MapFieldType; - typedef MapFieldLite MapFieldLiteType; + typedef unittest::TestMap::TestMap_MapInt32Int32Entry EntryType; + typedef MapField + MapFieldType; MapFieldStateTest() : state_(GetParam()) { // Build map field - const Descriptor* map_descriptor = - unittest::TestMap::descriptor() - ->FindFieldByName("map_int32_int32") - ->message_type(); - default_entry_ = - MessageFactory::generated_factory()->GetPrototype(map_descriptor); - map_field_.reset(new MapFieldType(default_entry_)); + map_field_.reset(new MapFieldType()); map_field_base_ = map_field_.get(); Expect(map_field_.get(), MAP_DIRTY, 0, 0, true); @@ -257,8 +249,8 @@ class MapFieldStateTest MakeMapDirty(map_field); MapFieldBase* map_field_base = map_field; map_field_base->MutableRepeatedField(); - Map* map = implicit_cast(map_field) - ->MapFieldLiteType::MutableMap(); + // We use MutableMap on impl_ because we don't want to disturb the syncing + Map* map = map_field->impl_.MutableMap(); map->clear(); Expect(map_field, REPEATED_DIRTY, 0, 1, false); @@ -270,8 +262,8 @@ class MapFieldStateTest MapFieldBaseStub* stub = reinterpret_cast(map_field_base); - Map* map = implicit_cast(map_field) - ->MapFieldLiteType::MutableMap(); + // We use MutableMap on impl_ because we don't want to disturb the syncing + Map* map = map_field->impl_.MutableMap(); RepeatedPtrField* repeated_field = stub->InternalRepeatedField(); switch (state) { @@ -302,7 +294,6 @@ class MapFieldStateTest google::protobuf::scoped_ptr map_field_; MapFieldBase* map_field_base_; State state_; - const Message* default_entry_; }; INSTANTIATE_TEST_CASE_P(MapFieldStateTestInstance, MapFieldStateTest, @@ -327,7 +318,7 @@ TEST_P(MapFieldStateTest, MutableMap) { } TEST_P(MapFieldStateTest, MergeFromClean) { - MapFieldType other(default_entry_); + MapFieldType other; AddOneStillClean(&other); map_field_->MergeFrom(other); @@ -342,7 +333,7 @@ TEST_P(MapFieldStateTest, MergeFromClean) { } TEST_P(MapFieldStateTest, MergeFromMapDirty) { - MapFieldType other(default_entry_); + MapFieldType other; MakeMapDirty(&other); map_field_->MergeFrom(other); @@ -357,7 +348,7 @@ TEST_P(MapFieldStateTest, MergeFromMapDirty) { } TEST_P(MapFieldStateTest, MergeFromRepeatedDirty) { - MapFieldType other(default_entry_); + MapFieldType other; MakeRepeatedDirty(&other); map_field_->MergeFrom(other); @@ -372,7 +363,7 @@ TEST_P(MapFieldStateTest, MergeFromRepeatedDirty) { } TEST_P(MapFieldStateTest, SwapClean) { - MapFieldType other(default_entry_); + MapFieldType other; AddOneStillClean(&other); map_field_->Swap(&other); @@ -395,7 +386,7 @@ TEST_P(MapFieldStateTest, SwapClean) { } TEST_P(MapFieldStateTest, SwapMapDirty) { - MapFieldType other(default_entry_); + MapFieldType other; MakeMapDirty(&other); map_field_->Swap(&other); @@ -418,7 +409,7 @@ TEST_P(MapFieldStateTest, SwapMapDirty) { } TEST_P(MapFieldStateTest, SwapRepeatedDirty) { - MapFieldType other(default_entry_); + MapFieldType other; MakeRepeatedDirty(&other); map_field_->Swap(&other); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/map_proto2_unittest.proto b/third_party/protobuf/3.2.0/src/google/protobuf/map_proto2_unittest.proto index e9360a5a68..20d58f903f 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/map_proto2_unittest.proto +++ b/third_party/protobuf/3.2.0/src/google/protobuf/map_proto2_unittest.proto @@ -84,3 +84,8 @@ message TestMaps { map m_bool = 11; map m_string = 12; } + +// Test maps in submessages. +message TestSubmessageMaps { + optional TestMaps m = 1; +} diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/map_test.cc b/third_party/protobuf/3.2.0/src/google/protobuf/map_test.cc index 43fe0f4447..a06b432aa9 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/map_test.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/map_test.cc @@ -54,10 +54,13 @@ #include #include #include -#include #include +#include #include #include +#include +#include +#include #include #include #include @@ -70,12 +73,8 @@ #include #include #include -#include -#include -#include -#include #include -#include +#include #include #include #include @@ -97,17 +96,15 @@ void MapTestForceDeterministic() { // Map API Test ===================================================== -// Parameterized tests on whether to use old style maps. -class MapImplTest : public testing::TestWithParam { +class MapImplTest : public ::testing::Test { protected: MapImplTest() - : map_ptr_(new Map(GetParam())), + : map_ptr_(new Map()), map_(*map_ptr_), const_map_(*map_ptr_) { EXPECT_TRUE(map_.empty()); EXPECT_EQ(0, map_.size()); } - ~MapImplTest() {} void ExpectSingleElement(int32 key, int32 value) { EXPECT_FALSE(map_.empty()); @@ -178,7 +175,7 @@ class MapImplTest : public testing::TestWithParam { const Map& const_map_; }; -TEST_P(MapImplTest, OperatorBracket) { +TEST_F(MapImplTest, OperatorBracket) { int32 key = 0; int32 value1 = 100; int32 value2 = 101; @@ -192,7 +189,7 @@ TEST_P(MapImplTest, OperatorBracket) { ExpectSingleElement(key, value2); } -TEST_P(MapImplTest, OperatorBracketNonExist) { +TEST_F(MapImplTest, OperatorBracketNonExist) { int32 key = 0; int32 default_value = 0; @@ -200,7 +197,7 @@ TEST_P(MapImplTest, OperatorBracketNonExist) { ExpectSingleElement(key, default_value); } -TEST_P(MapImplTest, MutableAt) { +TEST_F(MapImplTest, MutableAt) { int32 key = 0; int32 value1 = 100; int32 value2 = 101; @@ -214,15 +211,15 @@ TEST_P(MapImplTest, MutableAt) { #ifdef PROTOBUF_HAS_DEATH_TEST -TEST_P(MapImplTest, MutableAtNonExistDeathTest) { +TEST_F(MapImplTest, MutableAtNonExistDeathTest) { EXPECT_DEATH(map_.at(0), ""); } -TEST_P(MapImplTest, ImmutableAtNonExistDeathTest) { +TEST_F(MapImplTest, ImmutableAtNonExistDeathTest) { EXPECT_DEATH(const_map_.at(0), ""); } -TEST_P(MapImplTest, UsageErrors) { +TEST_F(MapImplTest, UsageErrors) { MapKey key; key.SetInt64Value(1); EXPECT_DEATH(key.GetUInt64Value(), @@ -239,23 +236,23 @@ TEST_P(MapImplTest, UsageErrors) { #endif // PROTOBUF_HAS_DEATH_TEST -TEST_P(MapImplTest, CountNonExist) { +TEST_F(MapImplTest, CountNonExist) { EXPECT_EQ(0, map_.count(0)); } -TEST_P(MapImplTest, MutableFindNonExist) { +TEST_F(MapImplTest, MutableFindNonExist) { EXPECT_TRUE(map_.end() == map_.find(0)); } -TEST_P(MapImplTest, ImmutableFindNonExist) { +TEST_F(MapImplTest, ImmutableFindNonExist) { EXPECT_TRUE(const_map_.end() == const_map_.find(0)); } -TEST_P(MapImplTest, ConstEnd) { +TEST_F(MapImplTest, ConstEnd) { EXPECT_TRUE(const_map_.end() == const_map_.cend()); } -TEST_P(MapImplTest, GetReferenceFromIterator) { +TEST_F(MapImplTest, GetReferenceFromIterator) { for (int i = 0; i < 10; i++) { map_[i] = i; } @@ -278,7 +275,7 @@ TEST_P(MapImplTest, GetReferenceFromIterator) { } } -TEST_P(MapImplTest, IteratorBasic) { +TEST_F(MapImplTest, IteratorBasic) { map_[0] = 0; // Default constructible (per forward iterator requirements). @@ -320,10 +317,9 @@ static int k2 = 1321555333; // A naive begin() implementation will cause begin() to get slower and slower // if one erases elements at the "front" of the hash map, and we'd like to // avoid that, as std::unordered_map does. -TEST_P(MapImplTest, BeginIsFast) { - // Disable this test for both new and old implementations. - if (/*GetParam()*/true) return; - Map map(false); // This test uses new-style maps only. +TEST_F(MapImplTest, BeginIsFast) { + if (true) return; // TODO(gpike): make this less flaky and re-enable it. + Map map; const int kTestSize = 250000; // Create a random-looking map of size n. Use non-negative integer keys. uint32 frog = 123983; @@ -371,7 +367,7 @@ TEST_P(MapImplTest, BeginIsFast) { // Try to create kTestSize keys that will land in just a few buckets, and // time the insertions, to get a rough estimate of whether an O(n^2) worst case // was triggered. This test is a hacky, but probably better than nothing. -TEST_P(MapImplTest, HashFlood) { +TEST_F(MapImplTest, HashFlood) { const int kTestSize = 1024; // must be a power of 2 std::set s; for (int i = 0; s.size() < kTestSize; i++) { @@ -404,6 +400,22 @@ TEST_P(MapImplTest, HashFlood) { EXPECT_LE(x1, x0 * 20); } +TEST_F(MapImplTest, CopyIteratorStressTest) { + std::vector::iterator> v; + const int kIters = 1e5; + for (uint32 i = 0; i < kIters; i++) { + int32 key = (3 + i * (5 + i * (-8 + i * (62 + i)))) & 0x77777777; + map_[key] = i; + v.push_back(map_.find(key)); + } + for (std::vector::iterator>::const_iterator it = v.begin(); + it != v.end(); it++) { + Map::iterator i = *it; + ASSERT_EQ(i->first, (*it)->first); + ASSERT_EQ(i->second, (*it)->second); + } +} + template static void TestValidityForAllKeysExcept(int key_to_avoid, const T& check_map, @@ -468,11 +480,11 @@ static void TestOldVersusNewIterator(int skip, Map* m) { } // Create and test an n-element Map, with emphasis on iterator correctness. -static void StressTestIterators(int n, bool test_old_style_proto2_maps) { +static void StressTestIterators(int n) { GOOGLE_LOG(INFO) << "StressTestIterators " << n; GOOGLE_CHECK_GT(n, 0); // Create a random-looking map of size n. Use non-negative integer keys. - Map m(test_old_style_proto2_maps); + Map m; uint32 frog = 123987 + n; int last_key = 0; int counter = 0; @@ -530,10 +542,7 @@ static void StressTestIterators(int n, bool test_old_style_proto2_maps) { } } -TEST_P(MapImplTest, IteratorInvalidation) { - // As multiple underlying hash_map implementations do not follow the - // validation requirement, the test is disabled for old-style maps. - if (GetParam()) return; +TEST_F(MapImplTest, IteratorInvalidation) { // Create a set of pseudo-random sizes to test. #ifndef NDEBUG const int kMaxSizeToTest = 100 * 1000; @@ -555,15 +564,12 @@ TEST_P(MapImplTest, IteratorInvalidation) { s.insert(3); // Now, the real work. for (std::set::iterator i = s.begin(); i != s.end(); ++i) { - StressTestIterators(*i, GetParam()); + StressTestIterators(*i); } } // Test that erase() revalidates iterators. -TEST_P(MapImplTest, EraseRevalidates) { - // As multiple underlying hash_map implementations do not follow the - // validation requirement, the test is disabled for old-style maps. - if (GetParam()) return; +TEST_F(MapImplTest, EraseRevalidates) { map_[3] = map_[13] = map_[20] = 0; const int initial_size = map_.size(); EXPECT_EQ(3, initial_size); @@ -595,7 +601,7 @@ bool IsConstHelper(const T& /*t*/) { return true; } -TEST_P(MapImplTest, IteratorConstness) { +TEST_F(MapImplTest, IteratorConstness) { map_[0] = 0; EXPECT_TRUE(IsConstHelper(*map_.cbegin())); EXPECT_TRUE(IsConstHelper(*const_map_.begin())); @@ -608,14 +614,14 @@ bool IsForwardIteratorHelper(T /*t*/) { return false; } -TEST_P(MapImplTest, IteratorCategory) { +TEST_F(MapImplTest, IteratorCategory) { EXPECT_TRUE(IsForwardIteratorHelper( std::iterator_traits::iterator>::iterator_category())); EXPECT_TRUE(IsForwardIteratorHelper(std::iterator_traits< Map::const_iterator>::iterator_category())); } -TEST_P(MapImplTest, InsertSingle) { +TEST_F(MapImplTest, InsertSingle) { int32 key = 0; int32 value1 = 100; int32 value2 = 101; @@ -640,7 +646,7 @@ TEST_P(MapImplTest, InsertSingle) { EXPECT_FALSE(result2.second); } -TEST_P(MapImplTest, InsertByIterator) { +TEST_F(MapImplTest, InsertByIterator) { int32 key1 = 0; int32 key2 = 1; int32 value1a = 100; @@ -663,7 +669,7 @@ TEST_P(MapImplTest, InsertByIterator) { ExpectElements(map1); } -TEST_P(MapImplTest, EraseSingleByKey) { +TEST_F(MapImplTest, EraseSingleByKey) { int32 key = 0; int32 value = 100; @@ -681,7 +687,7 @@ TEST_P(MapImplTest, EraseSingleByKey) { EXPECT_EQ(0, map_.erase(key)); } -TEST_P(MapImplTest, EraseMutipleByKey) { +TEST_F(MapImplTest, EraseMutipleByKey) { // erase in one specific order to trigger corner cases for (int i = 0; i < 5; i++) { map_[i] = i; @@ -708,7 +714,7 @@ TEST_P(MapImplTest, EraseMutipleByKey) { EXPECT_TRUE(map_.end() == map_.find(2)); } -TEST_P(MapImplTest, EraseSingleByIterator) { +TEST_F(MapImplTest, EraseSingleByIterator) { int32 key = 0; int32 value = 100; @@ -723,7 +729,7 @@ TEST_P(MapImplTest, EraseSingleByIterator) { EXPECT_TRUE(map_.begin() == map_.end()); } -TEST_P(MapImplTest, ValidIteratorAfterErase) { +TEST_F(MapImplTest, ValidIteratorAfterErase) { for (int i = 0; i < 10; i++) { map_[i] = i; } @@ -743,7 +749,7 @@ TEST_P(MapImplTest, ValidIteratorAfterErase) { EXPECT_EQ(5, map_.size()); } -TEST_P(MapImplTest, EraseByIterator) { +TEST_F(MapImplTest, EraseByIterator) { int32 key1 = 0; int32 key2 = 1; int32 value1 = 100; @@ -764,7 +770,7 @@ TEST_P(MapImplTest, EraseByIterator) { EXPECT_TRUE(map_.begin() == map_.end()); } -TEST_P(MapImplTest, Clear) { +TEST_F(MapImplTest, Clear) { int32 key = 0; int32 value = 100; @@ -798,16 +804,16 @@ static void CopyConstructorHelper(Arena* arena, Map* m) { EXPECT_EQ(value2, other.at(key2)); } -TEST_P(MapImplTest, CopyConstructorWithArena) { +TEST_F(MapImplTest, CopyConstructorWithArena) { Arena a; CopyConstructorHelper(&a, &map_); } -TEST_P(MapImplTest, CopyConstructorWithoutArena) { +TEST_F(MapImplTest, CopyConstructorWithoutArena) { CopyConstructorHelper(NULL, &map_); } -TEST_P(MapImplTest, IterConstructor) { +TEST_F(MapImplTest, IterConstructor) { int32 key1 = 0; int32 key2 = 1; int32 value1 = 100; @@ -817,15 +823,14 @@ TEST_P(MapImplTest, IterConstructor) { map[key1] = value1; map[key2] = value2; - Map new_map(map.begin(), map.end(), - GetParam()); + Map new_map(map.begin(), map.end()); EXPECT_EQ(2, new_map.size()); EXPECT_EQ(value1, new_map.at(key1)); EXPECT_EQ(value2, new_map.at(key2)); } -TEST_P(MapImplTest, Assigner) { +TEST_F(MapImplTest, Assigner) { int32 key1 = 0; int32 key2 = 1; int32 value1 = 100; @@ -837,7 +842,7 @@ TEST_P(MapImplTest, Assigner) { map_.insert(map.begin(), map.end()); - Map other(GetParam()); + Map other; int32 key_other = 123; int32 value_other = 321; other[key_other] = value_other; @@ -855,16 +860,9 @@ TEST_P(MapImplTest, Assigner) { EXPECT_EQ(2, other.size()); EXPECT_EQ(value1, other.at(key1)); EXPECT_EQ(value2, other.at(key2)); - - // Try assignment to a map with a different choice of "style." - Map m(!GetParam()); - m = other; - EXPECT_EQ(2, m.size()); - EXPECT_EQ(value1, m.at(key1)); - EXPECT_EQ(value2, m.at(key2)); } -TEST_P(MapImplTest, Rehash) { +TEST_F(MapImplTest, Rehash) { const int test_size = 50; std::map reference_map; for (int i = 0; i < test_size; i++) { @@ -881,7 +879,7 @@ TEST_P(MapImplTest, Rehash) { EXPECT_TRUE(map_.empty()); } -TEST_P(MapImplTest, EqualRange) { +TEST_F(MapImplTest, EqualRange) { int key = 100, key_missing = 101; map_[key] = 100; @@ -905,14 +903,14 @@ TEST_P(MapImplTest, EqualRange) { EXPECT_TRUE(const_map_.end() == const_range.second); } -TEST_P(MapImplTest, ConvertToStdMap) { +TEST_F(MapImplTest, ConvertToStdMap) { map_[100] = 101; std::map std_map(map_.begin(), map_.end()); EXPECT_EQ(1, std_map.size()); EXPECT_EQ(101, std_map[100]); } -TEST_P(MapImplTest, ConvertToStdVectorOfPairs) { +TEST_F(MapImplTest, ConvertToStdVectorOfPairs) { map_[100] = 101; std::vector > std_vec(map_.begin(), map_.end()); EXPECT_EQ(1, std_vec.size()); @@ -920,8 +918,8 @@ TEST_P(MapImplTest, ConvertToStdVectorOfPairs) { EXPECT_EQ(101, std_vec[0].second); } -TEST_P(MapImplTest, SwapSameStyle) { - Map another(GetParam()); // same old_style_ value +TEST_F(MapImplTest, SwapBasic) { + Map another; map_[9398] = 41999; another[9398] = 41999; another[8070] = 42056; @@ -933,23 +931,10 @@ TEST_P(MapImplTest, SwapSameStyle) { testing::Pair(9398, 41999))); } -TEST_P(MapImplTest, SwapDifferentStyle) { - Map another(!GetParam()); // different old_style_ value - map_[9398] = 41999; - another[9398] = 41999; - another[8070] = 42056; - another.swap(map_); - EXPECT_THAT(another, testing::UnorderedElementsAre( - testing::Pair(9398, 41999))); - EXPECT_THAT(map_, testing::UnorderedElementsAre( - testing::Pair(8070, 42056), - testing::Pair(9398, 41999))); -} - -TEST_P(MapImplTest, SwapArena) { +TEST_F(MapImplTest, SwapArena) { Arena arena1, arena2; - Map m1(&arena1, false); - Map m2(&arena2, false); + Map m1(&arena1); + Map m2(&arena2); map_[9398] = 41999; m1[9398] = 41999; m1[8070] = 42056; @@ -969,8 +954,6 @@ TEST_P(MapImplTest, SwapArena) { testing::Pair(9398, 41999))); } -INSTANTIATE_TEST_CASE_P(BoolSequence, MapImplTest, testing::Bool()); - // Map Field Reflection Test ======================================== static int Func(int i, int j) { @@ -992,6 +975,11 @@ static int Int(const string& value) { class MapFieldReflectionTest : public testing::Test { protected: typedef FieldDescriptor FD; + + int MapSize(const Reflection* reflection, const FieldDescriptor* field, + const Message& message) { + return reflection->MapSize(message, field); + } }; TEST_F(MapFieldReflectionTest, RegularFields) { @@ -1799,6 +1787,50 @@ TEST_F(MapFieldReflectionTest, RepeatedFieldRefMergeFromAndSwap) { // TODO(teboring): add test for duplicated key } +TEST_F(MapFieldReflectionTest, MapSizeWithDuplicatedKey) { + // Dynamic Message + { + DynamicMessageFactory factory; + google::protobuf::scoped_ptr message( + factory.GetPrototype(unittest::TestMap::descriptor())->New()); + const Reflection* reflection = message->GetReflection(); + const FieldDescriptor* field = + unittest::TestMap::descriptor()->FindFieldByName("map_int32_int32"); + + Message* entry1 = reflection->AddMessage(message.get(), field); + Message* entry2 = reflection->AddMessage(message.get(), field); + + const Reflection* entry_reflection = entry1->GetReflection(); + const FieldDescriptor* key_field = + entry1->GetDescriptor()->FindFieldByName("key"); + entry_reflection->SetInt32(entry1, key_field, 1); + entry_reflection->SetInt32(entry2, key_field, 1); + + EXPECT_EQ(2, reflection->FieldSize(*message, field)); + EXPECT_EQ(1, MapSize(reflection, field, *message)); + } + + // Generated Message + { + unittest::TestMap message; + const Reflection* reflection = message.GetReflection(); + const FieldDescriptor* field = + message.GetDescriptor()->FindFieldByName("map_int32_int32"); + + Message* entry1 = reflection->AddMessage(&message, field); + Message* entry2 = reflection->AddMessage(&message, field); + + const Reflection* entry_reflection = entry1->GetReflection(); + const FieldDescriptor* key_field = + entry1->GetDescriptor()->FindFieldByName("key"); + entry_reflection->SetInt32(entry1, key_field, 1); + entry_reflection->SetInt32(entry2, key_field, 1); + + EXPECT_EQ(2, reflection->FieldSize(message, field)); + EXPECT_EQ(1, MapSize(reflection, field, message)); + } +} + // Generated Message Test =========================================== TEST(GeneratedMapFieldTest, Accessors) { @@ -2706,6 +2738,69 @@ TEST_F(MapFieldInDynamicMessageTest, RecursiveMap) { ASSERT_TRUE(to->ParseFromString(data)); } +TEST_F(MapFieldInDynamicMessageTest, MapValueReferernceValidAfterSerialize) { + google::protobuf::scoped_ptr message(map_prototype_->New()); + MapReflectionTester reflection_tester(map_descriptor_); + reflection_tester.SetMapFieldsViaMapReflection(message.get()); + + // Get value reference before serialization, so that we know the value is from + // map. + MapKey map_key; + MapValueRef map_val; + map_key.SetInt32Value(0); + reflection_tester.GetMapValueViaMapReflection( + message.get(), "map_int32_foreign_message", map_key, &map_val); + Message* submsg = map_val.MutableMessageValue(); + + // In previous implementation, calling SerializeToString will cause syncing + // from map to repeated field, which will invalidate the submsg we previously + // got. + string data; + message->SerializeToString(&data); + + const Reflection* submsg_reflection = submsg->GetReflection(); + const Descriptor* submsg_desc = submsg->GetDescriptor(); + const FieldDescriptor* submsg_field = submsg_desc->FindFieldByName("c"); + submsg_reflection->SetInt32(submsg, submsg_field, 128); + + message->SerializeToString(&data); + TestMap to; + to.ParseFromString(data); + EXPECT_EQ(128, to.map_int32_foreign_message().at(0).c()); +} + +TEST_F(MapFieldInDynamicMessageTest, MapEntryReferernceValidAfterSerialize) { + google::protobuf::scoped_ptr message(map_prototype_->New()); + MapReflectionTester reflection_tester(map_descriptor_); + reflection_tester.SetMapFieldsViaReflection(message.get()); + + // Get map entry before serialization, so that we know the it is from + // repeated field. + Message* map_entry = reflection_tester.GetMapEntryViaReflection( + message.get(), "map_int32_foreign_message", 0); + const Reflection* map_entry_reflection = map_entry->GetReflection(); + const Descriptor* map_entry_desc = map_entry->GetDescriptor(); + const FieldDescriptor* value_field = map_entry_desc->FindFieldByName("value"); + Message* submsg = + map_entry_reflection->MutableMessage(map_entry, value_field); + + // In previous implementation, calling SerializeToString will cause syncing + // from repeated field to map, which will invalidate the map_entry we + // previously got. + string data; + message->SerializeToString(&data); + + const Reflection* submsg_reflection = submsg->GetReflection(); + const Descriptor* submsg_desc = submsg->GetDescriptor(); + const FieldDescriptor* submsg_field = submsg_desc->FindFieldByName("c"); + submsg_reflection->SetInt32(submsg, submsg_field, 128); + + message->SerializeToString(&data); + TestMap to; + to.ParseFromString(data); + EXPECT_EQ(128, to.map_int32_foreign_message().at(0).c()); +} + // ReflectionOps Test =============================================== TEST(ReflectionOpsForMapFieldTest, MapSanityCheck) { @@ -2768,6 +2863,20 @@ TEST(ReflectionOpsForMapFieldTest, MapDiscardUnknownFields) { GetUnknownFields(message).field_count()); } +TEST(ReflectionOpsForMapFieldTest, IsInitialized) { + unittest::TestRequiredMessageMap map_message; + + // Add an uninitialized message. + (*map_message.mutable_map_field())[0]; + EXPECT_FALSE(ReflectionOps::IsInitialized(map_message)); + + // Initialize uninitialized message + (*map_message.mutable_map_field())[0].set_a(0); + (*map_message.mutable_map_field())[0].set_b(0); + (*map_message.mutable_map_field())[0].set_c(0); + EXPECT_TRUE(ReflectionOps::IsInitialized(map_message)); +} + // Wire Format Test ================================================= TEST(WireFormatForMapFieldTest, ParseMap) { @@ -2828,6 +2937,33 @@ TEST(WireFormatForMapFieldTest, SerializeMap) { EXPECT_TRUE(dynamic_data == generated_data); } +TEST(WireFormatForMapFieldTest, SerializeMapDynamicMessage) { + DynamicMessageFactory factory; + google::protobuf::scoped_ptr dynamic_message; + dynamic_message.reset( + factory.GetPrototype(unittest::TestMap::descriptor())->New()); + MapReflectionTester reflection_tester( + unittest::TestMap::descriptor()); + reflection_tester.SetMapFieldsViaReflection(dynamic_message.get()); + reflection_tester.ExpectMapFieldsSetViaReflection(*dynamic_message); + + unittest::TestMap generated_message; + MapTestUtil::SetMapFields(&generated_message); + MapTestUtil::ExpectMapFieldsSet(generated_message); + + string generated_data; + string dynamic_data; + + // Serialize. + generated_message.SerializeToString(&generated_data); + dynamic_message->SerializeToString(&dynamic_data); + + // Because map serialization doesn't guarantee order, we just compare + // serialized size here. This is enough to tell dynamic message doesn't miss + // anything in serialization. + EXPECT_TRUE(dynamic_data.size() == generated_data.size()); +} + TEST(WireFormatForMapFieldTest, MapParseHelpers) { string data; @@ -2980,6 +3116,27 @@ TEST(MapSerializationTest, Deterministic) { TestDeterministicSerialization(t, "golden_message_maps"); } +TEST(MapSerializationTest, DeterministicSubmessage) { + protobuf_unittest::TestSubmessageMaps p; + protobuf_unittest::TestMaps t; + const string filename = "golden_message_maps"; + string golden; + GOOGLE_CHECK_OK(File::GetContents( + TestSourceDir() + "/google/protobuf/testdata/" + filename, + &golden, true)); + t.ParseFromString(golden); + *(p.mutable_m()) = t; + std::vector v; + // Use multiple attempts to increase the chance of a failure if something is + // buggy. For example, each separate copy of a map might use a different + // randomly-chosen hash function. + const int kAttempts = 10; + for (int i = 0; i < kAttempts; i++) { + protobuf_unittest::TestSubmessageMaps q(p); + ASSERT_EQ(DeterministicSerialization(q), DeterministicSerialization(p)); + } +} + // Text Format Test ================================================= TEST(TextFormatMapTest, SerializeAndParse) { @@ -3058,7 +3215,7 @@ TEST(ArenaTest, ParsingAndSerializingNoHeapAllocation) { } // Use text format parsing and serializing to test reflection api. -TEST(ArenaTest, RelfectionInTextFormat) { +TEST(ArenaTest, ReflectionInTextFormat) { Arena arena; string data; diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/map_test_util.cc b/third_party/protobuf/3.2.0/src/google/protobuf/map_test_util.cc index 3dd6aae555..4d3ad6092f 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/map_test_util.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/map_test_util.cc @@ -744,6 +744,22 @@ void MapReflectionTester::SetMapFieldsViaMapReflection( sub_foreign_message, foreign_c_, 1); } +void MapReflectionTester::GetMapValueViaMapReflection(Message* message, + const string& field_name, + const MapKey& map_key, + MapValueRef* map_val) { + const Reflection* reflection = message->GetReflection(); + EXPECT_FALSE(reflection->InsertOrLookupMapValue(message, F(field_name), + map_key, map_val)); +} + +Message* MapReflectionTester::GetMapEntryViaReflection(Message* message, + const string& field_name, + int index) { + const Reflection* reflection = message->GetReflection(); + return reflection->MutableRepeatedMessage(message, F(field_name), index); +} + void MapReflectionTester::ClearMapFieldsViaReflection( Message* message) { const Reflection* reflection = message->GetReflection(); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/map_test_util.h b/third_party/protobuf/3.2.0/src/google/protobuf/map_test_util.h index deaf0f4f4b..15c6c28946 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/map_test_util.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/map_test_util.h @@ -106,6 +106,11 @@ class MapReflectionTester { void ExpectClearViaReflection(const Message& message); void ExpectClearViaReflectionIterator(Message* message); void ExpectMapEntryClearViaReflection(Message* message); + void GetMapValueViaMapReflection(Message* message, + const string& field_name, + const MapKey& map_key, MapValueRef* map_val); + Message* GetMapEntryViaReflection(Message* message, const string& field_name, + int index); private: const FieldDescriptor* F(const string& name); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/map_test_util_impl.h b/third_party/protobuf/3.2.0/src/google/protobuf/map_test_util_impl.h index b3ba4e0699..ad4d1a3dd3 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/map_test_util_impl.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/map_test_util_impl.h @@ -33,14 +33,9 @@ #include #include +#include -#define EXPECT_TRUE GOOGLE_CHECK -#define ASSERT_TRUE GOOGLE_CHECK -#define EXPECT_FALSE(COND) GOOGLE_CHECK(!(COND)) -#define EXPECT_EQ GOOGLE_CHECK_EQ -#define ASSERT_EQ GOOGLE_CHECK_EQ - namespace google { namespace protobuf_unittest {} // forward declaration @@ -265,23 +260,23 @@ void MapTestUtilImpl::ExpectClear(const MapMessage& message) { template void MapTestUtilImpl::ExpectMapFieldsSet(const MapMessage& message) { - EXPECT_EQ(2, message.map_int32_int32().size()); - EXPECT_EQ(2, message.map_int64_int64().size()); - EXPECT_EQ(2, message.map_uint32_uint32().size()); - EXPECT_EQ(2, message.map_uint64_uint64().size()); - EXPECT_EQ(2, message.map_sint32_sint32().size()); - EXPECT_EQ(2, message.map_sint64_sint64().size()); - EXPECT_EQ(2, message.map_fixed32_fixed32().size()); - EXPECT_EQ(2, message.map_fixed64_fixed64().size()); - EXPECT_EQ(2, message.map_sfixed32_sfixed32().size()); - EXPECT_EQ(2, message.map_sfixed64_sfixed64().size()); - EXPECT_EQ(2, message.map_int32_float().size()); - EXPECT_EQ(2, message.map_int32_double().size()); - EXPECT_EQ(2, message.map_bool_bool().size()); - EXPECT_EQ(2, message.map_string_string().size()); - EXPECT_EQ(2, message.map_int32_bytes().size()); - EXPECT_EQ(2, message.map_int32_enum().size()); - EXPECT_EQ(2, message.map_int32_foreign_message().size()); + ASSERT_EQ(2, message.map_int32_int32().size()); + ASSERT_EQ(2, message.map_int64_int64().size()); + ASSERT_EQ(2, message.map_uint32_uint32().size()); + ASSERT_EQ(2, message.map_uint64_uint64().size()); + ASSERT_EQ(2, message.map_sint32_sint32().size()); + ASSERT_EQ(2, message.map_sint64_sint64().size()); + ASSERT_EQ(2, message.map_fixed32_fixed32().size()); + ASSERT_EQ(2, message.map_fixed64_fixed64().size()); + ASSERT_EQ(2, message.map_sfixed32_sfixed32().size()); + ASSERT_EQ(2, message.map_sfixed64_sfixed64().size()); + ASSERT_EQ(2, message.map_int32_float().size()); + ASSERT_EQ(2, message.map_int32_double().size()); + ASSERT_EQ(2, message.map_bool_bool().size()); + ASSERT_EQ(2, message.map_string_string().size()); + ASSERT_EQ(2, message.map_int32_bytes().size()); + ASSERT_EQ(2, message.map_int32_enum().size()); + ASSERT_EQ(2, message.map_int32_foreign_message().size()); EXPECT_EQ(0, message.map_int32_int32().at(0)); EXPECT_EQ(0, message.map_int64_int64().at(0)); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/map_type_handler.h b/third_party/protobuf/3.2.0/src/google/protobuf/map_type_handler.h index ac987cbc1c..301b37fed8 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/map_type_handler.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/map_type_handler.h @@ -186,9 +186,9 @@ class MapTypeHandler { static inline Type* EnsureMutable(Type** value, Arena* arena); // SpaceUsedInMapEntry: Return bytes used by value in MapEntry, excluding // those already calculate in sizeof(MapField). - static inline int SpaceUsedInMapEntry(const Type* value); + static inline size_t SpaceUsedInMapEntryLong(const Type* value); // Return bytes used by value in Map. - static inline int SpaceUsedInMap(const Type& value); + static inline size_t SpaceUsedInMapLong(const Type& value); // Assign default value to given instance. static inline void AssignDefaultValue(Type** value); // Return default instance if value is not initialized when calling const @@ -224,9 +224,7 @@ class MapTypeHandler { static inline void Write(int field, const MapEntryAccessorType& value, \ io::CodedOutputStream* output); \ static inline uint8* InternalWriteToArray( \ - int field, \ - const MapEntryAccessorType& value, \ - bool deterministic, \ + int field, const MapEntryAccessorType& value, bool deterministic, \ uint8* target); \ static inline uint8* WriteToArray(int field, \ const MapEntryAccessorType& value, \ @@ -242,9 +240,9 @@ class MapTypeHandler { static inline void ClearMaybeByDefaultEnum(TypeOnMemory* value, \ Arena* arena, \ int default_enum); \ - static inline int SpaceUsedInMapEntry(const TypeOnMemory& value); \ - static inline int SpaceUsedInMap(const TypeOnMemory& value); \ - static inline int SpaceUsedInMap(const string& value); \ + static inline size_t SpaceUsedInMapEntryLong(const TypeOnMemory& value); \ + static inline size_t SpaceUsedInMapLong(const TypeOnMemory& value); \ + static inline size_t SpaceUsedInMapLong(const string& value); \ static inline void AssignDefaultValue(TypeOnMemory* value); \ static inline const MapEntryAccessorType& DefaultIfNotInitialized( \ const TypeOnMemory& value, const TypeOnMemory& default_value); \ @@ -467,16 +465,15 @@ MapTypeHandler -inline int -MapTypeHandler::SpaceUsedInMapEntry(const Type* value) { - return value->SpaceUsed(); +inline size_t MapTypeHandler::SpaceUsedInMapEntryLong(const Type* value) { + return value->SpaceUsedLong(); } template -int MapTypeHandler::SpaceUsedInMap( +size_t MapTypeHandler::SpaceUsedInMapLong( const Type& value) { - return value.SpaceUsed(); + return value.SpaceUsedLong(); } template @@ -507,7 +504,7 @@ void MapTypeHandler::DeleteNoArena( template inline void MapTypeHandler::AssignDefaultValue(Type** value) { - *value = const_cast(&Type::default_instance()); + *value = const_cast(Type::internal_default_instance()); } template @@ -559,19 +556,21 @@ inline bool MapTypeHandler \ - inline int \ - MapTypeHandler::SpaceUsedInMapEntry( \ - const TypeOnMemory& value) { \ + inline size_t \ + MapTypeHandler::SpaceUsedInMapEntryLong(const TypeOnMemory& value) { \ return sizeof(value); \ } \ template \ - inline int MapTypeHandler::SpaceUsedInMap(const TypeOnMemory& value) { \ + inline size_t \ + MapTypeHandler::SpaceUsedInMapLong( \ + const TypeOnMemory& value) { \ return sizeof(value); \ } \ template \ - inline int MapTypeHandler::SpaceUsedInMap(const string& value) { \ + inline size_t \ + MapTypeHandler::SpaceUsedInMapLong( \ + const string& value) { \ return sizeof(value); \ } \ template \ @@ -647,14 +646,15 @@ STRING_OR_BYTES_HANDLER_FUNCTIONS(BYTES) return value; \ } \ template \ - inline int \ - MapTypeHandler::SpaceUsedInMapEntry( \ - const TypeOnMemory& value) { \ + inline size_t \ + MapTypeHandler::SpaceUsedInMapEntryLong(const TypeOnMemory& value) { \ return 0; \ } \ template \ - inline int MapTypeHandler::SpaceUsedInMap(const TypeOnMemory& value) { \ + inline size_t \ + MapTypeHandler::SpaceUsedInMapLong( \ + const TypeOnMemory& value) { \ return sizeof(Type); \ } \ template \ @@ -663,11 +663,9 @@ STRING_OR_BYTES_HANDLER_FUNCTIONS(BYTES) *value = 0; \ } \ template \ - inline void \ - MapTypeHandler::ClearMaybeByDefaultEnum(TypeOnMemory* value, \ - Arena* arena, \ - int default_enum_value) { \ + inline void MapTypeHandler:: \ + ClearMaybeByDefaultEnum(TypeOnMemory* value, Arena* arena, \ + int default_enum_value) { \ *value = static_cast(default_enum_value); \ } \ template \ @@ -688,11 +686,9 @@ STRING_OR_BYTES_HANDLER_FUNCTIONS(BYTES) *value = 0; \ } \ template \ - inline void \ - MapTypeHandler::InitializeMaybeByDefaultEnum(TypeOnMemory* value, \ - int default_enum_value, \ - Arena* arena) { \ + inline void MapTypeHandler:: \ + InitializeMaybeByDefaultEnum(TypeOnMemory* value, \ + int default_enum_value, Arena* arena) { \ *value = static_cast(default_enum_value); \ } \ template \ diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/message.cc b/third_party/protobuf/3.2.0/src/google/protobuf/message.cc index 6800e4cd55..2134f95f1c 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/message.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/message.cc @@ -158,8 +158,8 @@ void Message::SetCachedSize(int /* size */) const { "Must implement one or the other."; } -int Message::SpaceUsed() const { - return GetReflection()->SpaceUsed(*this); +size_t Message::SpaceUsedLong() const { + return GetReflection()->SpaceUsedLong(*this); } bool Message::SerializeToFileDescriptor(int file_descriptor) const { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/message.h b/third_party/protobuf/3.2.0/src/google/protobuf/message.h index 4d14584ddb..68acb5b13e 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/message.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/message.h @@ -154,6 +154,13 @@ class MapReflectionFriend; // scalar_map_container.h } +namespace internal { +class ReflectionOps; // reflection_ops.h +class MapKeySorter; // wire_format.cc +class WireFormat; // wire_format.h +class MapFieldReflectionTest; // map_test.cc +} + template class RepeatedField; // repeated_field.h @@ -245,7 +252,9 @@ class LIBPROTOBUF_EXPORT Message : public MessageLite { // using reflection (rather than the generated code implementation for // ByteSize()). Like ByteSize(), its CPU time is linear in the number of // fields defined for the proto. - virtual int SpaceUsed() const; + virtual size_t SpaceUsedLong() const; + + int SpaceUsed() const { return internal::ToIntSize(SpaceUsedLong()); } // Debugging & Testing---------------------------------------------- @@ -417,7 +426,11 @@ class LIBPROTOBUF_EXPORT Reflection { virtual UnknownFieldSet* MutableUnknownFields(Message* message) const = 0; // Estimate the amount of memory used by the message object. - virtual int SpaceUsed(const Message& message) const = 0; + virtual size_t SpaceUsedLong(const Message& message) const = 0; + + int SpaceUsed(const Message& message) const { + return internal::ToIntSize(SpaceUsedLong(message)); + } // Check if the given non-repeated field is set. virtual bool HasField(const Message& message, @@ -930,6 +943,10 @@ class LIBPROTOBUF_EXPORT Reflection { template friend class MutableRepeatedFieldRef; friend class ::google::protobuf::python::MapReflectionFriend; + friend class internal::MapFieldReflectionTest; + friend class internal::MapKeySorter; + friend class internal::WireFormat; + friend class internal::ReflectionOps; // Special version for specialized implementations of string. We can't call // MutableRawRepeatedField directly here because we don't have access to diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/message_lite.cc b/third_party/protobuf/3.2.0/src/google/protobuf/message_lite.cc index b8cb3f4c46..fda84b516f 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/message_lite.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/message_lite.cc @@ -222,6 +222,11 @@ bool MessageLite::ParsePartialFromArray(const void* data, int size) { // =================================================================== +uint8* MessageLite::SerializeWithCachedSizesToArray(uint8* target) const { + return InternalSerializeWithCachedSizesToArray( + io::CodedOutputStream::IsDefaultSerializationDeterministic(), target); +} + uint8* MessageLite::InternalSerializeWithCachedSizesToArray( bool deterministic, uint8* target) const { // We only optimize this when using optimize_for = SPEED. In other cases diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/message_lite.h b/third_party/protobuf/3.2.0/src/google/protobuf/message_lite.h index 5e5ed30681..046a736dc3 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/message_lite.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/message_lite.h @@ -42,6 +42,7 @@ #include #include #include +#include namespace google { @@ -248,11 +249,7 @@ class LIBPROTOBUF_EXPORT MessageLite { virtual size_t ByteSizeLong() const = 0; // Legacy ByteSize() API. - int ByteSize() const { - size_t result = ByteSizeLong(); - GOOGLE_DCHECK_LE(result, static_cast(INT_MAX)); - return static_cast(result); - } + int ByteSize() const { return internal::ToIntSize(ByteSizeLong()); } // Serializes the message without recomputing the size. The message must not // have changed since the last call to ByteSize(), and the value returned by @@ -260,11 +257,17 @@ class LIBPROTOBUF_EXPORT MessageLite { virtual void SerializeWithCachedSizes( io::CodedOutputStream* output) const = 0; - // A version of SerializeWithCachedSizesToArray, below, that does - // not guarantee deterministic serialization. - virtual uint8* SerializeWithCachedSizesToArray(uint8* target) const { - return InternalSerializeWithCachedSizesToArray(false, target); - } + // Functions below here are not part of the public interface. It isn't + // enforced, but they should be treated as private, and will be private + // at some future time. Unfortunately the implementation of the "friend" + // keyword in GCC is broken at the moment, but we expect it will be fixed. + + // Like SerializeWithCachedSizes, but writes directly to *target, returning + // a pointer to the byte immediately after the last byte written. "target" + // must point at a byte array of at least ByteSize() bytes. Whether to use + // deterministic serialization, e.g., maps in sorted order, is determined by + // CodedOutputStream::IsDefaultSerializationDeterministic(). + virtual uint8* SerializeWithCachedSizesToArray(uint8* target) const; // Returns the result of the last call to ByteSize(). An embedded message's // size is needed both to serialize it (because embedded messages are @@ -279,16 +282,6 @@ class LIBPROTOBUF_EXPORT MessageLite { // method.) virtual int GetCachedSize() const = 0; - // Functions below here are not part of the public interface. It isn't - // enforced, but they should be treated as private, and will be private - // at some future time. Unfortunately the implementation of the "friend" - // keyword in GCC is broken at the moment, but we expect it will be fixed. - - // Like SerializeWithCachedSizes, but writes directly to *target, returning - // a pointer to the byte immediately after the last byte written. "target" - // must point at a byte array of at least ByteSize() bytes. If deterministic - // is true then we use deterministic serialization, e.g., map keys are sorted. - // FOR INTERNAL USE ONLY! virtual uint8* InternalSerializeWithCachedSizesToArray(bool deterministic, uint8* target) const; diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/message_unittest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/message_unittest.cc index 2bbfe40a27..41cb3d65c0 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/message_unittest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/message_unittest.cc @@ -37,9 +37,7 @@ #include #include #include -#ifdef _MSC_VER -#include -#else +#ifndef _MSC_VER #include #endif #include @@ -64,6 +62,13 @@ namespace google { namespace protobuf { +#if defined(_WIN32) +// DO NOT include , instead create functions in io_win32.{h,cc} and import +// them like we do below. +using google::protobuf::stubs::close; +using google::protobuf::stubs::open; +#endif + #ifndef O_BINARY #ifdef _O_BINARY #define O_BINARY _O_BINARY @@ -552,6 +557,17 @@ TEST(MessageTest, MergeFrom) { ASSERT_EQ(0, dest.repeated_uint64_size()); } +TEST(MessageTest, IsInitialized) { + protobuf_unittest::TestIsInitialized msg; + EXPECT_TRUE(msg.IsInitialized()); + protobuf_unittest::TestIsInitialized::SubMessage* sub_message = msg.mutable_sub_message(); + EXPECT_TRUE(msg.IsInitialized()); + protobuf_unittest::TestIsInitialized::SubMessage::SubGroup* sub_group = sub_message->mutable_subgroup(); + EXPECT_FALSE(msg.IsInitialized()); + sub_group->set_i(1); + EXPECT_TRUE(msg.IsInitialized()); +} + TEST(MessageFactoryTest, GeneratedFactoryLookup) { EXPECT_EQ( MessageFactory::generated_factory()->GetPrototype( diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/metadata.h b/third_party/protobuf/3.2.0/src/google/protobuf/metadata.h index dca1fa453b..0a6507c067 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/metadata.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/metadata.h @@ -38,134 +38,13 @@ #ifndef GOOGLE_PROTOBUF_METADATA_H__ #define GOOGLE_PROTOBUF_METADATA_H__ -#include -#include -#include -#include +#include #include namespace google { namespace protobuf { namespace internal { -// This is the representation for messages that support arena allocation. It -// uses a tagged pointer to either store the Arena pointer, if there are no -// unknown fields, or a pointer to a block of memory with both the Arena pointer -// and the UnknownFieldSet, if there are unknown fields. This optimization -// allows for "zero-overhead" storage of the Arena pointer, relative to the -// above baseline implementation. -// -// The tagged pointer uses the LSB to disambiguate cases, and uses bit 0 == 0 to -// indicate an arena pointer and bit 0 == 1 to indicate a UFS+Arena-container -// pointer. -template -class InternalMetadataWithArenaBase { - public: - InternalMetadataWithArenaBase() : ptr_(NULL) {} - explicit InternalMetadataWithArenaBase(Arena* arena) : ptr_(arena) {} - - ~InternalMetadataWithArenaBase() { - if (have_unknown_fields() && arena() == NULL) { - delete PtrValue(); - } - ptr_ = NULL; - } - - GOOGLE_ATTRIBUTE_ALWAYS_INLINE const T& unknown_fields() const { - if (GOOGLE_PREDICT_FALSE(have_unknown_fields())) { - return PtrValue()->unknown_fields; - } else { - return Derived::default_instance(); - } - } - - GOOGLE_ATTRIBUTE_ALWAYS_INLINE T* mutable_unknown_fields() { - if (GOOGLE_PREDICT_TRUE(have_unknown_fields())) { - return &PtrValue()->unknown_fields; - } else { - return mutable_unknown_fields_slow(); - } - } - - GOOGLE_ATTRIBUTE_ALWAYS_INLINE Arena* arena() const { - if (GOOGLE_PREDICT_FALSE(have_unknown_fields())) { - return PtrValue()->arena; - } else { - return PtrValue(); - } - } - - GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool have_unknown_fields() const { - return PtrTag() == kTagContainer; - } - - GOOGLE_ATTRIBUTE_ALWAYS_INLINE void Swap(Derived* other) { - // Semantics here are that we swap only the unknown fields, not the arena - // pointer. We cannot simply swap ptr_ with other->ptr_ because we need to - // maintain our own arena ptr. Also, our ptr_ and other's ptr_ may be in - // different states (direct arena pointer vs. container with UFS) so we - // cannot simply swap ptr_ and then restore the arena pointers. We reuse - // UFS's swap implementation instead. - if (have_unknown_fields() || other->have_unknown_fields()) { - static_cast(this)->DoSwap(other->mutable_unknown_fields()); - } - } - - GOOGLE_ATTRIBUTE_ALWAYS_INLINE void MergeFrom(const Derived& other) { - if (other.have_unknown_fields()) { - static_cast(this)->DoMergeFrom(other.unknown_fields()); - } - } - - GOOGLE_ATTRIBUTE_ALWAYS_INLINE void Clear() { - if (have_unknown_fields()) { - static_cast(this)->DoClear(); - } - } - - GOOGLE_ATTRIBUTE_ALWAYS_INLINE void* raw_arena_ptr() const { - return ptr_; - } - - private: - void* ptr_; - - // Tagged pointer implementation. - enum { - // ptr_ is an Arena*. - kTagArena = 0, - // ptr_ is a Container*. - kTagContainer = 1, - }; - static const intptr_t kPtrTagMask = 1; - static const intptr_t kPtrValueMask = ~kPtrTagMask; - - // Accessors for pointer tag and pointer value. - GOOGLE_ATTRIBUTE_ALWAYS_INLINE int PtrTag() const { - return reinterpret_cast(ptr_) & kPtrTagMask; - } - - template U* PtrValue() const { - return reinterpret_cast( - reinterpret_cast(ptr_) & kPtrValueMask); - } - - // If ptr_'s tag is kTagContainer, it points to an instance of this struct. - struct Container { - T unknown_fields; - Arena* arena; - }; - - GOOGLE_ATTRIBUTE_NOINLINE T* mutable_unknown_fields_slow() { - Arena* my_arena = arena(); - Container* container = Arena::Create(my_arena); - ptr_ = reinterpret_cast( - reinterpret_cast(container) | kTagContainer); - container->arena = my_arena; - return &(container->unknown_fields); - } -}; - class InternalMetadataWithArena : public InternalMetadataWithArenaBase { @@ -192,36 +71,6 @@ class InternalMetadataWithArena } }; -// We store unknown fields as a string right now, because there is currently no -// good interface for reading unknown fields into an ArenaString. We may want -// to revisit this to allow unknown fields to be parsed onto the Arena. -class InternalMetadataWithArenaLite - : public InternalMetadataWithArenaBase { - public: - InternalMetadataWithArenaLite() {} - - explicit InternalMetadataWithArenaLite(Arena* arena) - : InternalMetadataWithArenaBase(arena) {} - - void DoSwap(string* other) { - mutable_unknown_fields()->swap(*other); - } - - void DoMergeFrom(const string& other) { - mutable_unknown_fields()->append(other); - } - - void DoClear() { - mutable_unknown_fields()->clear(); - } - - static const string& default_instance() { - return GetEmptyStringAlreadyInited(); - } -}; - } // namespace internal } // namespace protobuf diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/metadata_lite.h b/third_party/protobuf/3.2.0/src/google/protobuf/metadata_lite.h new file mode 100644 index 0000000000..840c02e82e --- /dev/null +++ b/third_party/protobuf/3.2.0/src/google/protobuf/metadata_lite.h @@ -0,0 +1,193 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef GOOGLE_PROTOBUF_METADATA_LITE_H__ +#define GOOGLE_PROTOBUF_METADATA_LITE_H__ + +#include +#include +#include + +namespace google { +namespace protobuf { +namespace internal { + +// This is the representation for messages that support arena allocation. It +// uses a tagged pointer to either store the Arena pointer, if there are no +// unknown fields, or a pointer to a block of memory with both the Arena pointer +// and the UnknownFieldSet, if there are unknown fields. This optimization +// allows for "zero-overhead" storage of the Arena pointer, relative to the +// above baseline implementation. +// +// The tagged pointer uses the LSB to disambiguate cases, and uses bit 0 == 0 to +// indicate an arena pointer and bit 0 == 1 to indicate a UFS+Arena-container +// pointer. +template +class InternalMetadataWithArenaBase { + public: + InternalMetadataWithArenaBase() : ptr_(NULL) {} + explicit InternalMetadataWithArenaBase(Arena* arena) : ptr_(arena) {} + + ~InternalMetadataWithArenaBase() { + if (have_unknown_fields() && arena() == NULL) { + delete PtrValue(); + } + ptr_ = NULL; + } + + GOOGLE_ATTRIBUTE_ALWAYS_INLINE const T& unknown_fields() const { + if (GOOGLE_PREDICT_FALSE(have_unknown_fields())) { + return PtrValue()->unknown_fields; + } else { + return Derived::default_instance(); + } + } + + GOOGLE_ATTRIBUTE_ALWAYS_INLINE T* mutable_unknown_fields() { + if (GOOGLE_PREDICT_TRUE(have_unknown_fields())) { + return &PtrValue()->unknown_fields; + } else { + return mutable_unknown_fields_slow(); + } + } + + GOOGLE_ATTRIBUTE_ALWAYS_INLINE Arena* arena() const { + if (GOOGLE_PREDICT_FALSE(have_unknown_fields())) { + return PtrValue()->arena; + } else { + return PtrValue(); + } + } + + GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool have_unknown_fields() const { + return PtrTag() == kTagContainer; + } + + GOOGLE_ATTRIBUTE_ALWAYS_INLINE void Swap(Derived* other) { + // Semantics here are that we swap only the unknown fields, not the arena + // pointer. We cannot simply swap ptr_ with other->ptr_ because we need to + // maintain our own arena ptr. Also, our ptr_ and other's ptr_ may be in + // different states (direct arena pointer vs. container with UFS) so we + // cannot simply swap ptr_ and then restore the arena pointers. We reuse + // UFS's swap implementation instead. + if (have_unknown_fields() || other->have_unknown_fields()) { + static_cast(this)->DoSwap(other->mutable_unknown_fields()); + } + } + + GOOGLE_ATTRIBUTE_ALWAYS_INLINE void MergeFrom(const Derived& other) { + if (other.have_unknown_fields()) { + static_cast(this)->DoMergeFrom(other.unknown_fields()); + } + } + + GOOGLE_ATTRIBUTE_ALWAYS_INLINE void Clear() { + if (have_unknown_fields()) { + static_cast(this)->DoClear(); + } + } + + GOOGLE_ATTRIBUTE_ALWAYS_INLINE void* raw_arena_ptr() const { + return ptr_; + } + + private: + void* ptr_; + + // Tagged pointer implementation. + enum { + // ptr_ is an Arena*. + kTagArena = 0, + // ptr_ is a Container*. + kTagContainer = 1, + }; + static const intptr_t kPtrTagMask = 1; + static const intptr_t kPtrValueMask = ~kPtrTagMask; + + // Accessors for pointer tag and pointer value. + GOOGLE_ATTRIBUTE_ALWAYS_INLINE int PtrTag() const { + return reinterpret_cast(ptr_) & kPtrTagMask; + } + + template U* PtrValue() const { + return reinterpret_cast( + reinterpret_cast(ptr_) & kPtrValueMask); + } + + // If ptr_'s tag is kTagContainer, it points to an instance of this struct. + struct Container { + T unknown_fields; + Arena* arena; + }; + + GOOGLE_ATTRIBUTE_NOINLINE T* mutable_unknown_fields_slow() { + Arena* my_arena = arena(); + Container* container = Arena::Create(my_arena); + ptr_ = reinterpret_cast( + reinterpret_cast(container) | kTagContainer); + container->arena = my_arena; + return &(container->unknown_fields); + } +}; + +// We store unknown fields as a string right now, because there is currently no +// good interface for reading unknown fields into an ArenaString. We may want +// to revisit this to allow unknown fields to be parsed onto the Arena. +class InternalMetadataWithArenaLite + : public InternalMetadataWithArenaBase { + public: + InternalMetadataWithArenaLite() {} + + explicit InternalMetadataWithArenaLite(Arena* arena) + : InternalMetadataWithArenaBase(arena) {} + + void DoSwap(string* other) { + mutable_unknown_fields()->swap(*other); + } + + void DoMergeFrom(const string& other) { + mutable_unknown_fields()->append(other); + } + + void DoClear() { + mutable_unknown_fields()->clear(); + } + + static const string& default_instance() { + return GetEmptyStringAlreadyInited(); + } +}; + +} // namespace internal +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_METADATA_LITE_H__ diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/reflection.h b/third_party/protobuf/3.2.0/src/google/protobuf/reflection.h index d5a6653cb9..fcb9a43559 100755 --- a/third_party/protobuf/3.2.0/src/google/protobuf/reflection.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/reflection.h @@ -570,8 +570,8 @@ struct RefTypeTraits< typedef RepeatedFieldRefIterator iterator; typedef RepeatedFieldAccessor AccessorType; typedef string AccessorValueType; - typedef string IteratorValueType; - typedef string* IteratorPointerType; + typedef const string IteratorValueType; + typedef const string* IteratorPointerType; static const FieldDescriptor::CppType cpp_type = FieldDescriptor::CPPTYPE_STRING; static const Descriptor* GetMessageFieldDescriptor() { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/reflection_ops.cc b/third_party/protobuf/3.2.0/src/google/protobuf/reflection_ops.cc index bb9c7f8bff..d186731184 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/reflection_ops.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/reflection_ops.cc @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -158,6 +159,27 @@ bool ReflectionOps::IsInitialized(const Message& message) { const FieldDescriptor* field = fields[i]; if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { + if (field->is_map()) { + const FieldDescriptor* value_field = field->message_type()->field(1); + if (value_field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { + MapFieldBase* map_field = + reflection->MapData(const_cast(&message), field); + if (map_field->IsMapValid()) { + MapIterator iter(const_cast(&message), field); + MapIterator end(const_cast(&message), field); + for (map_field->MapBegin(&iter), map_field->MapEnd(&end); + iter != end; ++iter) { + if (!iter.GetValueRef().GetMessageValue().IsInitialized()) { + return false; + } + } + continue; + } + } else { + continue; + } + } + if (field->is_repeated()) { int size = reflection->FieldSize(message, field); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/reflection_ops_unittest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/reflection_ops_unittest.cc index 864531701a..9cedb34229 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/reflection_ops_unittest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/reflection_ops_unittest.cc @@ -41,6 +41,7 @@ #include #include #include + #include namespace google { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/repeated_field.h b/third_party/protobuf/3.2.0/src/google/protobuf/repeated_field.h index db5893b501..a1013f6359 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/repeated_field.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/repeated_field.h @@ -51,8 +51,9 @@ #include #endif -#include #include +#include +#include #include #include #include @@ -76,6 +77,8 @@ class Message; namespace internal { +class MergePartialFromCodedStreamHelper; + static const int kMinRepeatedFieldAllocationSize = 4; // A utility function for logging that doesn't need any template types. @@ -155,6 +158,7 @@ class RepeatedField PROTOBUF_FINAL { // The new element is uninitialized if |Element| is a POD type. // Should be called only if Capacity() > Size(). Element* AddAlreadyReserved(); + Element* AddNAlreadyReserved(int elements); int Capacity() const; // Like STL resize. Uses value to fill appended elements. @@ -216,7 +220,11 @@ class RepeatedField PROTOBUF_FINAL { // Returns the number of bytes used by the repeated field, excluding // sizeof(*this) - int SpaceUsedExcludingSelf() const; + size_t SpaceUsedExcludingSelfLong() const; + + int SpaceUsedExcludingSelf() const { + return internal::ToIntSize(SpaceUsedExcludingSelfLong()); + } // Removes the element referenced by position. // @@ -238,6 +246,11 @@ class RepeatedField PROTOBUF_FINAL { return GetArenaNoVirtual(); } + // For internal use only. + // + // This is public due to it being called by generated code. + inline void InternalSwap(RepeatedField* other); + private: static const int kInitialSize = 0; // A note on the representation here (see also comment below for @@ -276,8 +289,6 @@ class RepeatedField PROTOBUF_FINAL { // Copy the elements of |from| into |to|. void CopyArray(Element* to, const Element* from, int size); - inline void InternalSwap(RepeatedField* other); - // Internal helper expected by Arena methods. inline Arena* GetArenaNoVirtual() const { return (rep_ == NULL) ? NULL : rep_->arena; @@ -291,7 +302,7 @@ class RepeatedField PROTOBUF_FINAL { Element* e = &rep->elements[0]; Element* limit = &rep->elements[size]; for (; e < limit; e++) { - e->Element::~Element(); + e->~Element(); } if (rep->arena == NULL) { #if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation) @@ -303,6 +314,9 @@ class RepeatedField PROTOBUF_FINAL { } } } + + friend class internal::WireFormatLite; + const Element* unsafe_data() const; }; template @@ -321,7 +335,8 @@ namespace internal { // shouldn't be necessary, but our compiler doesn't optimize std::copy very // effectively. template ::value> + bool HasTrivialCopy = + has_trivial_copy::value> struct ElementCopier { void operator()(Element* to, const Element* from, int array_size); }; @@ -335,8 +350,8 @@ namespace internal { // exist on the contained type. In particular, we rely on MergeFrom() existing // as a general proxy for the fact that a copy will work, and we also provide a // specific override for string*. -template -struct TypeImplementsMergeBehavior { +template +struct TypeImplementsMergeBehaviorProbeForMergeFrom { typedef char HasMerge; typedef long HasNoMerge; @@ -360,8 +375,13 @@ struct TypeImplementsMergeBehavior { (sizeof(Check(0)) == sizeof(HasMerge))> type; }; -template<> -struct TypeImplementsMergeBehavior< ::std::string > { +template +struct TypeImplementsMergeBehavior : + TypeImplementsMergeBehaviorProbeForMergeFrom {}; + + +template <> +struct TypeImplementsMergeBehavior< ::std::string> { typedef google::protobuf::internal::true_type type; }; @@ -379,7 +399,7 @@ struct TypeImplementsMergeBehavior< ::std::string > { // static void Merge(const Type& from, Type* to); // // // Only needs to be implemented if SpaceUsedExcludingSelf() is called. -// static int SpaceUsed(const Type&); +// static int SpaceUsedLong(const Type&); // }; class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase { protected: @@ -389,10 +409,10 @@ class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase { friend class GeneratedMessageReflection; // ExtensionSet stores repeated message extensions as - // RepeatedPtrField, but non-lite ExtensionSets need to - // implement SpaceUsed(), and thus need to call SpaceUsedExcludingSelf() - // reinterpreting MessageLite as Message. ExtensionSet also needs to make - // use of AddFromCleared(), which is not part of the public interface. + // RepeatedPtrField, but non-lite ExtensionSets need to implement + // SpaceUsedLong(), and thus need to call SpaceUsedExcludingSelfLong() + // reinterpreting MessageLite as Message. ExtensionSet also needs to make use + // of AddFromCleared(), which is not part of the public interface. friend class ExtensionSet; // The MapFieldBase implementation needs to call protected methods directly, @@ -400,6 +420,10 @@ class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase { // subclass. friend class MapFieldBase; + // The table-driven MergePartialFromCodedStream implementation needs to + // operate on RepeatedPtrField. + friend class MergePartialFromCodedStreamHelper; + // To parse directly into a proto2 generated class, the upb class GMR_Handlers // needs to be able to modify a RepeatedPtrFieldBase directly. friend class upb::google_opensource::GMR_Handlers; @@ -426,7 +450,7 @@ class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase { #if LANG_CXX11 template void Add(typename TypeHandler::Type&& value, - std::enable_if* dummy = NULL); + internal::enable_if* dummy = NULL); #endif template @@ -459,7 +483,7 @@ class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase { void SwapElements(int index1, int index2); template - int SpaceUsedExcludingSelf() const; + size_t SpaceUsedExcludingSelfLong() const; // Advanced memory management -------------------------------------- @@ -583,14 +607,12 @@ class GenericTypeHandler { #if LANG_CXX11 static const bool Moveable = false; #endif + static inline GenericType* New(Arena* arena) { return ::google::protobuf::Arena::CreateMaybeMessage( arena, static_cast(0)); } - // We force NewFromPrototype() to be non-inline to reduce code size: - // else, several other methods get inlined copies of message types' - // constructors. - GOOGLE_ATTRIBUTE_NOINLINE static GenericType* NewFromPrototype( + static inline GenericType* NewFromPrototype( const GenericType* prototype, ::google::protobuf::Arena* arena = NULL); static inline void Delete(GenericType* value, Arena* arena) { if (arena == NULL) { @@ -607,8 +629,8 @@ class GenericTypeHandler { static inline void Clear(GenericType* value) { value->Clear(); } GOOGLE_ATTRIBUTE_NOINLINE static void Merge(const GenericType& from, GenericType* to); - static inline int SpaceUsed(const GenericType& value) { - return value.SpaceUsed(); + static inline size_t SpaceUsedLong(const GenericType& value) { + return value.SpaceUsedLong(); } static inline const Type& default_instance() { return Type::default_instance(); @@ -626,11 +648,9 @@ void GenericTypeHandler::Merge(const GenericType& from, to->MergeFrom(from); } -// NewFromPrototype() and Merge() cannot be defined here; if they're declared -// inline the compiler will complain about not matching GOOGLE_ATTRIBUTE_NOINLINE -// above, and if not, compilation will result in multiple definitions. These -// are therefore declared as specializations here and defined in -// message_lite.cc. +// NewFromPrototype() and Merge() are not defined inline here, as we will need +// to do a virtual function dispatch anyways to go from Message* to call +// New/Merge. template<> MessageLite* GenericTypeHandler::NewFromPrototype( const MessageLite* prototype, google::protobuf::Arena* arena); @@ -708,7 +728,7 @@ class StringTypeHandler { return Arena::Create(arena); } #if LANG_CXX11 - static inline string* New(Arena* arena, std::string&& value) { + static inline string* New(Arena* arena, string&& value) { return Arena::Create(arena, std::move(value)); } #endif @@ -732,12 +752,11 @@ class StringTypeHandler { static inline const Type& default_instance() { return ::google::protobuf::internal::GetEmptyString(); } - static int SpaceUsed(const string& value) { - return static_cast(sizeof(value)) + StringSpaceUsedExcludingSelf(value); + static size_t SpaceUsedLong(const string& value) { + return sizeof(value) + StringSpaceUsedExcludingSelfLong(value); } }; - } // namespace internal // RepeatedPtrField is like RepeatedField, but used for repeated strings or @@ -842,10 +861,11 @@ class RepeatedPtrField PROTOBUF_FINAL : public internal::RepeatedPtrFieldBase { // Custom STL-like iterator that iterates over and returns the underlying // pointers to Element rather than Element itself. - typedef internal::RepeatedPtrOverPtrsIterator - pointer_iterator; - typedef internal::RepeatedPtrOverPtrsIterator - const_pointer_iterator; + typedef internal::RepeatedPtrOverPtrsIterator + pointer_iterator; + typedef internal::RepeatedPtrOverPtrsIterator + const_pointer_iterator; pointer_iterator pointer_begin(); const_pointer_iterator pointer_begin() const; pointer_iterator pointer_end(); @@ -853,7 +873,11 @@ class RepeatedPtrField PROTOBUF_FINAL : public internal::RepeatedPtrFieldBase { // Returns (an estimate of) the number of bytes used by the repeated field, // excluding sizeof(*this). - int SpaceUsedExcludingSelf() const; + size_t SpaceUsedExcludingSelfLong() const; + + int SpaceUsedExcludingSelf() const { + return internal::ToIntSize(SpaceUsedExcludingSelfLong()); + } // Advanced memory management -------------------------------------- // When hardcore memory management becomes necessary -- as it sometimes @@ -970,6 +994,11 @@ class RepeatedPtrField PROTOBUF_FINAL : public internal::RepeatedPtrFieldBase { return GetArenaNoVirtual(); } + // For internal use only. + // + // This is public due to it being called by generated code. + using RepeatedPtrFieldBase::InternalSwap; + private: // Note: RepeatedPtrField SHOULD NOT be subclassed by users. class TypeHandler; @@ -1088,6 +1117,14 @@ inline Element* RepeatedField::AddAlreadyReserved() { return &rep_->elements[current_size_++]; } +template +inline Element* RepeatedField::AddNAlreadyReserved(int elements) { + GOOGLE_DCHECK_LE(current_size_ + elements, total_size_); + Element* ret = &rep_->elements[current_size_]; + current_size_ += elements; + return ret; +} + template inline void RepeatedField::Resize(int new_size, const Element& value) { GOOGLE_DCHECK_GE(new_size, 0); @@ -1208,9 +1245,17 @@ inline const Element* RepeatedField::data() const { return rep_ ? rep_->elements : NULL; } +template +inline const Element* RepeatedField::unsafe_data() const { + GOOGLE_DCHECK(rep_); + return rep_->elements; +} template inline void RepeatedField::InternalSwap(RepeatedField* other) { + GOOGLE_DCHECK(this != other); + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + std::swap(rep_, other->rep_); std::swap(current_size_, other->current_size_); std::swap(total_size_, other->total_size_); @@ -1219,7 +1264,7 @@ inline void RepeatedField::InternalSwap(RepeatedField* other) { template void RepeatedField::Swap(RepeatedField* other) { if (this == other) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { InternalSwap(other); } else { RepeatedField temp(other->GetArenaNoVirtual()); @@ -1232,7 +1277,6 @@ void RepeatedField::Swap(RepeatedField* other) { template void RepeatedField::UnsafeArenaSwap(RepeatedField* other) { if (this == other) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); InternalSwap(other); } @@ -1274,9 +1318,8 @@ RepeatedField::cend() const { } template -inline int RepeatedField::SpaceUsedExcludingSelf() const { - return rep_ ? - (total_size_ * sizeof(Element) + kRepHeaderSize) : 0; +inline size_t RepeatedField::SpaceUsedExcludingSelfLong() const { + return rep_ ? (total_size_ * sizeof(Element) + kRepHeaderSize) : 0; } // Avoid inlining of Reserve(): new, copy, and delete[] lead to a significant @@ -1288,9 +1331,9 @@ void RepeatedField::Reserve(int new_size) { Arena* arena = GetArenaNoVirtual(); new_size = std::max(google::protobuf::internal::kMinRepeatedFieldAllocationSize, std::max(total_size_ * 2, new_size)); - GOOGLE_CHECK_LE(static_cast(new_size), - (std::numeric_limits::max() - kRepHeaderSize) / - sizeof(Element)) + GOOGLE_DCHECK_LE( + static_cast(new_size), + (std::numeric_limits::max() - kRepHeaderSize) / sizeof(Element)) << "Requested size is too large to fit into size_t."; size_t bytes = kRepHeaderSize + sizeof(Element) * new_size; if (arena == NULL) { @@ -1476,9 +1519,10 @@ inline typename TypeHandler::Type* RepeatedPtrFieldBase::Add( template inline void RepeatedPtrFieldBase::Add( typename TypeHandler::Type&& value, - std::enable_if*) { + internal::enable_if*) { if (rep_ != NULL && current_size_ < rep_->allocated_size) { - cast(rep_->elements[current_size_++]) = std::move(value); + *cast(rep_->elements[current_size_++]) = std::move(value); + return; } if (!rep_ || rep_->allocated_size == total_size_) { Reserve(total_size_ + 1); @@ -1606,11 +1650,11 @@ inline void RepeatedPtrFieldBase::SwapElements(int index1, int index2) { } template -inline int RepeatedPtrFieldBase::SpaceUsedExcludingSelf() const { - int allocated_bytes = total_size_ * sizeof(void*); +inline size_t RepeatedPtrFieldBase::SpaceUsedExcludingSelfLong() const { + size_t allocated_bytes = total_size_ * sizeof(void*); if (rep_ != NULL) { for (int i = 0; i < rep_->allocated_size; ++i) { - allocated_bytes += TypeHandler::SpaceUsed( + allocated_bytes += TypeHandler::SpaceUsedLong( *cast(rep_->elements[i])); } allocated_bytes += kRepHeaderSize; @@ -1819,7 +1863,6 @@ class RepeatedPtrField::TypeHandler : public internal::StringTypeHandler { }; - template inline RepeatedPtrField::RepeatedPtrField() : RepeatedPtrFieldBase() {} @@ -2036,7 +2079,6 @@ inline void RepeatedPtrField::Swap(RepeatedPtrField* other) { template inline void RepeatedPtrField::UnsafeArenaSwap( RepeatedPtrField* other) { - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); if (this == other) return; RepeatedPtrFieldBase::InternalSwap(other); @@ -2053,8 +2095,8 @@ inline Arena* RepeatedPtrField::GetArenaNoVirtual() const { } template -inline int RepeatedPtrField::SpaceUsedExcludingSelf() const { - return RepeatedPtrFieldBase::SpaceUsedExcludingSelf(); +inline size_t RepeatedPtrField::SpaceUsedExcludingSelfLong() const { + return RepeatedPtrFieldBase::SpaceUsedExcludingSelfLong(); } template @@ -2212,18 +2254,17 @@ class RepeatedPtrIterator // the array. // The VoidPtr template parameter holds the type-agnostic pointer value // referenced by the iterator. It should either be "void *" for a mutable -// iterator, or "const void *" for a constant iterator. -template +// iterator, or "const void* const" for a constant iterator. +template class RepeatedPtrOverPtrsIterator - : public std::iterator { + : public std::iterator { public: typedef RepeatedPtrOverPtrsIterator iterator; - typedef std::iterator< - std::random_access_iterator_tag, Element*> superclass; + typedef std::iterator superclass; // Shadow the value_type in std::iterator<> because const_iterator::value_type // needs to be T, not const T. - typedef typename remove_const::type value_type; + typedef typename remove_const::type value_type; // Let the compiler know that these are type names, so we don't have to // write "typename" in front of them everywhere. @@ -2235,7 +2276,7 @@ class RepeatedPtrOverPtrsIterator explicit RepeatedPtrOverPtrsIterator(VoidPtr* it) : it_(it) {} // dereferenceable - reference operator*() const { return *reinterpret_cast(it_); } + reference operator*() const { return *reinterpret_cast(it_); } pointer operator->() const { return &(operator*()); } // {inc,dec}rementable @@ -2291,6 +2332,9 @@ class RepeatedPtrOverPtrsIterator }; void RepeatedPtrFieldBase::InternalSwap(RepeatedPtrFieldBase* other) { + GOOGLE_DCHECK(this != other); + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); + std::swap(rep_, other->rep_); std::swap(current_size_, other->current_size_); std::swap(total_size_, other->total_size_); @@ -2337,7 +2381,7 @@ RepeatedPtrField::pointer_begin() { template inline typename RepeatedPtrField::const_pointer_iterator RepeatedPtrField::pointer_begin() const { - return const_pointer_iterator(const_cast(raw_mutable_data())); + return const_pointer_iterator(const_cast(raw_data())); } template inline typename RepeatedPtrField::pointer_iterator @@ -2348,7 +2392,7 @@ template inline typename RepeatedPtrField::const_pointer_iterator RepeatedPtrField::pointer_end() const { return const_pointer_iterator( - const_cast(raw_mutable_data() + size())); + const_cast(raw_data() + size())); } diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/repeated_field_reflection_unittest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/repeated_field_reflection_unittest.cc index fcebe5ce33..fd46656540 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/repeated_field_reflection_unittest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/repeated_field_reflection_unittest.cc @@ -189,8 +189,8 @@ TEST(RepeatedFieldReflectionTest, ExtensionFields) { } } -template -void TestRepeatedFieldRefIterator( +template +void TestRepeatedFieldRefIteratorForPrimitive( const Ref& handle, const MessageType& message, ValueType (MessageType::*GetFunc)(int) const) { int index = 0; @@ -202,6 +202,21 @@ void TestRepeatedFieldRefIterator( EXPECT_EQ(handle.size(), index); } +template +void TestRepeatedFieldRefIteratorForString( + const RepeatedFieldRef& handle, const MessageType& message, + ValueType (MessageType::*GetFunc)(int) const) { + int index = 0; + for (typename RepeatedFieldRef::const_iterator it = handle.begin(); + it != handle.end(); ++it) { + // Test both operator* and operator-> + EXPECT_EQ((message.*GetFunc)(index), *it); + EXPECT_EQ((message.*GetFunc)(index).size(), it->size()); + ++index; + } + EXPECT_EQ(handle.size(), index); +} + TEST(RepeatedFieldReflectionTest, RepeatedFieldRefForRegularFields) { TestAllTypes message; const Reflection* refl = message.GetReflection(); @@ -312,12 +327,12 @@ TEST(RepeatedFieldReflectionTest, RepeatedFieldRefForRegularFields) { } // Test iterators. - TestRepeatedFieldRefIterator(rf_int32, message, - &TestAllTypes::repeated_int32); - TestRepeatedFieldRefIterator(rf_double, message, - &TestAllTypes::repeated_double); - TestRepeatedFieldRefIterator(rf_string, message, - &TestAllTypes::repeated_string); + TestRepeatedFieldRefIteratorForPrimitive(rf_int32, message, + &TestAllTypes::repeated_int32); + TestRepeatedFieldRefIteratorForPrimitive(rf_double, message, + &TestAllTypes::repeated_double); + TestRepeatedFieldRefIteratorForString(rf_string, message, + &TestAllTypes::repeated_string); // Test iterators for message fields. typedef RepeatedFieldRef::iterator MessageIterator; @@ -474,10 +489,10 @@ TEST(RepeatedFieldReflectionTest, RepeatedFieldRefForEnums) { EXPECT_EQ(TestAllTypes::BAZ, message.repeated_nested_enum(i)); } - TestRepeatedFieldRefIterator(enum_ref, message, - &TestAllTypes::repeated_nested_enum); - TestRepeatedFieldRefIterator(int32_ref, message, - &TestAllTypes::repeated_nested_enum); + TestRepeatedFieldRefIteratorForPrimitive(enum_ref, message, + &TestAllTypes::repeated_nested_enum); + TestRepeatedFieldRefIteratorForPrimitive(int32_ref, message, + &TestAllTypes::repeated_nested_enum); // Test Add() mutable_enum_ref.Add(TestAllTypes::FOO); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/repeated_field_unittest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/repeated_field_unittest.cc index ec1074c9ce..043cc746d5 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/repeated_field_unittest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/repeated_field_unittest.cc @@ -45,9 +45,9 @@ #include #include #include -#include #include #include +#include #include namespace google { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/source_context.pb.cc b/third_party/protobuf/3.2.0/src/google/protobuf/source_context.pb.cc index 50e17da16d..3244444aa4 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/source_context.pb.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/source_context.pb.cc @@ -31,11 +31,26 @@ namespace { } // namespace +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField + const TableStruct::entries[] = { + {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, +}; + +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField + const TableStruct::aux[] = { + ::google::protobuf::internal::AuxillaryParseTableField(), +}; +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const + TableStruct::schema[] = { + { NULL, NULL, 0, -1, -1, false }, +}; + const ::google::protobuf::uint32 TableStruct::offsets[] = { ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceContext, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceContext, file_name_), }; @@ -165,7 +180,7 @@ void SourceContext::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* SourceContext::descriptor() { protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::file_level_metadata[0].descriptor; + return protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const SourceContext& SourceContext::default_instance() { @@ -236,6 +251,9 @@ failure: void SourceContext::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.SourceContext) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // string file_name = 1; if (this->file_name().size() > 0) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -251,8 +269,10 @@ 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; + // string file_name = 1; if (this->file_name().size() > 0) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -305,6 +325,9 @@ void SourceContext::MergeFrom(const SourceContext& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.SourceContext) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + if (from.file_name().size() > 0) { file_name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.file_name_); @@ -340,7 +363,7 @@ void SourceContext::InternalSwap(SourceContext* other) { ::google::protobuf::Metadata SourceContext::GetMetadata() const { protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::file_level_metadata[0]; + return protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -368,6 +391,7 @@ void SourceContext::set_file_name(::std::string&& value) { } #endif void SourceContext::set_file_name(const char* value) { + GOOGLE_DCHECK(value != NULL); file_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.SourceContext.file_name) diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/source_context.pb.h b/third_party/protobuf/3.2.0/src/google/protobuf/source_context.pb.h index 10888385a5..23cd7f3ec2 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/source_context.pb.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/source_context.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3002000 +#if GOOGLE_PROTOBUF_VERSION < 3003000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003000 < 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. @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,9 @@ namespace protobuf { namespace protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto { // Internal implementation detail -- do not call these. struct LIBPROTOBUF_EXPORT TableStruct { + static const ::google::protobuf::internal::ParseTableField entries[]; + static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; + static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; static void InitDefaultsImpl(); static void Shutdown(); @@ -72,6 +76,8 @@ class LIBPROTOBUF_EXPORT SourceContext : public ::google::protobuf::Message /* @ return reinterpret_cast( &_SourceContext_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 0; void Swap(SourceContext* other); @@ -94,11 +100,6 @@ class LIBPROTOBUF_EXPORT SourceContext : public ::google::protobuf::Message /* @ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -140,7 +141,7 @@ class LIBPROTOBUF_EXPORT SourceContext : public ::google::protobuf::Message /* @ ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::internal::ArenaStringPtr file_name_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::TableStruct; }; // =================================================================== @@ -172,6 +173,7 @@ inline void SourceContext::set_file_name(::std::string&& value) { } #endif inline void SourceContext::set_file_name(const char* value) { + GOOGLE_DCHECK(value != NULL); file_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.SourceContext.file_name) diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/struct.pb.cc b/third_party/protobuf/3.2.0/src/google/protobuf/struct.pb.cc index a1aa51ec0b..207e9efed7 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/struct.pb.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/struct.pb.cc @@ -19,6 +19,8 @@ namespace google { namespace protobuf { +class Struct_FieldsEntryDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed { +} _Struct_FieldsEntry_default_instance_; class StructDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed { } _Struct_default_instance_; class ValueDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed { @@ -43,37 +45,58 @@ const ::google::protobuf::EnumDescriptor* file_level_enum_descriptors[1]; } // namespace +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField + const TableStruct::entries[] = { + {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, +}; + +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField + const TableStruct::aux[] = { + ::google::protobuf::internal::AuxillaryParseTableField(), +}; +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const + TableStruct::schema[] = { + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, +}; + const ::google::protobuf::uint32 TableStruct::offsets[] = { ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Struct, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Struct, fields_), ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Value, _internal_metadata_), ~0u, // no _extensions_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Value, _oneof_case_[0]), - PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), null_value_), - PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), number_value_), - PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), string_value_), - PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), bool_value_), - PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), struct_value_), - PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), list_value_), + ~0u, // no _weak_field_map_ + GOOGLE_PROTOBUF_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), null_value_), + GOOGLE_PROTOBUF_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), number_value_), + GOOGLE_PROTOBUF_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), string_value_), + GOOGLE_PROTOBUF_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), bool_value_), + GOOGLE_PROTOBUF_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), struct_value_), + GOOGLE_PROTOBUF_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), list_value_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Value, kind_), ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ListValue, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ListValue, values_), }; static const ::google::protobuf::internal::MigrationSchema schemas[] = { { 0, -1, sizeof(Struct)}, - { 5, -1, sizeof(Value)}, - { 16, -1, sizeof(ListValue)}, + { 6, -1, sizeof(Value)}, + { 18, -1, sizeof(ListValue)}, }; static ::google::protobuf::Message const * const file_default_instances[] = { + reinterpret_cast(&_Struct_FieldsEntry_default_instance_), reinterpret_cast(&_Struct_default_instance_), reinterpret_cast(&_Value_default_instance_), reinterpret_cast(&_ListValue_default_instance_), @@ -87,6 +110,7 @@ void protobuf_AssignDescriptors() { AssignDescriptors( "google/protobuf/struct.proto", schemas, file_default_instances, TableStruct::offsets, factory, file_level_metadata, file_level_enum_descriptors, NULL); +file_level_metadata[0].reflection = Struct::Struct_FieldsEntry::CreateReflection(file_level_metadata[0].descriptor, _Struct_FieldsEntry_default_instance_.get_mutable()); } void protobuf_AssignDescriptorsOnce() { @@ -98,16 +122,6 @@ void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 4); - const ::google::protobuf::Descriptor* Struct_FieldsEntry_descriptor = protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[0].descriptor; - ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - Struct_FieldsEntry_descriptor, - ::google::protobuf::internal::MapEntry< - ::std::string, - ::google::protobuf::Value, - ::google::protobuf::internal::WireFormatLite::TYPE_STRING, - ::google::protobuf::internal::WireFormatLite::TYPE_MESSAGE, - 0>::CreateDefaultInstance( - Struct_FieldsEntry_descriptor)); } } // namespace @@ -119,15 +133,19 @@ void TableStruct::Shutdown() { delete file_level_metadata[2].reflection; _ListValue_default_instance_.Shutdown(); delete file_level_metadata[3].reflection; + delete file_level_metadata[0].reflection; } void TableStruct::InitDefaultsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; ::google::protobuf::internal::InitProtobufDefaults(); + _Struct_FieldsEntry_default_instance_.DefaultConstruct(); _Struct_default_instance_.DefaultConstruct(); _Value_default_instance_.DefaultConstruct(); _ListValue_default_instance_.DefaultConstruct(); + _Struct_FieldsEntry_default_instance_.get_mutable()->set_default_instance(_Struct_FieldsEntry_default_instance_.get_mutable()); + _Struct_FieldsEntry_default_instance_.get_mutable()->InitAsDefaultInstance(); _Value_default_instance_.null_value_ = 0; _Value_default_instance_.number_value_ = 0; _Value_default_instance_.string_value_.UnsafeSetDefault( @@ -200,6 +218,20 @@ bool NullValue_IsValid(int value) { // =================================================================== +Struct::Struct_FieldsEntry::Struct_FieldsEntry() {} +Struct::Struct_FieldsEntry::Struct_FieldsEntry(::google::protobuf::Arena* arena) : SuperType(arena) {} +::google::protobuf::Metadata Struct::Struct_FieldsEntry::GetMetadata() const { + protobuf_google_2fprotobuf_2fstruct_2eproto::protobuf_AssignDescriptorsOnce(); + return protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[0]; +} +void Struct::Struct_FieldsEntry::MergeFrom( + const ::google::protobuf::Message& other) { + ::google::protobuf::Message::MergeFrom(other); +} +void Struct::Struct_FieldsEntry::MergeFrom(const Struct_FieldsEntry& other) { + MergeFromInternal(other); +} + #if PROTOBUF_INLINE_NOT_IN_HEADERS #endif // PROTOBUF_INLINE_NOT_IN_HEADERS @@ -233,21 +265,11 @@ Struct::Struct(const Struct& from) _internal_metadata_(NULL), _cached_size_(0) { _internal_metadata_.MergeFrom(from._internal_metadata_); - const ::google::protobuf::Descriptor*& Struct_FieldsEntry_descriptor = protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[0].descriptor; - fields_.SetAssignDescriptorCallback( - protobuf_google_2fprotobuf_2fstruct_2eproto::protobuf_AssignDescriptorsOnce); - fields_.SetEntryDescriptor( - &Struct_FieldsEntry_descriptor); fields_.MergeFrom(from.fields_); // @@protoc_insertion_point(copy_constructor:google.protobuf.Struct) } void Struct::SharedCtor() { - const ::google::protobuf::Descriptor*& Struct_FieldsEntry_descriptor = protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[0].descriptor; - fields_.SetAssignDescriptorCallback( - protobuf_google_2fprotobuf_2fstruct_2eproto::protobuf_AssignDescriptorsOnce); - fields_.SetEntryDescriptor( - &Struct_FieldsEntry_descriptor); _cached_size_ = 0; } @@ -277,7 +299,7 @@ void Struct::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* Struct::descriptor() { protobuf_google_2fprotobuf_2fstruct_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[1].descriptor; + return protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const Struct& Struct::default_instance() { @@ -308,8 +330,8 @@ bool Struct::MergePartialFromCodedStream( case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(10u)) { - DO_(input->IncrementRecursionDepth()); Struct_FieldsEntry::Parser< ::google::protobuf::internal::MapField< + Struct_FieldsEntry, ::std::string, ::google::protobuf::Value, ::google::protobuf::internal::WireFormatLite::TYPE_STRING, ::google::protobuf::internal::WireFormatLite::TYPE_MESSAGE, @@ -324,7 +346,6 @@ bool Struct::MergePartialFromCodedStream( } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -352,6 +373,9 @@ failure: void Struct::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.Struct) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // map fields = 1; if (!this->fields().empty()) { typedef ::google::protobuf::Map< ::std::string, ::google::protobuf::Value >::const_pointer @@ -412,8 +436,10 @@ 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; + // map fields = 1; if (!this->fields().empty()) { typedef ::google::protobuf::Map< ::std::string, ::google::protobuf::Value >::const_pointer @@ -527,6 +553,9 @@ void Struct::MergeFrom(const Struct& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Struct) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + fields_.MergeFrom(from.fields_); } @@ -574,7 +603,7 @@ void Struct::InternalSwap(Struct* other) { ::google::protobuf::Metadata Struct::GetMetadata() const { protobuf_google_2fprotobuf_2fstruct_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[1]; + return protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -701,7 +730,7 @@ void Value::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* Value::descriptor() { protobuf_google_2fprotobuf_2fstruct_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[2].descriptor; + return protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const Value& Value::default_instance() { @@ -877,6 +906,9 @@ failure: void Value::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.Value) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // .google.protobuf.NullValue null_value = 1; if (has_null_value()) { ::google::protobuf::internal::WireFormatLite::WriteEnum( @@ -920,8 +952,10 @@ 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; + // .google.protobuf.NullValue null_value = 1; if (has_null_value()) { target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray( @@ -953,14 +987,14 @@ void Value::SerializeWithCachedSizes( if (has_struct_value()) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 5, *kind_.struct_value_, false, target); + 5, *kind_.struct_value_, deterministic, target); } // .google.protobuf.ListValue list_value = 6; if (has_list_value()) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 6, *kind_.list_value_, false, target); + 6, *kind_.list_value_, deterministic, target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Value) @@ -1039,6 +1073,9 @@ void Value::MergeFrom(const Value& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Value) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + switch (from.kind_case()) { case kNullValue: { set_null_value(from.null_value()); @@ -1115,7 +1152,7 @@ void Value::InternalSwap(Value* other) { ::google::protobuf::Metadata Value::GetMetadata() const { protobuf_google_2fprotobuf_2fstruct_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[2]; + return protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -1211,6 +1248,7 @@ void Value::set_string_value(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.Value.string_value) } void Value::set_string_value(const char* value) { + GOOGLE_DCHECK(value != NULL); if (!has_string_value()) { clear_kind(); set_has_string_value(); @@ -1568,7 +1606,7 @@ void ListValue::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* ListValue::descriptor() { protobuf_google_2fprotobuf_2fstruct_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[3].descriptor; + return protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const ListValue& ListValue::default_instance() { @@ -1599,13 +1637,11 @@ bool ListValue::MergePartialFromCodedStream( case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(10u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_values())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -1633,6 +1669,9 @@ failure: void ListValue::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.ListValue) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // repeated .google.protobuf.Value values = 1; for (unsigned int i = 0, n = this->values_size(); i < n; i++) { ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( @@ -1644,13 +1683,15 @@ 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; + // repeated .google.protobuf.Value values = 1; for (unsigned int i = 0, n = this->values_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 1, this->values(i), false, target); + 1, this->values(i), deterministic, target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.ListValue) @@ -1698,6 +1739,9 @@ void ListValue::MergeFrom(const ListValue& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ListValue) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + values_.MergeFrom(from.values_); } @@ -1739,13 +1783,13 @@ void ListValue::UnsafeArenaSwap(ListValue* other) { InternalSwap(other); } void ListValue::InternalSwap(ListValue* other) { - values_.UnsafeArenaSwap(&other->values_); + values_.InternalSwap(&other->values_); std::swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata ListValue::GetMetadata() const { protobuf_google_2fprotobuf_2fstruct_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[3]; + return protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/struct.pb.h b/third_party/protobuf/3.2.0/src/google/protobuf/struct.pb.h index 043f0c32b1..a37a5652a9 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/struct.pb.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/struct.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3002000 +#if GOOGLE_PROTOBUF_VERSION < 3003000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003000 < 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. @@ -22,12 +22,13 @@ #include #include #include +#include #include #include #include #include // IWYU pragma: export #include // IWYU pragma: export -#include +#include // IWYU pragma: export #include #include #include @@ -40,6 +41,9 @@ LIBPROTOBUF_EXPORT extern ListValueDefaultTypeInternal _ListValue_default_instan class Struct; class StructDefaultTypeInternal; LIBPROTOBUF_EXPORT extern StructDefaultTypeInternal _Struct_default_instance_; +class Struct_FieldsEntry; +class Struct_FieldsEntryDefaultTypeInternal; +LIBPROTOBUF_EXPORT extern Struct_FieldsEntryDefaultTypeInternal _Struct_FieldsEntry_default_instance_; class Value; class ValueDefaultTypeInternal; LIBPROTOBUF_EXPORT extern ValueDefaultTypeInternal _Value_default_instance_; @@ -52,6 +56,9 @@ namespace protobuf { namespace protobuf_google_2fprotobuf_2fstruct_2eproto { // Internal implementation detail -- do not call these. struct LIBPROTOBUF_EXPORT TableStruct { + static const ::google::protobuf::internal::ParseTableField entries[]; + static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; + static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; static void InitDefaultsImpl(); static void Shutdown(); @@ -110,6 +117,8 @@ class LIBPROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc return reinterpret_cast( &_Struct_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 1; void UnsafeArenaSwap(Struct* other); void Swap(Struct* other); @@ -133,11 +142,6 @@ class LIBPROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -181,19 +185,34 @@ class LIBPROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc friend class ::google::protobuf::Arena; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; - typedef ::google::protobuf::internal::MapEntryLite< + public: + class Struct_FieldsEntry : public ::google::protobuf::internal::MapEntry { + public: + typedef ::google::protobuf::internal::MapEntry - Struct_FieldsEntry; + 0 > SuperType; + Struct_FieldsEntry(); + Struct_FieldsEntry(::google::protobuf::Arena* arena); + void MergeFrom(const ::google::protobuf::Message& other) PROTOBUF_FINAL; + void MergeFrom(const Struct_FieldsEntry& other); + static const Message* internal_default_instance() { return reinterpret_cast(&_Struct_FieldsEntry_default_instance_); } + ::google::protobuf::Metadata GetMetadata() const; + }; ::google::protobuf::internal::MapField< + Struct_FieldsEntry, ::std::string, ::google::protobuf::Value, ::google::protobuf::internal::WireFormatLite::TYPE_STRING, ::google::protobuf::internal::WireFormatLite::TYPE_MESSAGE, 0 > fields_; + private: mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fstruct_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2fstruct_2eproto::TableStruct; }; // ------------------------------------------------------------------- @@ -232,6 +251,8 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_ return reinterpret_cast( &_Value_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 2; void UnsafeArenaSwap(Value* other); void Swap(Value* other); @@ -255,11 +276,6 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -396,7 +412,7 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_ mutable int _cached_size_; ::google::protobuf::uint32 _oneof_case_[1]; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fstruct_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2fstruct_2eproto::TableStruct; }; // ------------------------------------------------------------------- @@ -425,6 +441,8 @@ class LIBPROTOBUF_EXPORT ListValue : public ::google::protobuf::Message /* @@pro return reinterpret_cast( &_ListValue_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 3; void UnsafeArenaSwap(ListValue* other); void Swap(ListValue* other); @@ -448,11 +466,6 @@ class LIBPROTOBUF_EXPORT ListValue : public ::google::protobuf::Message /* @@pro ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -500,7 +513,7 @@ class LIBPROTOBUF_EXPORT ListValue : public ::google::protobuf::Message /* @@pro typedef void DestructorSkippable_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::Value > values_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fstruct_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2fstruct_2eproto::TableStruct; }; // =================================================================== @@ -624,6 +637,7 @@ inline void Value::set_string_value(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.Value.string_value) } inline void Value::set_string_value(const char* value) { + GOOGLE_DCHECK(value != NULL); if (!has_string_value()) { clear_kind(); set_has_string_value(); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/stubs/common.h b/third_party/protobuf/3.2.0/src/google/protobuf/stubs/common.h index d261149803..60874e0917 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/stubs/common.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/stubs/common.h @@ -35,7 +35,12 @@ #ifndef GOOGLE_PROTOBUF_COMMON_H__ #define GOOGLE_PROTOBUF_COMMON_H__ +#include +#include +#include +#include #include +#include #include #include @@ -96,27 +101,27 @@ 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 3002000 +#define GOOGLE_PROTOBUF_VERSION 3003000 // A suffix string for alpha, beta or rc releases. Empty for stable releases. #define GOOGLE_PROTOBUF_VERSION_SUFFIX "" // The minimum library version which works with the current version of the // headers. -#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 3002000 +#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 3003000 // The minimum header version which works with the current version of // the library. This constant should only be used by protoc's C++ code // generator. -static const int kMinHeaderVersionForLibrary = 3002000; +static const int kMinHeaderVersionForLibrary = 3003000; // The minimum protoc version which works with the current version of the // headers. -#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 3002000 +#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 3003000 // The minimum header version which works with the current version of // protoc. This constant should only be used in VerifyVersion(). -static const int kMinHeaderVersionForProtoc = 3002000; +static const int kMinHeaderVersionForProtoc = 3003000; // Verifies that the headers and libraries are compatible. Use the macro // below to call this. @@ -220,7 +225,14 @@ class FatalException : public std::exception { // This is at the end of the file instead of the beginning to work around a bug // in some versions of MSVC. -using namespace std; // Don't do this at home, kids. +// 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; } // namespace protobuf } // namespace google diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/stubs/int128_unittest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/stubs/int128_unittest.cc index 5d33292ccc..1ec899ad7b 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/stubs/int128_unittest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/stubs/int128_unittest.cc @@ -370,29 +370,29 @@ TEST(Int128, DivideAndMod) { EXPECT_EQ(r, result_r); // Try the other way around. - swap(q, b); + std::swap(q, b); result_q = a / b; result_r = a % b; EXPECT_EQ(q, result_q); EXPECT_EQ(r, result_r); // Restore. - swap(b, q); + std::swap(b, q); // Dividend < divisor; result should be q:0 r:. - swap(a, b); + std::swap(a, b); result_q = a / b; result_r = a % b; EXPECT_EQ(0, result_q); EXPECT_EQ(a, result_r); // Try the other way around. - swap(a, q); + std::swap(a, q); result_q = a / b; result_r = a % b; EXPECT_EQ(0, result_q); EXPECT_EQ(a, result_r); // Restore. - swap(q, a); - swap(b, a); + std::swap(q, a); + std::swap(b, a); // Try a large remainder. b = a / 2 + 1; @@ -501,7 +501,7 @@ TEST(Int128, OStream) { {uint128(12345), std::ios::dec | std::ios::left, 6, '_', "12345_"}, }; for (size_t i = 0; i < GOOGLE_ARRAYSIZE(cases); ++i) { - ostringstream os; + std::ostringstream os; os.flags(cases[i].flags); os.width(cases[i].width); os.fill(cases[i].fill); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/stubs/io_win32.cc b/third_party/protobuf/3.2.0/src/google/protobuf/stubs/io_win32.cc index bffa450a26..310cb1b0c4 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/stubs/io_win32.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/stubs/io_win32.cc @@ -30,21 +30,31 @@ // Author: laszlocsomor@google.com (Laszlo Csomor) // -// Implementation for long-path-aware open/mkdir/access on Windows. +// Implementation for long-path-aware open/mkdir/etc. on Windows. // // These functions convert the input path to an absolute Windows path -// with UNC prefix if necessary, then pass that to -// _wopen/_wmkdir/_waccess (declared in ) respectively. This -// allows working with files/directories whose paths are longer than -// MAX_PATH (260 chars). +// with "\\?\" prefix if necessary, then pass that to _wopen/_wmkdir/etc. +// (declared in ) 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 +#include #include +#include +#include +#include +#include #include +#include #include @@ -84,14 +94,14 @@ bool has_drive_letter(const char_type* ch) { } template -bool has_unc_prefix(const std::basic_string& path) { +bool has_longpath_prefix(const std::basic_string& path) { return path.size() > 4 && path[0] == '\\' && path[1] == '\\' && path[2] == '?' && path[3] == '\\'; } template bool is_path_absolute(const std::basic_string& path) { - return (path.size() > 2 && path[1] == ':') || has_unc_prefix(path); + return (path.size() > 2 && path[1] == ':') || has_longpath_prefix(path); } template @@ -104,24 +114,16 @@ bool is_drive_relative(const string& s) { (s.size() == 2 || !is_separator(s[2])); } -void replace_directory_separators(WCHAR* p) { - for (; *p != L'\0'; ++p) { - if (*p == L'/') { - *p = L'\\'; +template +void replace_directory_separators(char_type* p) { + for (; *p; ++p) { + if (*p == '/') { + *p = '\\'; } } } -wstring get_cwd() { - DWORD result = ::GetCurrentDirectoryW(0, NULL); - std::unique_ptr cwd(new WCHAR[result]); - ::GetCurrentDirectoryW(result, cwd.get()); - cwd.get()[result - 1] = 0; - replace_directory_separators(cwd.get()); - return std::move(wstring(cwd.get())); -} - -wstring join_paths(const wstring& path1, const wstring& path2) { +string join_paths(const string& path1, const string& path2) { if (path1.empty() || is_path_absolute(path2)) { return path2; } @@ -134,12 +136,12 @@ wstring join_paths(const wstring& path1, const wstring& path2) { : (path1 + path2); } else { return is_separator(path2.front()) ? (path1 + path2) - : (path1 + L'\\' + path2); + : (path1 + '\\' + path2); } } string normalize(string path) { - if (has_unc_prefix(path)) { + if (has_longpath_prefix(path)) { path = path.substr(4); } @@ -162,10 +164,11 @@ string normalize(string path) { string segment(path, segment_start, i - segment_start); segment_start = -1; if (segment == dotdot) { - if (!segments.empty() && !has_drive_letter(segments[0].c_str())) { + if (!segments.empty() && + (!has_drive_letter(segments[0].c_str()) || segments.size() > 1)) { segments.pop_back(); } - } else if (segment != dot) { + } else if (segment != dot && !segment.empty()) { segments.push_back(segment); } } @@ -191,22 +194,28 @@ string normalize(string path) { first = false; result << s; } + // Preserve trailing separator if the input contained it. + if (is_separator(path.back())) { + result << '\\'; + } return result.str(); } +std::unique_ptr as_wstring(const string& s) { + int len = ::MultiByteToWideChar(CP_UTF8, 0, s.c_str(), s.size(), NULL, 0); + std::unique_ptr 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) { - int len = - ::MultiByteToWideChar(CP_UTF8, 0, path.c_str(), path.size(), NULL, 0); - std::unique_ptr wbuf(new WCHAR[len + 1]); - ::MultiByteToWideChar(CP_UTF8, 0, path.c_str(), path.size(), wbuf.get(), - len + 1); - wbuf.get()[len] = 0; + std::unique_ptr wbuf(as_wstring(path)); replace_directory_separators(wbuf.get()); - return std::move(wstring(wbuf.get())); + return wstring(wbuf.get()); } -bool as_windows_path(const string& path, size_t max_path, - wstring* result) { +bool as_windows_path(const string& path, wstring* result) { if (path.empty()) { result->clear(); return true; @@ -215,11 +224,18 @@ bool as_windows_path(const string& path, size_t max_path, return false; } - *result = as_wchar_path(normalize(path)); - if (!is_path_absolute(path)) { - *result = join_paths(get_cwd(), *result); + string mutable_path = path; + if (!is_path_absolute(mutable_path)) { + char cwd[MAX_PATH]; + ::GetCurrentDirectoryA(MAX_PATH, cwd); + mutable_path = join_paths(cwd, mutable_path); } - if (result->size() >= max_path && !has_unc_prefix(*result)) { + *result = as_wchar_path(normalize(mutable_path)); + if (!has_longpath_prefix(*result)) { + // 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; @@ -227,41 +243,104 @@ bool as_windows_path(const string& path, size_t max_path, } // namespace -int win32_open(const char* path, int flags, int mode) { +int open(const char* path, int flags, int mode) { +#ifdef SUPPORT_LONGPATHS wstring wpath; - if (!as_windows_path(path, MAX_PATH, &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 win32_mkdir(const char* path, int _mode) { - // CreateDirectoryA's limit is 248 chars, see MSDN. - // https://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx - // This limit presumably includes the null-terminator, because other - // functions that have the MAX_PATH limit, such as CreateFileA, - // actually include it. +int mkdir(const char* path, int _mode) { +#ifdef SUPPORT_LONGPATHS wstring wpath; - if (!as_windows_path(path, 248, &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 win32_access(const char* path, int mode) { +int access(const char* path, int mode) { +#ifdef SUPPORT_LONGPATHS wstring wpath; - if (!as_windows_path(path, MAX_PATH, &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 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, size_t max_path) { +wstring testonly_path_to_winpath(const string& path) { wstring wpath; - as_windows_path(path, max_path, &wpath); + as_windows_path(path, &wpath); return wpath; } diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/stubs/io_win32.h b/third_party/protobuf/3.2.0/src/google/protobuf/stubs/io_win32.h index 0716faaa78..e4632f4da9 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/stubs/io_win32.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/stubs/io_win32.h @@ -34,11 +34,11 @@ // 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/mkdir to -// ::google::protobuf::stubs::win32_{open/access/mkdir}. +// By including this file you'll redefine open/access/etc. to +// ::google::protobuf::stubs::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. +// 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. @@ -47,43 +47,30 @@ #if defined(_WIN32) -#include -#include -#include -#include -#include -#include - #include namespace google { namespace protobuf { namespace stubs { -int win32_open(const char* path, int flags, int mode = 0); -int win32_mkdir(const char* name, int _mode); -int win32_access(const char* pathname, int mode); -std::wstring testonly_path_to_winpath(const std::string& path, size_t max_path); +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 stubs } // namespace protobuf } // namespace google -#ifdef open -#undef open -#endif -#define open ::google::protobuf::stubs::win32_open - -#ifdef mkdir -#undef mkdir -#endif -#define mkdir ::google::protobuf::stubs::win32_mkdir - -#ifdef access -#undef access -#endif -#define access ::google::protobuf::stubs::win32_access - #ifndef W_OK #define W_OK 02 // not defined by MSVC for whatever reason #endif @@ -104,3 +91,4 @@ std::wstring testonly_path_to_winpath(const std::string& path, size_t max_path); #endif // GOOGLE_PROTOBUF_STUBS_IO_WIN32_H__ + diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/stubs/io_win32_unittest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/stubs/io_win32_unittest.cc index fb3d5f7244..ca0f13a72a 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/stubs/io_win32_unittest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/stubs/io_win32_unittest.cc @@ -38,13 +38,20 @@ #define WIN32_LEAN_AND_MEAN #include +#include #include +#include +#include +#include +#include #include #include +#include #include #include +#include #include namespace google { @@ -62,7 +69,8 @@ class IoWin32Test : public ::testing::Test { void TearDown() override; protected: - static bool DeleteAllUnder(wstring path); + bool CreateAllUnder(wstring path); + bool DeleteAllUnder(wstring path); string test_tmpdir; wstring wtest_tmpdir; @@ -75,25 +83,64 @@ class IoWin32Test : public ::testing::Test { } void IoWin32Test::SetUp() { - test_tmpdir.clear(); + 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); + } - const char* test_tmpdir_env = getenv("TEST_TMPDIR"); - if (test_tmpdir_env == nullptr || *test_tmpdir_env == 0) { - // Using assertions in SetUp/TearDown seems to confuse the test framework, - // so just leave the member variables empty in case of failure. - return; + // 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; + } + } } - test_tmpdir = string(test_tmpdir_env); 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, 248); + 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() { @@ -102,6 +149,30 @@ void IoWin32Test::TearDown() { } } +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".."); @@ -159,8 +230,11 @@ TEST_F(IoWin32Test, AccessTest) { } string file = path + "\\file.txt"; int fd = open(file.c_str(), O_CREAT | O_WRONLY, 0644); - EXPECT_GT(fd, 0); - EXPECT_EQ(close(fd), 0); + 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); @@ -169,20 +243,14 @@ TEST_F(IoWin32Test, AccessTest) { EXPECT_NE(access((file + ".blah").c_str(), F_OK), 0); EXPECT_NE(access((file + ".blah").c_str(), W_OK), 0); - // chdir into the test_tmpdir, 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 - EXPECT_EQ(_chdir(test_tmpdir.c_str()), 0); EXPECT_EQ(access(".", F_OK), 0); EXPECT_EQ(access(".", W_OK), 0); - EXPECT_EQ(access("accesstest", F_OK | W_OK), 0); - ASSERT_EQ(access("./normalize_me/../.././accesstest", F_OK | W_OK), 0); - EXPECT_NE(access("blah", F_OK), 0); - EXPECT_NE(access("blah", 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); @@ -202,26 +270,12 @@ TEST_F(IoWin32Test, OpenTest) { } string file = path + "\\file.txt"; int fd = open(file.c_str(), O_CREAT | O_WRONLY, 0644); - ASSERT_GT(fd, 0); - EXPECT_EQ(write(fd, "hello", 5), 5); - EXPECT_EQ(close(fd), 0); - - // chdir into the test_tmpdir, 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 - EXPECT_EQ(_chdir(test_tmpdir.c_str()), 0); - fd = open("file-relative.txt", O_CREAT | O_WRONLY, 0644); - ASSERT_GT(fd, 0); - EXPECT_EQ(write(fd, "hello", 5), 5); - EXPECT_EQ(close(fd), 0); - - fd = open("./normalize_me/../.././file-relative.txt", O_RDONLY); - ASSERT_GT(fd, 0); - EXPECT_EQ(close(fd), 0); + 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); @@ -240,17 +294,6 @@ TEST_F(IoWin32Test, MkdirTest) { ASSERT_EQ(mkdir(path.c_str(), 0644), 0); } while (path.size() <= MAX_PATH); - // chdir into the test_tmpdir, 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 - EXPECT_EQ(_chdir(test_tmpdir.c_str()), 0); - ASSERT_EQ(mkdir("relative_mkdirtest", 0644), 0); - ASSERT_EQ(mkdir("./normalize_me/../.././blah", 0644), 0); - ASSERT_EQ(mkdir("c:bad", 0644), -1); ASSERT_EQ(errno, ENOENT); ASSERT_EQ(mkdir("/tmp/bad", 0644), -1); @@ -259,6 +302,57 @@ TEST_F(IoWin32Test, MkdirTest) { 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 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""); +} + } // namespace } // namespace stubs } // namespace protobuf diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/stubs/strutil.cc b/third_party/protobuf/3.2.0/src/google/protobuf/stubs/strutil.cc index 15b6e53f1a..336894b52b 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/stubs/strutil.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/stubs/strutil.cc @@ -227,7 +227,7 @@ void SplitStringToIteratorUsing(const string& full, void SplitStringUsing(const string& full, const char* delim, vector* result) { - back_insert_iterator< vector > it(*result); + std::back_insert_iterator< vector > it(*result); SplitStringToIteratorUsing(full, delim, it); } @@ -265,7 +265,7 @@ void SplitStringToIteratorAllowEmpty(const StringType& full, void SplitStringAllowEmpty(const string& full, const char* delim, vector* result) { - back_insert_iterator > it(*result); + std::back_insert_iterator > it(*result); SplitStringToIteratorAllowEmpty(full, delim, 0, it); } @@ -1262,10 +1262,10 @@ char* DoubleToBuffer(double value, char* buffer) { // this assert. GOOGLE_COMPILE_ASSERT(DBL_DIG < 20, DBL_DIG_is_too_big); - if (value == numeric_limits::infinity()) { + if (value == std::numeric_limits::infinity()) { strcpy(buffer, "inf"); return buffer; - } else if (value == -numeric_limits::infinity()) { + } else if (value == -std::numeric_limits::infinity()) { strcpy(buffer, "-inf"); return buffer; } else if (MathLimits::IsNaN(value)) { @@ -1380,10 +1380,10 @@ char* FloatToBuffer(float value, char* buffer) { // this assert. GOOGLE_COMPILE_ASSERT(FLT_DIG < 10, FLT_DIG_is_too_big); - if (value == numeric_limits::infinity()) { + if (value == std::numeric_limits::infinity()) { strcpy(buffer, "inf"); return buffer; - } else if (value == -numeric_limits::infinity()) { + } else if (value == -std::numeric_limits::infinity()) { strcpy(buffer, "-inf"); return buffer; } else if (MathLimits::IsNaN(value)) { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/test_util_lite.cc b/third_party/protobuf/3.2.0/src/google/protobuf/test_util_lite.cc index 388c0cbde2..79c5abec6d 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/test_util_lite.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/test_util_lite.cc @@ -35,14 +35,9 @@ #include #include #include +#include -#define EXPECT_TRUE GOOGLE_CHECK -#define ASSERT_TRUE GOOGLE_CHECK -#define EXPECT_FALSE(COND) GOOGLE_CHECK(!(COND)) -#define EXPECT_EQ GOOGLE_CHECK_EQ -#define ASSERT_EQ GOOGLE_CHECK_EQ - namespace google { namespace protobuf { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/testing/file.cc b/third_party/protobuf/3.2.0/src/google/protobuf/testing/file.cc index 470512edff..b935488989 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/testing/file.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/testing/file.cc @@ -38,24 +38,28 @@ #ifdef _MSC_VER #define WIN32_LEAN_AND_MEAN // yeah, right #include // Find*File(). :( -#include -#include +// #include #else #include #include #endif #include +#include + 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 , instead create functions in io_win32.{h,cc} and import +// them like we do below. +using google::protobuf::stubs::access; +using google::protobuf::stubs::chdir; +using google::protobuf::stubs::fopen; +using google::protobuf::stubs::mkdir; +using google::protobuf::stubs::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/third_party/protobuf/3.2.0/src/google/protobuf/testing/googletest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/testing/googletest.cc index d45706b654..0dd2476b03 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/testing/googletest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/testing/googletest.cc @@ -33,14 +33,14 @@ #include #include +#include #include #include #include #include #include #ifdef _MSC_VER -#include -#include +// #include #else #include #endif @@ -53,7 +53,13 @@ namespace google { namespace protobuf { #ifdef _WIN32 -#define mkdir(name, mode) mkdir(name) +// DO NOT include , instead create functions in io_win32.{h,cc} and import +// them like we do below. +using google::protobuf::stubs::close; +using google::protobuf::stubs::dup2; +using google::protobuf::stubs::dup; +using google::protobuf::stubs::mkdir; +using google::protobuf::stubs::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/third_party/protobuf/3.2.0/src/google/protobuf/text_format.cc b/third_party/protobuf/3.2.0/src/google/protobuf/text_format.cc index 778b878e79..04c887e088 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/text_format.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/text_format.cc @@ -74,18 +74,6 @@ inline bool IsOctNumber(const string& str) { (str[1] >= '0' && str[1] < '8')); } -inline bool GetAnyFieldDescriptors(const Message& message, - const FieldDescriptor** type_url_field, - const FieldDescriptor** value_field) { - const Descriptor* descriptor = message.GetDescriptor(); - *type_url_field = descriptor->FindFieldByNumber(1); - *value_field = descriptor->FindFieldByNumber(2); - return (*type_url_field != NULL && - (*type_url_field)->type() == FieldDescriptor::TYPE_STRING && - *value_field != NULL && - (*value_field)->type() == FieldDescriptor::TYPE_BYTES); -} - } // namespace string Message::DebugString() const { @@ -1322,6 +1310,7 @@ bool TextFormat::Parser::ParseFromString(const string& input, return Parse(&input_stream, output); } + bool TextFormat::Parser::Merge(io::ZeroCopyInputStream* input, Message* output) { ParserImpl parser(output->GetDescriptor(), input, error_collector_, @@ -1339,6 +1328,7 @@ bool TextFormat::Parser::MergeFromString(const string& input, return Merge(&input_stream, output); } + bool TextFormat::Parser::MergeUsingImpl(io::ZeroCopyInputStream* /* input */, Message* output, ParserImpl* parser_impl) { @@ -1387,6 +1377,7 @@ bool TextFormat::Parser::ParseFieldValueFromString( return Parser().MergeFromString(input, output); } + // =========================================================================== // The default implementation for FieldValuePrinter. The base class just diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/text_format.h b/third_party/protobuf/3.2.0/src/google/protobuf/text_format.h index 2873d3392b..560fd391bc 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/text_format.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/text_format.h @@ -75,8 +75,8 @@ class LIBPROTOBUF_EXPORT TextFormat { io::ZeroCopyOutputStream* output); // Like Print(), but outputs directly to a string. - // Note: output will be cleared before prior to printing, and will - // be left empty even if printing fails. + // Note: output will be cleared prior to printing, and will be left empty + // even if printing fails. static bool PrintToString(const Message& message, string* output); // Like PrintUnknownFields(), but outputs directly to a string. diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/text_format_unittest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/text_format_unittest.cc index e644133953..422a86b4ba 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/text_format_unittest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/text_format_unittest.cc @@ -53,11 +53,11 @@ #include #include #include -#include #include #include #include #include +#include namespace google { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/timestamp.pb.cc b/third_party/protobuf/3.2.0/src/google/protobuf/timestamp.pb.cc index c1865d93e0..b2fe28a472 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/timestamp.pb.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/timestamp.pb.cc @@ -31,11 +31,26 @@ namespace { } // namespace +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField + const TableStruct::entries[] = { + {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, +}; + +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField + const TableStruct::aux[] = { + ::google::protobuf::internal::AuxillaryParseTableField(), +}; +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const + TableStruct::schema[] = { + { NULL, NULL, 0, -1, -1, false }, +}; + const ::google::protobuf::uint32 TableStruct::offsets[] = { ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Timestamp, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Timestamp, seconds_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Timestamp, nanos_), }; @@ -186,7 +201,7 @@ void Timestamp::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* Timestamp::descriptor() { protobuf_google_2fprotobuf_2ftimestamp_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2ftimestamp_2eproto::file_level_metadata[0].descriptor; + return protobuf_google_2fprotobuf_2ftimestamp_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const Timestamp& Timestamp::default_instance() { @@ -266,6 +281,9 @@ failure: void Timestamp::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.Timestamp) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // int64 seconds = 1; if (this->seconds() != 0) { ::google::protobuf::internal::WireFormatLite::WriteInt64(1, this->seconds(), output); @@ -281,8 +299,10 @@ 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; + // int64 seconds = 1; if (this->seconds() != 0) { target = ::google::protobuf::internal::WireFormatLite::WriteInt64ToArray(1, this->seconds(), target); @@ -341,6 +361,9 @@ void Timestamp::MergeFrom(const Timestamp& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Timestamp) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + if (from.seconds() != 0) { set_seconds(from.seconds()); } @@ -394,7 +417,7 @@ void Timestamp::InternalSwap(Timestamp* other) { ::google::protobuf::Metadata Timestamp::GetMetadata() const { protobuf_google_2fprotobuf_2ftimestamp_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2ftimestamp_2eproto::file_level_metadata[0]; + return protobuf_google_2fprotobuf_2ftimestamp_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/timestamp.pb.h b/third_party/protobuf/3.2.0/src/google/protobuf/timestamp.pb.h index e6fc09a1cc..9847854037 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/timestamp.pb.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/timestamp.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3002000 +#if GOOGLE_PROTOBUF_VERSION < 3003000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003000 < 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. @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,9 @@ namespace protobuf { namespace protobuf_google_2fprotobuf_2ftimestamp_2eproto { // Internal implementation detail -- do not call these. struct LIBPROTOBUF_EXPORT TableStruct { + static const ::google::protobuf::internal::ParseTableField entries[]; + static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; + static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; static void InitDefaultsImpl(); static void Shutdown(); @@ -78,6 +82,8 @@ class LIBPROTOBUF_EXPORT Timestamp : public ::google::protobuf::Message /* @@pro return reinterpret_cast( &_Timestamp_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 0; void UnsafeArenaSwap(Timestamp* other); void Swap(Timestamp* other); @@ -101,11 +107,6 @@ class LIBPROTOBUF_EXPORT Timestamp : public ::google::protobuf::Message /* @@pro ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -154,7 +155,7 @@ class LIBPROTOBUF_EXPORT Timestamp : public ::google::protobuf::Message /* @@pro ::google::protobuf::int64 seconds_; ::google::protobuf::int32 nanos_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2ftimestamp_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2ftimestamp_2eproto::TableStruct; }; // =================================================================== diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/timestamp.proto b/third_party/protobuf/3.2.0/src/google/protobuf/timestamp.proto index 67e2eba4f8..b7cbd17502 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/timestamp.proto +++ b/third_party/protobuf/3.2.0/src/google/protobuf/timestamp.proto @@ -52,6 +52,8 @@ option objc_class_prefix = "GPB"; // and from RFC 3339 date strings. // See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt). // +// # Examples +// // Example 1: Compute Timestamp from POSIX `time()`. // // Timestamp timestamp; @@ -92,6 +94,29 @@ option objc_class_prefix = "GPB"; // timestamp = Timestamp() // timestamp.GetCurrentTime() // +// # JSON Mapping +// +// In JSON format, the Timestamp type is encoded as a string in the +// [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the +// format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" +// where {year} is always expressed using four digits while {month}, {day}, +// {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional +// seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), +// are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone +// is required, though only UTC (as indicated by "Z") is presently supported. +// +// For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past +// 01:30 UTC on January 15, 2017. +// +// In JavaScript, one can convert a Date object to this format using the +// standard [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString] +// method. In Python, a standard `datetime.datetime` object can be converted +// to this format using [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) +// with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one +// can use the Joda Time's [`ISODateTimeFormat.dateTime()`]( +// http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime()) +// to obtain a formatter capable of generating timestamps in this format. +// // message Timestamp { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/type.pb.cc b/third_party/protobuf/3.2.0/src/google/protobuf/type.pb.cc index 017392c9d9..8f017a8921 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/type.pb.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/type.pb.cc @@ -40,11 +40,30 @@ const ::google::protobuf::EnumDescriptor* file_level_enum_descriptors[3]; } // namespace +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField + const TableStruct::entries[] = { + {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, +}; + +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField + const TableStruct::aux[] = { + ::google::protobuf::internal::AuxillaryParseTableField(), +}; +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const + TableStruct::schema[] = { + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, +}; + const ::google::protobuf::uint32 TableStruct::offsets[] = { ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Type, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Type, name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Type, fields_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Type, oneofs_), @@ -55,6 +74,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, kind_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, cardinality_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, number_), @@ -69,6 +89,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Enum, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Enum, name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Enum, enumvalue_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Enum, options_), @@ -78,6 +99,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValue, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValue, name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValue, number_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValue, options_), @@ -85,16 +107,17 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Option, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Option, name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Option, value_), }; static const ::google::protobuf::internal::MigrationSchema schemas[] = { { 0, -1, sizeof(Type)}, - { 10, -1, sizeof(Field)}, - { 24, -1, sizeof(Enum)}, - { 33, -1, sizeof(EnumValue)}, - { 40, -1, sizeof(Option)}, + { 11, -1, sizeof(Field)}, + { 26, -1, sizeof(Enum)}, + { 36, -1, sizeof(EnumValue)}, + { 44, -1, sizeof(Option)}, }; static ::google::protobuf::Message const * const file_default_instances[] = { @@ -449,7 +472,7 @@ void Type::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* Type::descriptor() { protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[0].descriptor; + return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const Type& Type::default_instance() { @@ -504,13 +527,11 @@ bool Type::MergePartialFromCodedStream( case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(18u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_fields())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -535,13 +556,11 @@ bool Type::MergePartialFromCodedStream( case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(34u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_options())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -596,6 +615,9 @@ failure: void Type::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.Type) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // string name = 1; if (this->name().size() > 0) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -645,8 +667,10 @@ 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; + // string name = 1; if (this->name().size() > 0) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -662,7 +686,7 @@ void Type::SerializeWithCachedSizes( for (unsigned int i = 0, n = this->fields_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 2, this->fields(i), false, target); + 2, this->fields(i), deterministic, target); } // repeated string oneofs = 3; @@ -679,14 +703,14 @@ void Type::SerializeWithCachedSizes( for (unsigned int i = 0, n = this->options_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 4, this->options(i), false, target); + 4, this->options(i), deterministic, target); } // .google.protobuf.SourceContext source_context = 5; if (this->has_source_context()) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 5, *this->source_context_, false, target); + 5, *this->source_context_, deterministic, target); } // .google.protobuf.Syntax syntax = 6; @@ -779,6 +803,9 @@ void Type::MergeFrom(const Type& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Type) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + fields_.MergeFrom(from.fields_); oneofs_.MergeFrom(from.oneofs_); options_.MergeFrom(from.options_); @@ -831,9 +858,9 @@ void Type::UnsafeArenaSwap(Type* other) { InternalSwap(other); } void Type::InternalSwap(Type* other) { - fields_.UnsafeArenaSwap(&other->fields_); - oneofs_.UnsafeArenaSwap(&other->oneofs_); - options_.UnsafeArenaSwap(&other->options_); + fields_.InternalSwap(&other->fields_); + oneofs_.InternalSwap(&other->oneofs_); + options_.InternalSwap(&other->options_); name_.Swap(&other->name_); std::swap(source_context_, other->source_context_); std::swap(syntax_, other->syntax_); @@ -842,7 +869,7 @@ void Type::InternalSwap(Type* other) { ::google::protobuf::Metadata Type::GetMetadata() const { protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[0]; + return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -862,6 +889,7 @@ void Type::set_name(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.Type.name) } void Type::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArenaNoVirtual()); @@ -970,6 +998,7 @@ void Type::set_oneofs(int index, ::std::string&& value) { } #endif void Type::set_oneofs(int index, const char* value) { + GOOGLE_DCHECK(value != NULL); oneofs_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.Type.oneofs) } @@ -988,11 +1017,12 @@ void Type::add_oneofs(const ::std::string& value) { } #if LANG_CXX11 void Type::add_oneofs(::std::string&& value) { - oneofs_.Add()->assign(std::move(value)); + oneofs_.Add(std::move(value)); // @@protoc_insertion_point(field_add:google.protobuf.Type.oneofs) } #endif void Type::add_oneofs(const char* value) { + GOOGLE_DCHECK(value != NULL); oneofs_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.Type.oneofs) } @@ -1214,7 +1244,7 @@ void Field::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* Field::descriptor() { protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[1].descriptor; + return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const Field& Field::default_instance() { @@ -1355,13 +1385,11 @@ bool Field::MergePartialFromCodedStream( case 9: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(74u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_options())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -1421,6 +1449,9 @@ failure: void Field::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.Field) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // .google.protobuf.Field.Kind kind = 1; if (this->kind() != 0) { ::google::protobuf::internal::WireFormatLite::WriteEnum( @@ -1499,8 +1530,10 @@ 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; + // .google.protobuf.Field.Kind kind = 1; if (this->kind() != 0) { target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray( @@ -1554,7 +1587,7 @@ void Field::SerializeWithCachedSizes( for (unsigned int i = 0, n = this->options_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 9, this->options(i), false, target); + 9, this->options(i), deterministic, target); } // string json_name = 10; @@ -1683,6 +1716,9 @@ void Field::MergeFrom(const Field& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Field) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + options_.MergeFrom(from.options_); if (from.name().size() > 0) { set_name(from.name()); @@ -1751,7 +1787,7 @@ void Field::UnsafeArenaSwap(Field* other) { InternalSwap(other); } void Field::InternalSwap(Field* other) { - options_.UnsafeArenaSwap(&other->options_); + options_.InternalSwap(&other->options_); name_.Swap(&other->name_); type_url_.Swap(&other->type_url_); json_name_.Swap(&other->json_name_); @@ -1766,7 +1802,7 @@ void Field::InternalSwap(Field* other) { ::google::protobuf::Metadata Field::GetMetadata() const { protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[1]; + return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -1828,6 +1864,7 @@ void Field::set_name(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.Field.name) } void Field::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArenaNoVirtual()); @@ -1894,6 +1931,7 @@ void Field::set_type_url(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.Field.type_url) } void Field::set_type_url(const char* value) { + GOOGLE_DCHECK(value != NULL); type_url_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArenaNoVirtual()); @@ -2018,6 +2056,7 @@ void Field::set_json_name(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.Field.json_name) } void Field::set_json_name(const char* value) { + GOOGLE_DCHECK(value != NULL); json_name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArenaNoVirtual()); @@ -2084,6 +2123,7 @@ void Field::set_default_value(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.Field.default_value) } void Field::set_default_value(const char* value) { + GOOGLE_DCHECK(value != NULL); default_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArenaNoVirtual()); @@ -2259,7 +2299,7 @@ void Enum::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* Enum::descriptor() { protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[2].descriptor; + return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const Enum& Enum::default_instance() { @@ -2313,13 +2353,11 @@ bool Enum::MergePartialFromCodedStream( case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(18u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_enumvalue())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -2327,13 +2365,11 @@ bool Enum::MergePartialFromCodedStream( case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(26u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_options())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -2388,6 +2424,9 @@ failure: void Enum::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.Enum) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // string name = 1; if (this->name().size() > 0) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -2427,8 +2466,10 @@ 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; + // string name = 1; if (this->name().size() > 0) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -2444,21 +2485,21 @@ void Enum::SerializeWithCachedSizes( for (unsigned int i = 0, n = this->enumvalue_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 2, this->enumvalue(i), false, target); + 2, this->enumvalue(i), deterministic, target); } // repeated .google.protobuf.Option options = 3; for (unsigned int i = 0, n = this->options_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 3, this->options(i), false, target); + 3, this->options(i), deterministic, target); } // .google.protobuf.SourceContext source_context = 4; if (this->has_source_context()) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 4, *this->source_context_, false, target); + 4, *this->source_context_, deterministic, target); } // .google.protobuf.Syntax syntax = 5; @@ -2543,6 +2584,9 @@ void Enum::MergeFrom(const Enum& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Enum) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + enumvalue_.MergeFrom(from.enumvalue_); options_.MergeFrom(from.options_); if (from.name().size() > 0) { @@ -2594,8 +2638,8 @@ void Enum::UnsafeArenaSwap(Enum* other) { InternalSwap(other); } void Enum::InternalSwap(Enum* other) { - enumvalue_.UnsafeArenaSwap(&other->enumvalue_); - options_.UnsafeArenaSwap(&other->options_); + enumvalue_.InternalSwap(&other->enumvalue_); + options_.InternalSwap(&other->options_); name_.Swap(&other->name_); std::swap(source_context_, other->source_context_); std::swap(syntax_, other->syntax_); @@ -2604,7 +2648,7 @@ void Enum::InternalSwap(Enum* other) { ::google::protobuf::Metadata Enum::GetMetadata() const { protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[2]; + return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -2624,6 +2668,7 @@ void Enum::set_name(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.Enum.name) } void Enum::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArenaNoVirtual()); @@ -2878,7 +2923,7 @@ void EnumValue::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* EnumValue::descriptor() { protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[3].descriptor; + return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const EnumValue& EnumValue::default_instance() { @@ -2941,13 +2986,11 @@ bool EnumValue::MergePartialFromCodedStream( case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(26u)) { - DO_(input->IncrementRecursionDepth()); - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_options())); } else { goto handle_unusual; } - input->UnsafeDecrementRecursionDepth(); break; } @@ -2975,6 +3018,9 @@ failure: void EnumValue::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.EnumValue) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // string name = 1; if (this->name().size() > 0) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -3001,8 +3047,10 @@ 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; + // string name = 1; if (this->name().size() > 0) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -3023,7 +3071,7 @@ void EnumValue::SerializeWithCachedSizes( for (unsigned int i = 0, n = this->options_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 3, this->options(i), false, target); + 3, this->options(i), deterministic, target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.EnumValue) @@ -3085,6 +3133,9 @@ void EnumValue::MergeFrom(const EnumValue& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumValue) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + options_.MergeFrom(from.options_); if (from.name().size() > 0) { set_name(from.name()); @@ -3132,7 +3183,7 @@ void EnumValue::UnsafeArenaSwap(EnumValue* other) { InternalSwap(other); } void EnumValue::InternalSwap(EnumValue* other) { - options_.UnsafeArenaSwap(&other->options_); + options_.InternalSwap(&other->options_); name_.Swap(&other->name_); std::swap(number_, other->number_); std::swap(_cached_size_, other->_cached_size_); @@ -3140,7 +3191,7 @@ void EnumValue::InternalSwap(EnumValue* other) { ::google::protobuf::Metadata EnumValue::GetMetadata() const { protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[3]; + return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -3160,6 +3211,7 @@ void EnumValue::set_name(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.EnumValue.name) } void EnumValue::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArenaNoVirtual()); @@ -3370,7 +3422,7 @@ void Option::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* Option::descriptor() { protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[4].descriptor; + return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const Option& Option::default_instance() { @@ -3453,6 +3505,9 @@ failure: void Option::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.Option) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // string name = 1; if (this->name().size() > 0) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -3474,8 +3529,10 @@ 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; + // string name = 1; if (this->name().size() > 0) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -3491,7 +3548,7 @@ void Option::SerializeWithCachedSizes( if (this->has_value()) { target = ::google::protobuf::internal::WireFormatLite:: InternalWriteMessageNoVirtualToArray( - 2, *this->value_, false, target); + 2, *this->value_, deterministic, target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Option) @@ -3542,6 +3599,9 @@ void Option::MergeFrom(const Option& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Option) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + if (from.name().size() > 0) { set_name(from.name()); } @@ -3595,7 +3655,7 @@ void Option::InternalSwap(Option* other) { ::google::protobuf::Metadata Option::GetMetadata() const { protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[4]; + return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -3615,6 +3675,7 @@ void Option::set_name(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.Option.name) } void Option::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArenaNoVirtual()); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/type.pb.h b/third_party/protobuf/3.2.0/src/google/protobuf/type.pb.h index ae81600885..c1cd41640d 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/type.pb.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/type.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3002000 +#if GOOGLE_PROTOBUF_VERSION < 3003000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003000 < 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. @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -64,6 +65,9 @@ namespace protobuf { namespace protobuf_google_2fprotobuf_2ftype_2eproto { // Internal implementation detail -- do not call these. struct LIBPROTOBUF_EXPORT TableStruct { + static const ::google::protobuf::internal::ParseTableField entries[]; + static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; + static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; static void InitDefaultsImpl(); static void Shutdown(); @@ -181,6 +185,8 @@ class LIBPROTOBUF_EXPORT Type : public ::google::protobuf::Message /* @@protoc_i return reinterpret_cast( &_Type_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 0; void UnsafeArenaSwap(Type* other); void Swap(Type* other); @@ -204,11 +210,6 @@ class LIBPROTOBUF_EXPORT Type : public ::google::protobuf::Message /* @@protoc_i ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -331,7 +332,7 @@ class LIBPROTOBUF_EXPORT Type : public ::google::protobuf::Message /* @@protoc_i ::google::protobuf::SourceContext* source_context_; int syntax_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2ftype_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2ftype_2eproto::TableStruct; }; // ------------------------------------------------------------------- @@ -360,6 +361,8 @@ class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_ return reinterpret_cast( &_Field_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 1; void UnsafeArenaSwap(Field* other); void Swap(Field* other); @@ -383,11 +386,6 @@ class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -620,7 +618,7 @@ class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_ ::google::protobuf::int32 oneof_index_; bool packed_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2ftype_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2ftype_2eproto::TableStruct; }; // ------------------------------------------------------------------- @@ -649,6 +647,8 @@ class LIBPROTOBUF_EXPORT Enum : public ::google::protobuf::Message /* @@protoc_i return reinterpret_cast( &_Enum_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 2; void UnsafeArenaSwap(Enum* other); void Swap(Enum* other); @@ -672,11 +672,6 @@ class LIBPROTOBUF_EXPORT Enum : public ::google::protobuf::Message /* @@protoc_i ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -776,7 +771,7 @@ class LIBPROTOBUF_EXPORT Enum : public ::google::protobuf::Message /* @@protoc_i ::google::protobuf::SourceContext* source_context_; int syntax_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2ftype_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2ftype_2eproto::TableStruct; }; // ------------------------------------------------------------------- @@ -805,6 +800,8 @@ class LIBPROTOBUF_EXPORT EnumValue : public ::google::protobuf::Message /* @@pro return reinterpret_cast( &_EnumValue_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 3; void UnsafeArenaSwap(EnumValue* other); void Swap(EnumValue* other); @@ -828,11 +825,6 @@ class LIBPROTOBUF_EXPORT EnumValue : public ::google::protobuf::Message /* @@pro ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -902,7 +894,7 @@ class LIBPROTOBUF_EXPORT EnumValue : public ::google::protobuf::Message /* @@pro ::google::protobuf::internal::ArenaStringPtr name_; ::google::protobuf::int32 number_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2ftype_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2ftype_2eproto::TableStruct; }; // ------------------------------------------------------------------- @@ -931,6 +923,8 @@ class LIBPROTOBUF_EXPORT Option : public ::google::protobuf::Message /* @@protoc return reinterpret_cast( &_Option_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 4; void UnsafeArenaSwap(Option* other); void Swap(Option* other); @@ -954,11 +948,6 @@ class LIBPROTOBUF_EXPORT Option : public ::google::protobuf::Message /* @@protoc ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -1025,7 +1014,7 @@ class LIBPROTOBUF_EXPORT Option : public ::google::protobuf::Message /* @@protoc ::google::protobuf::internal::ArenaStringPtr name_; ::google::protobuf::Any* value_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2ftype_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2ftype_2eproto::TableStruct; }; // =================================================================== @@ -1049,6 +1038,7 @@ inline void Type::set_name(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.Type.name) } inline void Type::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArenaNoVirtual()); @@ -1157,6 +1147,7 @@ inline void Type::set_oneofs(int index, ::std::string&& value) { } #endif inline void Type::set_oneofs(int index, const char* value) { + GOOGLE_DCHECK(value != NULL); oneofs_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.Type.oneofs) } @@ -1175,11 +1166,12 @@ inline void Type::add_oneofs(const ::std::string& value) { } #if LANG_CXX11 inline void Type::add_oneofs(::std::string&& value) { - oneofs_.Add()->assign(std::move(value)); + oneofs_.Add(std::move(value)); // @@protoc_insertion_point(field_add:google.protobuf.Type.oneofs) } #endif inline void Type::add_oneofs(const char* value) { + GOOGLE_DCHECK(value != NULL); oneofs_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.Type.oneofs) } @@ -1353,6 +1345,7 @@ inline void Field::set_name(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.Field.name) } inline void Field::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArenaNoVirtual()); @@ -1419,6 +1412,7 @@ inline void Field::set_type_url(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.Field.type_url) } inline void Field::set_type_url(const char* value) { + GOOGLE_DCHECK(value != NULL); type_url_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArenaNoVirtual()); @@ -1543,6 +1537,7 @@ inline void Field::set_json_name(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.Field.json_name) } inline void Field::set_json_name(const char* value) { + GOOGLE_DCHECK(value != NULL); json_name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArenaNoVirtual()); @@ -1609,6 +1604,7 @@ inline void Field::set_default_value(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.Field.default_value) } inline void Field::set_default_value(const char* value) { + GOOGLE_DCHECK(value != NULL); default_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArenaNoVirtual()); @@ -1679,6 +1675,7 @@ inline void Enum::set_name(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.Enum.name) } inline void Enum::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArenaNoVirtual()); @@ -1874,6 +1871,7 @@ inline void EnumValue::set_name(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.EnumValue.name) } inline void EnumValue::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArenaNoVirtual()); @@ -1988,6 +1986,7 @@ inline void Option::set_name(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.Option.name) } inline void Option::set_name(const char* value) { + GOOGLE_DCHECK(value != NULL); name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArenaNoVirtual()); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/unittest.proto b/third_party/protobuf/3.2.0/src/google/protobuf/unittest.proto index 188a4f478c..2040487e83 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/unittest.proto +++ b/third_party/protobuf/3.2.0/src/google/protobuf/unittest.proto @@ -433,7 +433,14 @@ message TestRecursiveMessage { // Test that mutual recursion works. message TestMutualRecursionA { + message SubMessage { + optional TestMutualRecursionB b = 1; + } optional TestMutualRecursionB bb = 1; + optional group SubGroup = 2 { + optional SubMessage sub_message = 3; // Needed because of bug in javatest + optional TestAllTypes not_in_this_scc = 4; + } } message TestMutualRecursionB { @@ -441,6 +448,15 @@ message TestMutualRecursionB { optional int32 optional_int32 = 2; } +message TestIsInitialized { + message SubMessage { + optional group SubGroup = 1 { + required int32 i = 2; + } + } + optional SubMessage sub_message = 1; +} + // Test that groups have disjoint field numbers from their siblings and // parents. This is NOT possible in proto1; only google.protobuf. When attempting // to compile with proto1, this will emit an error; so we only include it diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/unittest_lazy_dependencies.proto b/third_party/protobuf/3.2.0/src/google/protobuf/unittest_lazy_dependencies.proto new file mode 100644 index 0000000000..2f5efd2aaa --- /dev/null +++ b/third_party/protobuf/3.2.0/src/google/protobuf/unittest_lazy_dependencies.proto @@ -0,0 +1,75 @@ +// 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: trafacz@google.com (Todd Rafacz) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// A proto file we will use for unit testing. + +syntax = "proto2"; + +import "google/protobuf/unittest_lazy_dependencies_custom_option.proto"; + +// Some generic_services option(s) added automatically. +// See: http://go/proto2-generic-services-default +option cc_generic_services = true; // auto-added +option java_generic_services = true; // auto-added +option py_generic_services = true; // auto-added +option cc_enable_arenas = true; + +// We don't put this in a package within proto2 because we need to make sure +// that the generated code doesn't depend on being in the proto2 namespace. +// In test_util.h we do "using namespace unittest = protobuf_unittest". +package protobuf_unittest.lazy_imports; + +// Protos optimized for SPEED use a strict superset of the generated code +// of equivalent ones optimized for CODE_SIZE, so we should optimize all our +// tests for speed unless explicitly testing code size optimization. +option optimize_for = SPEED; + +option java_outer_classname = "UnittestLazyImportsProto"; + +// The following are used to test that the proto file +// with the definition of the following field types is +// not built when this proto file is built. Then test +// that calling message_type() etc will build the correct +// descriptor lazily and return it. + +message ImportedMessage { + optional LazyMessage lazy_message = 1; +} + +message MessageCustomOption { +} + +message MessageCustomOption2 { + option (lazy_enum_option) = LAZY_ENUM_0; +} diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/unittest_lazy_dependencies_custom_option.proto b/third_party/protobuf/3.2.0/src/google/protobuf/unittest_lazy_dependencies_custom_option.proto new file mode 100644 index 0000000000..22438257d3 --- /dev/null +++ b/third_party/protobuf/3.2.0/src/google/protobuf/unittest_lazy_dependencies_custom_option.proto @@ -0,0 +1,67 @@ +// 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: trafacz@google.com (Todd Rafacz) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// A proto file we will use for unit testing. + +syntax = "proto2"; + +import "google/protobuf/unittest_lazy_dependencies_enum.proto"; +import "google/protobuf/descriptor.proto"; + +// Some generic_services option(s) added automatically. +// See: http://go/proto2-generic-services-default +option cc_generic_services = true; // auto-added +option java_generic_services = true; // auto-added +option py_generic_services = true; // auto-added +option cc_enable_arenas = true; + +// We don't put this in a package within proto2 because we need to make sure +// that the generated code doesn't depend on being in the proto2 namespace. +// In test_util.h we do "using namespace unittest = protobuf_unittest". +package protobuf_unittest.lazy_imports; + +// Protos optimized for SPEED use a strict superset of the generated code +// of equivalent ones optimized for CODE_SIZE, so we should optimize all our +// tests for speed unless explicitly testing code size optimization. +option optimize_for = SPEED; + +option java_outer_classname = "UnittestLazyImportsCustomOptionProto"; + +message LazyMessage { + optional int32 a = 1; +} + +extend google.protobuf.MessageOptions { + optional LazyEnum lazy_enum_option = 138596335 [default = LAZY_ENUM_1]; +} diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/unittest_lazy_dependencies_enum.proto b/third_party/protobuf/3.2.0/src/google/protobuf/unittest_lazy_dependencies_enum.proto new file mode 100644 index 0000000000..9be64d8580 --- /dev/null +++ b/third_party/protobuf/3.2.0/src/google/protobuf/unittest_lazy_dependencies_enum.proto @@ -0,0 +1,61 @@ +// 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: trafacz@google.com (Todd Rafacz) +// Based on original Protocol Buffers design by +// Sanjay Ghemawat, Jeff Dean, and others. +// +// A proto file we will use for unit testing. + +syntax = "proto2"; + +// Some generic_services option(s) added automatically. +// See: http://go/proto2-generic-services-default +option cc_generic_services = true; // auto-added +option java_generic_services = true; // auto-added +option py_generic_services = true; // auto-added +option cc_enable_arenas = true; + +// We don't put this in a package within proto2 because we need to make sure +// that the generated code doesn't depend on being in the proto2 namespace. +// In test_util.h we do "using namespace unittest = protobuf_unittest". +package protobuf_unittest.lazy_imports; + +// Protos optimized for SPEED use a strict superset of the generated code +// of equivalent ones optimized for CODE_SIZE, so we should optimize all our +// tests for speed unless explicitly testing code size optimization. +option optimize_for = SPEED; + +option java_outer_classname = "UnittestLazyImportsEnumProto"; + +enum LazyEnum { + LAZY_ENUM_0 = 0; + LAZY_ENUM_1 = 1; +} diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/unittest_proto3_arena.proto b/third_party/protobuf/3.2.0/src/google/protobuf/unittest_proto3_arena.proto index b835a6ba36..9375d85ae0 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/unittest_proto3_arena.proto +++ b/third_party/protobuf/3.2.0/src/google/protobuf/unittest_proto3_arena.proto @@ -96,6 +96,8 @@ message TestAllTypes { optional_public_import_message = 26; NestedMessage optional_lazy_message = 27 [lazy=true]; + protobuf_unittest_import.ImportMessage optional_lazy_import_message = 115 + [lazy = true]; // Repeated repeated int32 repeated_int32 = 31; diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/unknown_field_set.cc b/third_party/protobuf/3.2.0/src/google/protobuf/unknown_field_set.cc index 9472c4fa5f..0ada85e570 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/unknown_field_set.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/unknown_field_set.cc @@ -123,21 +123,21 @@ void UnknownFieldSet::MergeToInternalMetdata( metadata->mutable_unknown_fields()->MergeFrom(other); } -int UnknownFieldSet::SpaceUsedExcludingSelf() const { +size_t UnknownFieldSet::SpaceUsedExcludingSelfLong() const { if (fields_ == NULL) return 0; - int total_size = sizeof(*fields_) + sizeof(UnknownField) * fields_->size(); + size_t total_size = sizeof(*fields_) + sizeof(UnknownField) * fields_->size(); for (int i = 0; i < fields_->size(); i++) { const UnknownField& field = (*fields_)[i]; switch (field.type()) { case UnknownField::TYPE_LENGTH_DELIMITED: - total_size += sizeof(*field.length_delimited_.string_value_) + - internal::StringSpaceUsedExcludingSelf( - *field.length_delimited_.string_value_); + total_size += sizeof(*field.data_.length_delimited_.string_value_) + + internal::StringSpaceUsedExcludingSelfLong( + *field.data_.length_delimited_.string_value_); break; case UnknownField::TYPE_GROUP: - total_size += field.group_->SpaceUsed(); + total_size += field.data_.group_->SpaceUsedLong(); break; default: break; @@ -146,7 +146,7 @@ int UnknownFieldSet::SpaceUsedExcludingSelf() const { return total_size; } -int UnknownFieldSet::SpaceUsed() const { +size_t UnknownFieldSet::SpaceUsedLong() const { return sizeof(*this) + SpaceUsedExcludingSelf(); } @@ -154,7 +154,7 @@ void UnknownFieldSet::AddVarint(int number, uint64 value) { UnknownField field; field.number_ = number; field.SetType(UnknownField::TYPE_VARINT); - field.varint_ = value; + field.data_.varint_ = value; if (fields_ == NULL) fields_ = new std::vector(); fields_->push_back(field); } @@ -163,7 +163,7 @@ void UnknownFieldSet::AddFixed32(int number, uint32 value) { UnknownField field; field.number_ = number; field.SetType(UnknownField::TYPE_FIXED32); - field.fixed32_ = value; + field.data_.fixed32_ = value; if (fields_ == NULL) fields_ = new std::vector(); fields_->push_back(field); } @@ -172,7 +172,7 @@ void UnknownFieldSet::AddFixed64(int number, uint64 value) { UnknownField field; field.number_ = number; field.SetType(UnknownField::TYPE_FIXED64); - field.fixed64_ = value; + field.data_.fixed64_ = value; if (fields_ == NULL) fields_ = new std::vector(); fields_->push_back(field); } @@ -181,10 +181,10 @@ string* UnknownFieldSet::AddLengthDelimited(int number) { UnknownField field; field.number_ = number; field.SetType(UnknownField::TYPE_LENGTH_DELIMITED); - field.length_delimited_.string_value_ = new string; + field.data_.length_delimited_.string_value_ = new string; if (fields_ == NULL) fields_ = new std::vector(); fields_->push_back(field); - return field.length_delimited_.string_value_; + return field.data_.length_delimited_.string_value_; } @@ -192,10 +192,10 @@ UnknownFieldSet* UnknownFieldSet::AddGroup(int number) { UnknownField field; field.number_ = number; field.SetType(UnknownField::TYPE_GROUP); - field.group_ = new UnknownFieldSet; + field.data_.group_ = new UnknownFieldSet; if (fields_ == NULL) fields_ = new std::vector(); fields_->push_back(field); - return field.group_; + return field.data_.group_; } void UnknownFieldSet::AddField(const UnknownField& field) { @@ -276,10 +276,10 @@ bool UnknownFieldSet::ParseFromArray(const void* data, int size) { void UnknownField::Delete() { switch (type()) { case UnknownField::TYPE_LENGTH_DELIMITED: - delete length_delimited_.string_value_; + delete data_.length_delimited_.string_value_; break; case UnknownField::TYPE_GROUP: - delete group_; + delete data_.group_; break; default: break; @@ -291,10 +291,10 @@ void UnknownField::Delete() { void UnknownField::Reset() { switch (type()) { case UnknownField::TYPE_LENGTH_DELIMITED: - length_delimited_.string_value_ = NULL; + data_.length_delimited_.string_value_ = NULL; break; case UnknownField::TYPE_GROUP: { - group_ = NULL; + data_.group_ = NULL; break; } default: @@ -305,13 +305,13 @@ void UnknownField::Reset() { void UnknownField::DeepCopy(const UnknownField& other) { switch (type()) { case UnknownField::TYPE_LENGTH_DELIMITED: - length_delimited_.string_value_ = new string( - *length_delimited_.string_value_); + data_.length_delimited_.string_value_ = new string( + *data_.length_delimited_.string_value_); break; case UnknownField::TYPE_GROUP: { UnknownFieldSet* group = new UnknownFieldSet(); - group->InternalMergeFrom(*group_); - group_ = group; + group->InternalMergeFrom(*data_.group_); + data_.group_ = group; break; } default: @@ -323,14 +323,14 @@ void UnknownField::DeepCopy(const UnknownField& other) { void UnknownField::SerializeLengthDelimitedNoTag( io::CodedOutputStream* output) const { GOOGLE_DCHECK_EQ(TYPE_LENGTH_DELIMITED, type()); - const string& data = *length_delimited_.string_value_; + const string& data = *data_.length_delimited_.string_value_; output->WriteVarint32(data.size()); output->WriteRawMaybeAliased(data.data(), data.size()); } uint8* UnknownField::SerializeLengthDelimitedNoTagToArray(uint8* target) const { GOOGLE_DCHECK_EQ(TYPE_LENGTH_DELIMITED, type()); - const string& data = *length_delimited_.string_value_; + const string& data = *data_.length_delimited_.string_value_; target = io::CodedOutputStream::WriteVarint32ToArray(data.size(), target); target = io::CodedOutputStream::WriteStringToArray(data, target); return target; diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/unknown_field_set.h b/third_party/protobuf/3.2.0/src/google/protobuf/unknown_field_set.h index c2ad89182d..002ea8e849 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/unknown_field_set.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/unknown_field_set.h @@ -43,6 +43,7 @@ #include #include #include +#include namespace google { namespace protobuf { @@ -106,10 +107,18 @@ class LIBPROTOBUF_EXPORT UnknownFieldSet { // Computes (an estimate of) the total number of bytes currently used for // storing the unknown fields in memory. Does NOT include // sizeof(*this) in the calculation. - int SpaceUsedExcludingSelf() const; + size_t SpaceUsedExcludingSelfLong() const; + + int SpaceUsedExcludingSelf() const { + return internal::ToIntSize(SpaceUsedExcludingSelfLong()); + } // Version of SpaceUsed() including sizeof(*this). - int SpaceUsed() const; + size_t SpaceUsedLong() const; + + int SpaceUsed() const { + return internal::ToIntSize(SpaceUsedLong()); + } // Returns the number of fields present in the UnknownFieldSet. inline int field_count() const; @@ -214,8 +223,6 @@ class LIBPROTOBUF_EXPORT UnknownField { inline size_t GetLengthDelimitedSize() const; - private: - friend class UnknownFieldSet; // If this UnknownField contains a pointer, delete it. void Delete(); @@ -243,7 +250,7 @@ class LIBPROTOBUF_EXPORT UnknownField { uint64 fixed64_; mutable union LengthDelimited length_delimited_; UnknownFieldSet* group_; - }; + } data_; }; // =================================================================== @@ -287,6 +294,8 @@ inline void UnknownFieldSet::AddLengthDelimited( } + + inline int UnknownField::number() const { return number_; } inline UnknownField::Type UnknownField::type() const { return static_cast(type_); @@ -294,53 +303,53 @@ inline UnknownField::Type UnknownField::type() const { inline uint64 UnknownField::varint() const { assert(type() == TYPE_VARINT); - return varint_; + return data_.varint_; } inline uint32 UnknownField::fixed32() const { assert(type() == TYPE_FIXED32); - return fixed32_; + return data_.fixed32_; } inline uint64 UnknownField::fixed64() const { assert(type() == TYPE_FIXED64); - return fixed64_; + return data_.fixed64_; } inline const string& UnknownField::length_delimited() const { assert(type() == TYPE_LENGTH_DELIMITED); - return *length_delimited_.string_value_; + return *data_.length_delimited_.string_value_; } inline const UnknownFieldSet& UnknownField::group() const { assert(type() == TYPE_GROUP); - return *group_; + return *data_.group_; } inline void UnknownField::set_varint(uint64 value) { assert(type() == TYPE_VARINT); - varint_ = value; + data_.varint_ = value; } inline void UnknownField::set_fixed32(uint32 value) { assert(type() == TYPE_FIXED32); - fixed32_ = value; + data_.fixed32_ = value; } inline void UnknownField::set_fixed64(uint64 value) { assert(type() == TYPE_FIXED64); - fixed64_ = value; + data_.fixed64_ = value; } inline void UnknownField::set_length_delimited(const string& value) { assert(type() == TYPE_LENGTH_DELIMITED); - length_delimited_.string_value_->assign(value); + data_.length_delimited_.string_value_->assign(value); } inline string* UnknownField::mutable_length_delimited() { assert(type() == TYPE_LENGTH_DELIMITED); - return length_delimited_.string_value_; + return data_.length_delimited_.string_value_; } inline UnknownFieldSet* UnknownField::mutable_group() { assert(type() == TYPE_GROUP); - return group_; + return data_.group_; } inline size_t UnknownField::GetLengthDelimitedSize() const { GOOGLE_DCHECK_EQ(TYPE_LENGTH_DELIMITED, type()); - return length_delimited_.string_value_->size(); + return data_.length_delimited_.string_value_->size(); } inline void UnknownField::SetType(Type type) { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/util/delimited_message_util_test.cc b/third_party/protobuf/3.2.0/src/google/protobuf/util/delimited_message_util_test.cc index b261d43cc9..157a84112c 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/util/delimited_message_util_test.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/util/delimited_message_util_test.cc @@ -15,7 +15,7 @@ namespace protobuf { namespace util { TEST(DelimitedMessageUtilTest, DelimitedMessages) { - stringstream stream; + std::stringstream stream; { protobuf_unittest::TestAllTypes message1; diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/default_value_objectwriter.cc b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/default_value_objectwriter.cc index b33ad20699..5763d0c612 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/default_value_objectwriter.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/default_value_objectwriter.cc @@ -189,6 +189,39 @@ void DefaultValueObjectWriter::RegisterFieldScrubCallBack( field_scrub_callback_.reset(field_scrub_callback.release()); } +DefaultValueObjectWriter::Node* DefaultValueObjectWriter::CreateNewNode( + const string& name, const google::protobuf::Type* type, NodeKind kind, + const DataPiece& data, bool is_placeholder, const std::vector& path, + bool suppress_empty_list, FieldScrubCallBack* field_scrub_callback) { + return new Node(name, type, kind, data, is_placeholder, path, + suppress_empty_list, field_scrub_callback); +} + +DefaultValueObjectWriter::Node* DefaultValueObjectWriter::CreateNewNode( + const string& name, const google::protobuf::Type* type, NodeKind kind, + const DataPiece& data, bool is_placeholder, const std::vector& path, + bool suppress_empty_list, bool preserve_proto_field_names, + FieldScrubCallBack* field_scrub_callback) { + return new Node(name, type, kind, data, is_placeholder, path, + suppress_empty_list, preserve_proto_field_names, + field_scrub_callback); +} + +DefaultValueObjectWriter::Node::Node( + const string& name, const google::protobuf::Type* type, NodeKind kind, + const DataPiece& data, bool is_placeholder, const std::vector& path, + bool suppress_empty_list, FieldScrubCallBack* field_scrub_callback) + : name_(name), + type_(type), + kind_(kind), + is_any_(false), + data_(data), + is_placeholder_(is_placeholder), + path_(path), + suppress_empty_list_(suppress_empty_list), + preserve_proto_field_names_(false), + field_scrub_callback_(field_scrub_callback) {} + DefaultValueObjectWriter::Node::Node( const string& name, const google::protobuf::Type* type, NodeKind kind, const DataPiece& data, bool is_placeholder, const std::vector& path, @@ -473,10 +506,10 @@ DefaultValueObjectWriter* DefaultValueObjectWriter::StartObject( StringPiece name) { if (current_ == NULL) { std::vector path; - root_.reset(new Node(name.ToString(), &type_, OBJECT, DataPiece::NullData(), - false, path, suppress_empty_list_, - preserve_proto_field_names_, - field_scrub_callback_.get())); + root_.reset(CreateNewNode(string(name), &type_, OBJECT, + DataPiece::NullData(), false, path, + suppress_empty_list_, preserve_proto_field_names_, + field_scrub_callback_.get())); root_->PopulateChildren(typeinfo_); current_ = root_.get(); return this; @@ -486,14 +519,15 @@ DefaultValueObjectWriter* DefaultValueObjectWriter::StartObject( if (current_->kind() == LIST || current_->kind() == MAP || child == NULL) { // If current_ is a list or a map node, we should create a new child and use // the type of current_ as the type of the new child. - google::protobuf::scoped_ptr node(new Node( - name.ToString(), ((current_->kind() == LIST || current_->kind() == MAP) - ? current_->type() - : NULL), - OBJECT, DataPiece::NullData(), false, - child == NULL ? current_->path() : child->path(), - suppress_empty_list_, preserve_proto_field_names_, - field_scrub_callback_.get())); + google::protobuf::scoped_ptr node( + CreateNewNode(string(name), + ((current_->kind() == LIST || current_->kind() == MAP) + ? current_->type() + : NULL), + OBJECT, DataPiece::NullData(), false, + child == NULL ? current_->path() : child->path(), + suppress_empty_list_, preserve_proto_field_names_, + field_scrub_callback_.get())); child = node.get(); current_->AddChild(node.release()); } @@ -523,10 +557,10 @@ DefaultValueObjectWriter* DefaultValueObjectWriter::StartList( StringPiece name) { if (current_ == NULL) { std::vector path; - root_.reset(new Node(name.ToString(), &type_, LIST, DataPiece::NullData(), - false, path, suppress_empty_list_, - preserve_proto_field_names_, - field_scrub_callback_.get())); + root_.reset(CreateNewNode(string(name), &type_, LIST, DataPiece::NullData(), + false, path, suppress_empty_list_, + preserve_proto_field_names_, + field_scrub_callback_.get())); current_ = root_.get(); return this; } @@ -534,10 +568,10 @@ DefaultValueObjectWriter* DefaultValueObjectWriter::StartList( Node* child = current_->FindChild(name); if (child == NULL || child->kind() != LIST) { google::protobuf::scoped_ptr node( - new Node(name.ToString(), NULL, LIST, DataPiece::NullData(), false, - child == NULL ? current_->path() : child->path(), - suppress_empty_list_, preserve_proto_field_names_, - field_scrub_callback_.get())); + CreateNewNode(string(name), NULL, LIST, DataPiece::NullData(), false, + child == NULL ? current_->path() : child->path(), + suppress_empty_list_, preserve_proto_field_names_, + field_scrub_callback_.get())); child = node.get(); current_->AddChild(node.release()); } @@ -596,10 +630,10 @@ void DefaultValueObjectWriter::RenderDataPiece(StringPiece name, if (child == NULL || child->kind() != PRIMITIVE) { // No children are found, creates a new child. google::protobuf::scoped_ptr node( - new Node(name.ToString(), NULL, PRIMITIVE, data, false, - child == NULL ? current_->path() : child->path(), - suppress_empty_list_, preserve_proto_field_names_, - field_scrub_callback_.get())); + CreateNewNode(string(name), NULL, PRIMITIVE, data, false, + child == NULL ? current_->path() : child->path(), + suppress_empty_list_, preserve_proto_field_names_, + field_scrub_callback_.get())); current_->AddChild(node.release()); } else { child->set_data(data); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/default_value_objectwriter.h b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/default_value_objectwriter.h index ddf2359408..ef2cc98103 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/default_value_objectwriter.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/default_value_objectwriter.h @@ -127,9 +127,11 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter { void set_suppress_empty_list(bool value) { suppress_empty_list_ = value; } // If set to true, original proto field names are used - void set_preserve_proto_field_names(bool value) { preserve_proto_field_names_ = value; } + void set_preserve_proto_field_names(bool value) { + preserve_proto_field_names_ = value; + } - private: + protected: enum NodeKind { PRIMITIVE = 0, OBJECT = 1, @@ -144,7 +146,12 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter { Node(const string& name, const google::protobuf::Type* type, NodeKind kind, const DataPiece& data, bool is_placeholder, const std::vector& path, bool suppress_empty_list, - bool preserve_proto_field_names, FieldScrubCallBack* field_scrub_callback); + FieldScrubCallBack* field_scrub_callback); + Node(const string& name, const google::protobuf::Type* type, NodeKind kind, + const DataPiece& data, bool is_placeholder, + const std::vector& path, bool suppress_empty_list, + bool preserve_proto_field_names, + FieldScrubCallBack* field_scrub_callback); virtual ~Node() { for (int i = 0; i < children_.size(); ++i) { delete children_[i]; @@ -160,7 +167,7 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter { // Populates children of this Node based on its type. If there are already // children created, they will be merged to the result. Caller should pass // in TypeInfo for looking up types of the children. - void PopulateChildren(const TypeInfo* typeinfo); + virtual void PopulateChildren(const TypeInfo* typeinfo); // If this node is a leaf (has data), writes the current node to the // ObjectWriter; if not, then recursively writes the children to the @@ -190,7 +197,7 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter { is_placeholder_ = is_placeholder; } - private: + protected: // Returns the Value Type of a map given the Type of the map entry and a // TypeInfo instance. const google::protobuf::Type* GetMapValueType( @@ -230,9 +237,32 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter { // or not. This callback is owned by the creator of this node. FieldScrubCallBack* field_scrub_callback_; + private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Node); }; + // Creates a new Node and returns it. Caller owns memory of returned object. + virtual Node* CreateNewNode(const string& name, + const google::protobuf::Type* type, NodeKind kind, + const DataPiece& data, bool is_placeholder, + const std::vector& path, + bool suppress_empty_list, + FieldScrubCallBack* field_scrub_callback); + + // Creates a new Node and returns it. Caller owns memory of returned object. + virtual Node* CreateNewNode(const string& name, + const google::protobuf::Type* type, NodeKind kind, + const DataPiece& data, bool is_placeholder, + const std::vector& path, + bool suppress_empty_list, + bool preserve_proto_field_names, + FieldScrubCallBack* field_scrub_callback); + + // Creates a DataPiece containing the default value of the type of the field. + static DataPiece CreateDefaultDataPieceForField( + const google::protobuf::Field& field, const TypeInfo* typeinfo); + + private: // Populates children of "node" if it is an "any" Node and its real type has // been given. void MaybePopulateChildrenOfAny(Node* node); @@ -241,10 +271,6 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter { // NULL. void WriteRoot(); - // Creates a DataPiece containing the default value of the type of the field. - static DataPiece CreateDefaultDataPieceForField( - const google::protobuf::Field& field, const TypeInfo* typeinfo); - // Adds or replaces the data_ of a primitive child node. void RenderDataPiece(StringPiece name, const DataPiece& data); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/field_mask_utility.cc b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/field_mask_utility.cc index 53b90fb05d..38835f67d2 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/field_mask_utility.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/field_mask_utility.cc @@ -44,11 +44,6 @@ inline util::Status CallPathSink(PathSinkCallback path_sink, return path_sink->Run(arg); } -util::Status CreatePublicError(util::error::Code code, - const string& message) { - return util::Status(code, message); -} - // Appends a FieldMask path segment to a prefix. string AppendPathSegmentToPrefix(StringPiece prefix, StringPiece segment) { if (prefix.empty()) { @@ -216,7 +211,7 @@ util::Status DecodeCompactFieldMaskPaths(StringPiece paths, StrCat("Invalid FieldMask '", paths, "'. Cannot find matching ')' for all '('.")); } - return util::Status::OK; + return util::Status(); } } // namespace converter diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/json_escaping.cc b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/json_escaping.cc index 47e4dd6df9..18b7f92363 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/json_escaping.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/json_escaping.cc @@ -84,30 +84,6 @@ static const char kCommonEscapes[160][7] = { "\\u009c", "\\u009d", "\\u009e", "\\u009f" }; -// Determines if the given char value is a unicode high-surrogate code unit. -// Such values do not represent characters by themselves, but are used in the -// representation of supplementary characters in the utf-16 encoding. -inline bool IsHighSurrogate(uint16 c) { - // Optimized form of: - // return c >= kMinHighSurrogate && c <= kMaxHighSurrogate; - // (Reduced from 3 ALU instructions to 2 ALU instructions) - return (c & ~(JsonEscaping::kMaxHighSurrogate - - JsonEscaping::kMinHighSurrogate)) - == JsonEscaping::kMinHighSurrogate; -} - -// Determines if the given char value is a unicode low-surrogate code unit. -// Such values do not represent characters by themselves, but are used in the -// representation of supplementary characters in the utf-16 encoding. -inline bool IsLowSurrogate(uint16 c) { - // Optimized form of: - // return c >= kMinLowSurrogate && c <= kMaxLowSurrogate; - // (Reduced from 3 ALU instructions to 2 ALU instructions) - return (c & ~(JsonEscaping::kMaxLowSurrogate - - JsonEscaping::kMinLowSurrogate)) - == JsonEscaping::kMinLowSurrogate; -} - // Determines if the given char value is a unicode surrogate code unit (either // high-surrogate or low-surrogate). inline bool IsSurrogate(uint32 c) { @@ -117,36 +93,12 @@ inline bool IsSurrogate(uint32 c) { return (c & 0xfffff800) == JsonEscaping::kMinHighSurrogate; } -// Returns true if the given unicode code point cp is -// in the supplementary character range. -inline bool IsSupplementalCodePoint(uint32 cp) { - // Optimized form of: - // return kMinSupplementaryCodePoint <= cp && cp <= kMaxCodePoint; - // (Reduced from 3 ALU instructions to 2 ALU instructions) - return (cp & ~(JsonEscaping::kMinSupplementaryCodePoint - 1)) - < JsonEscaping::kMaxCodePoint; -} - // Returns true if the given unicode code point cp is a valid // unicode code point (i.e. in the range 0 <= cp <= kMaxCodePoint). inline bool IsValidCodePoint(uint32 cp) { return cp <= JsonEscaping::kMaxCodePoint; } -// Converts the specified surrogate pair to its supplementary code point value. -// It is the callers' responsibility to validate the specified surrogate pair. -inline uint32 ToCodePoint(uint16 high, uint16 low) { - // Optimized form of: - // return ((high - kMinHighSurrogate) << 10) - // + (low - kMinLowSurrogate) - // + kMinSupplementaryCodePoint; - // (Reduced from 5 ALU instructions to 3 ALU instructions) - return (high << 10) + low + - (JsonEscaping::kMinSupplementaryCodePoint - - (static_cast(JsonEscaping::kMinHighSurrogate) << 10) - - JsonEscaping::kMinLowSurrogate); -} - // Returns the low surrogate for the given unicode code point. The result is // meaningless if the given code point is not a supplementary character. inline uint16 ToLowSurrogate(uint32 cp) { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/json_stream_parser.cc b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/json_stream_parser.cc index b38030c3c6..047c14e150 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/json_stream_parser.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/json_stream_parser.cc @@ -130,7 +130,7 @@ util::Status JsonStreamParser::Parse(StringPiece json) { // Don't point chunk to leftover_ because leftover_ will be updated in // ParseChunk(chunk). chunk_storage_.swap(leftover_); - json.AppendToString(&chunk_storage_); + StrAppend(&chunk_storage_, json); chunk = StringPiece(chunk_storage_); } @@ -141,11 +141,11 @@ util::Status JsonStreamParser::Parse(StringPiece json) { // Any leftover characters are stashed in leftover_ for later parsing when // there is more data available. - chunk.substr(n).AppendToString(&leftover_); + StrAppend(&leftover_, chunk.substr(n)); return status; } else { - chunk.CopyToString(&leftover_); - return util::Status::OK; + leftover_.assign(chunk.data(), chunk.size()); + return util::Status(); } } @@ -153,7 +153,7 @@ util::Status JsonStreamParser::FinishParse() { // If we do not expect anything and there is nothing left to parse we're all // done. if (stack_.empty() && leftover_.empty()) { - return util::Status::OK; + return util::Status(); } // Storage for UTF8-coerced string. @@ -184,7 +184,7 @@ util::Status JsonStreamParser::FinishParse() { util::Status JsonStreamParser::ParseChunk(StringPiece chunk) { // Do not do any work if the chunk is empty. - if (chunk.empty()) return util::Status::OK; + if (chunk.empty()) return util::Status(); p_ = json_ = chunk; @@ -206,7 +206,7 @@ util::Status JsonStreamParser::ParseChunk(StringPiece chunk) { // unparsed data left, we save it for later parse. leftover_ = p_.ToString(); } - return util::Status::OK; + return util::Status(); } util::Status JsonStreamParser::RunParser() { @@ -252,15 +252,15 @@ util::Status JsonStreamParser::RunParser() { // If we have a key we still need to render, make sure to save off the // contents in our own storage. if (!key_.empty() && key_storage_.empty()) { - key_.AppendToString(&key_storage_); + StrAppend(&key_storage_, key_); key_ = StringPiece(key_storage_); } - result = util::Status::OK; + result = util::Status(); } return result; } } - return util::Status::OK; + return util::Status(); } util::Status JsonStreamParser::ParseValue(TokenType type) { @@ -386,7 +386,7 @@ util::Status JsonStreamParser::ParseStringHelper() { // start fresh. string_open_ = 0; Advance(); - return util::Status::OK; + return util::Status(); } // Normal character, just advance past it. Advance(); @@ -468,7 +468,7 @@ util::Status JsonStreamParser::ParseUnicodeEscape() { // Advance past the [final] code unit escape. p_.remove_prefix(kUnicodeEscapedLength); parsed_storage_.append(buf, len); - return util::Status::OK; + return util::Status(); } util::Status JsonStreamParser::ParseNumber() { @@ -542,7 +542,7 @@ util::Status JsonStreamParser::ParseNumberHelper(NumberResult* result) { } result->type = NumberResult::DOUBLE; p_.remove_prefix(index); - return util::Status::OK; + return util::Status(); } // Positive non-floating point number, parse as a uint64. @@ -556,7 +556,7 @@ util::Status JsonStreamParser::ParseNumberHelper(NumberResult* result) { } result->type = NumberResult::UINT; p_.remove_prefix(index); - return util::Status::OK; + return util::Status(); } // Octal/Hex numbers are not valid JSON values. @@ -569,7 +569,7 @@ util::Status JsonStreamParser::ParseNumberHelper(NumberResult* result) { } result->type = NumberResult::INT; p_.remove_prefix(index); - return util::Status::OK; + return util::Status(); } util::Status JsonStreamParser::HandleBeginObject() { @@ -578,7 +578,7 @@ util::Status JsonStreamParser::HandleBeginObject() { ow_->StartObject(key_); key_ = StringPiece(); stack_.push(ENTRY); - return util::Status::OK; + return util::Status(); } util::Status JsonStreamParser::ParseObjectMid(TokenType type) { @@ -590,13 +590,13 @@ util::Status JsonStreamParser::ParseObjectMid(TokenType type) { if (type == END_OBJECT) { Advance(); ow_->EndObject(); - return util::Status::OK; + return util::Status(); } // Found a comma, advance past it and get ready for an entry. if (type == VALUE_SEPARATOR) { Advance(); stack_.push(ENTRY); - return util::Status::OK; + return util::Status(); } // Illegal token after key:value pair. return ReportFailure("Expected , or } after key:value pair."); @@ -611,7 +611,7 @@ util::Status JsonStreamParser::ParseEntry(TokenType type) { if (type == END_OBJECT) { ow_->EndObject(); Advance(); - return util::Status::OK; + return util::Status(); } util::Status result; @@ -650,7 +650,7 @@ util::Status JsonStreamParser::ParseEntryMid(TokenType type) { if (type == ENTRY_SEPARATOR) { Advance(); stack_.push(VALUE); - return util::Status::OK; + return util::Status(); } return ReportFailure("Expected : between key:value pair."); } @@ -661,7 +661,7 @@ util::Status JsonStreamParser::HandleBeginArray() { ow_->StartList(key_); key_ = StringPiece(); stack_.push(ARRAY_VALUE); - return util::Status::OK; + return util::Status(); } util::Status JsonStreamParser::ParseArrayValue(TokenType type) { @@ -672,7 +672,7 @@ util::Status JsonStreamParser::ParseArrayValue(TokenType type) { if (type == END_ARRAY) { ow_->EndList(); Advance(); - return util::Status::OK; + return util::Status(); } // The ParseValue call may push something onto the stack so we need to make @@ -696,14 +696,14 @@ util::Status JsonStreamParser::ParseArrayMid(TokenType type) { if (type == END_ARRAY) { ow_->EndList(); Advance(); - return util::Status::OK; + return util::Status(); } // Found a comma, advance past it and expect an array value next. if (type == VALUE_SEPARATOR) { Advance(); stack_.push(ARRAY_VALUE); - return util::Status::OK; + return util::Status(); } // Illegal token after array value. return ReportFailure("Expected , or ] after array value."); @@ -713,27 +713,27 @@ util::Status JsonStreamParser::ParseTrue() { ow_->RenderBool(key_, true); key_ = StringPiece(); p_.remove_prefix(true_len); - return util::Status::OK; + return util::Status(); } util::Status JsonStreamParser::ParseFalse() { ow_->RenderBool(key_, false); key_ = StringPiece(); p_.remove_prefix(false_len); - return util::Status::OK; + return util::Status(); } util::Status JsonStreamParser::ParseNull() { ow_->RenderNull(key_); key_ = StringPiece(); p_.remove_prefix(null_len); - return util::Status::OK; + return util::Status(); } util::Status JsonStreamParser::ParseEmptyNull() { ow_->RenderNull(key_); key_ = StringPiece(); - return util::Status::OK; + return util::Status(); } bool JsonStreamParser::IsEmptyNullAllowed(TokenType type) { @@ -793,7 +793,7 @@ util::Status JsonStreamParser::ParseKey() { } // Since we aren't using the key storage, clear it out. key_storage_.clear(); - return util::Status::OK; + return util::Status(); } JsonStreamParser::TokenType JsonStreamParser::GetNextTokenType() { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/proto_writer.h b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/proto_writer.h index 21dff88d72..0db8485cb7 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/proto_writer.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/proto_writer.h @@ -81,32 +81,32 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter { virtual ~ProtoWriter(); // ObjectWriter methods. - virtual ProtoWriter* StartObject(StringPiece name); - virtual ProtoWriter* EndObject(); - virtual ProtoWriter* StartList(StringPiece name); - virtual ProtoWriter* EndList(); - virtual ProtoWriter* RenderBool(StringPiece name, bool value) { + ProtoWriter* StartObject(StringPiece name); + ProtoWriter* EndObject(); + ProtoWriter* StartList(StringPiece name); + ProtoWriter* EndList(); + ProtoWriter* RenderBool(StringPiece name, bool value) { return RenderDataPiece(name, DataPiece(value)); } - virtual ProtoWriter* RenderInt32(StringPiece name, int32 value) { + ProtoWriter* RenderInt32(StringPiece name, int32 value) { return RenderDataPiece(name, DataPiece(value)); } - virtual ProtoWriter* RenderUint32(StringPiece name, uint32 value) { + ProtoWriter* RenderUint32(StringPiece name, uint32 value) { return RenderDataPiece(name, DataPiece(value)); } - virtual ProtoWriter* RenderInt64(StringPiece name, int64 value) { + ProtoWriter* RenderInt64(StringPiece name, int64 value) { return RenderDataPiece(name, DataPiece(value)); } - virtual ProtoWriter* RenderUint64(StringPiece name, uint64 value) { + ProtoWriter* RenderUint64(StringPiece name, uint64 value) { return RenderDataPiece(name, DataPiece(value)); } - virtual ProtoWriter* RenderDouble(StringPiece name, double value) { + ProtoWriter* RenderDouble(StringPiece name, double value) { return RenderDataPiece(name, DataPiece(value)); } - virtual ProtoWriter* RenderFloat(StringPiece name, float value) { + ProtoWriter* RenderFloat(StringPiece name, float value) { return RenderDataPiece(name, DataPiece(value)); } - virtual ProtoWriter* RenderString(StringPiece name, StringPiece value) { + ProtoWriter* RenderString(StringPiece name, StringPiece value) { return RenderDataPiece(name, DataPiece(value, use_strict_base64_decoding())); } @@ -114,7 +114,7 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter { return RenderDataPiece( name, DataPiece(value, false, use_strict_base64_decoding())); } - virtual ProtoWriter* RenderNull(StringPiece name) { + ProtoWriter* RenderNull(StringPiece name) { return RenderDataPiece(name, DataPiece::NullData()); } @@ -242,7 +242,7 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter { ProtoWriter(const TypeInfo* typeinfo, const google::protobuf::Type& type, strings::ByteSink* output, ErrorListener* listener); - virtual ProtoElement* element() { return element_.get(); } + ProtoElement* element() { return element_.get(); } // Helper methods for calling ErrorListener. See error_listener.h. void InvalidName(StringPiece unknown_name, StringPiece message); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectsource.cc b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectsource.cc index 61491af0c2..025fbd4091 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectsource.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectsource.cc @@ -240,7 +240,7 @@ Status ProtoStreamObjectSource::WriteMessage(const google::protobuf::Type& type, if (include_start_and_end) { ow->EndObject(); } - return Status::OK; + return util::Status(); } StatusOr ProtoStreamObjectSource::RenderList( @@ -322,7 +322,7 @@ Status ProtoStreamObjectSource::RenderPacked( RETURN_IF_ERROR(RenderField(field, StringPiece(), ow)); } stream_->PopLimit(old_limit); - return Status::OK; + return util::Status(); } Status ProtoStreamObjectSource::RenderTimestamp( @@ -346,7 +346,7 @@ Status ProtoStreamObjectSource::RenderTimestamp( ow->RenderString(field_name, ::google::protobuf::internal::FormatTime(seconds, nanos)); - return Status::OK; + return util::Status(); } Status ProtoStreamObjectSource::RenderDuration( @@ -387,7 +387,7 @@ Status ProtoStreamObjectSource::RenderDuration( FormatNanos(nanos, os->add_trailing_zeros_for_timestamp_and_duration_) .c_str()); ow->RenderString(field_name, formatted_duration); - return Status::OK; + return util::Status(); } Status ProtoStreamObjectSource::RenderDouble(const ProtoStreamObjectSource* os, @@ -401,7 +401,7 @@ Status ProtoStreamObjectSource::RenderDouble(const ProtoStreamObjectSource* os, os->stream_->ReadTag(); } ow->RenderDouble(field_name, bit_cast(buffer64)); - return Status::OK; + return util::Status(); } Status ProtoStreamObjectSource::RenderFloat(const ProtoStreamObjectSource* os, @@ -415,7 +415,7 @@ Status ProtoStreamObjectSource::RenderFloat(const ProtoStreamObjectSource* os, os->stream_->ReadTag(); } ow->RenderFloat(field_name, bit_cast(buffer32)); - return Status::OK; + return util::Status(); } Status ProtoStreamObjectSource::RenderInt64(const ProtoStreamObjectSource* os, @@ -429,7 +429,7 @@ Status ProtoStreamObjectSource::RenderInt64(const ProtoStreamObjectSource* os, os->stream_->ReadTag(); } ow->RenderInt64(field_name, bit_cast(buffer64)); - return Status::OK; + return util::Status(); } Status ProtoStreamObjectSource::RenderUInt64(const ProtoStreamObjectSource* os, @@ -443,7 +443,7 @@ Status ProtoStreamObjectSource::RenderUInt64(const ProtoStreamObjectSource* os, os->stream_->ReadTag(); } ow->RenderUint64(field_name, bit_cast(buffer64)); - return Status::OK; + return util::Status(); } Status ProtoStreamObjectSource::RenderInt32(const ProtoStreamObjectSource* os, @@ -457,7 +457,7 @@ Status ProtoStreamObjectSource::RenderInt32(const ProtoStreamObjectSource* os, os->stream_->ReadTag(); } ow->RenderInt32(field_name, bit_cast(buffer32)); - return Status::OK; + return util::Status(); } Status ProtoStreamObjectSource::RenderUInt32(const ProtoStreamObjectSource* os, @@ -471,7 +471,7 @@ Status ProtoStreamObjectSource::RenderUInt32(const ProtoStreamObjectSource* os, os->stream_->ReadTag(); } ow->RenderUint32(field_name, bit_cast(buffer32)); - return Status::OK; + return util::Status(); } Status ProtoStreamObjectSource::RenderBool(const ProtoStreamObjectSource* os, @@ -486,7 +486,7 @@ Status ProtoStreamObjectSource::RenderBool(const ProtoStreamObjectSource* os, os->stream_->ReadTag(); } ow->RenderBool(field_name, buffer64 != 0); - return Status::OK; + return util::Status(); } Status ProtoStreamObjectSource::RenderString(const ProtoStreamObjectSource* os, @@ -502,7 +502,7 @@ Status ProtoStreamObjectSource::RenderString(const ProtoStreamObjectSource* os, os->stream_->ReadTag(); } ow->RenderString(field_name, str); - return Status::OK; + return util::Status(); } Status ProtoStreamObjectSource::RenderBytes(const ProtoStreamObjectSource* os, @@ -518,7 +518,7 @@ Status ProtoStreamObjectSource::RenderBytes(const ProtoStreamObjectSource* os, os->stream_->ReadTag(); } ow->RenderBytes(field_name, str); - return Status::OK; + return util::Status(); } Status ProtoStreamObjectSource::RenderStruct(const ProtoStreamObjectSource* os, @@ -537,7 +537,7 @@ Status ProtoStreamObjectSource::RenderStruct(const ProtoStreamObjectSource* os, } } ow->EndObject(); - return Status::OK; + return util::Status(); } Status ProtoStreamObjectSource::RenderStructValue( @@ -553,7 +553,7 @@ Status ProtoStreamObjectSource::RenderStructValue( } RETURN_IF_ERROR(os->RenderField(field, field_name, ow)); } - return Status::OK; + return util::Status(); } // TODO(skarvaje): Avoid code duplication of for loops and SkipField logic. @@ -566,7 +566,7 @@ Status ProtoStreamObjectSource::RenderStructListValue( if (tag == 0) { ow->StartList(field_name); ow->EndList(); - return Status::OK; + return util::Status(); } while (tag != 0) { @@ -578,7 +578,7 @@ Status ProtoStreamObjectSource::RenderStructListValue( } ASSIGN_OR_RETURN(tag, os->RenderList(field, field_name, tag, ow)); } - return Status::OK; + return util::Status(); } Status ProtoStreamObjectSource::RenderAny(const ProtoStreamObjectSource* os, @@ -620,7 +620,7 @@ Status ProtoStreamObjectSource::RenderAny(const ProtoStreamObjectSource* os, ow->RenderString("@type", type_url); } ow->EndObject(); - return util::Status::OK; + return util::Status(); } // If there is a value but no type, we cannot render it, so report an error. @@ -685,7 +685,7 @@ Status ProtoStreamObjectSource::RenderFieldMask( combined.append(ConvertFieldMaskPath(str, &ToCamelCase)); } ow->RenderString(field_name, combined); - return Status::OK; + return util::Status(); } @@ -781,7 +781,7 @@ Status ProtoStreamObjectSource::RenderField( // Render all other non-message types. return RenderNonMessageField(field, field_name, ow); } - return Status::OK; + return util::Status(); } Status ProtoStreamObjectSource::RenderNonMessageField( @@ -910,7 +910,7 @@ Status ProtoStreamObjectSource::RenderNonMessageField( default: break; } - return Status::OK; + return util::Status(); } // TODO(skarvaje): Fix this to avoid code duplication. @@ -1079,7 +1079,7 @@ Status ProtoStreamObjectSource::IncrementRecursionDepth( StrCat("Message too deep. Max recursion depth reached for type '", type_name, "', field '", field_name, "'")); } - return Status::OK; + return util::Status(); } namespace { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectsource.h b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectsource.h index 5f443d9d48..58d77c2c71 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectsource.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectsource.h @@ -112,9 +112,7 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource { // Sets whether to always output enums as ints, by default this is off, and // enums are rendered as strings. - void set_use_ints_for_enums(bool value) { - use_ints_for_enums_ = value; - } + void set_use_ints_for_enums(bool value) { use_ints_for_enums_ = value; } // Sets whether to use original proto field names void set_preserve_proto_field_names(bool value) { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectsource_test.cc b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectsource_test.cc index e215c4abcd..06c9bb6d4c 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectsource_test.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectsource_test.cc @@ -111,7 +111,7 @@ class ProtostreamObjectSourceTest void DoTest(const Message& msg, const Descriptor* descriptor) { Status status = ExecuteTest(msg, descriptor); - EXPECT_EQ(Status::OK, status); + EXPECT_EQ(util::Status(), status); } Status ExecuteTest(const Message& msg, const Descriptor* descriptor) { @@ -509,9 +509,7 @@ TEST_P(ProtostreamObjectSourceTest, UseIntsForEnumsTest) { UseIntsForEnums(); - ow_.StartObject("") - ->RenderInt32("type", 3) - ->EndObject(); + ow_.StartObject("")->RenderInt32("type", 3)->EndObject(); DoTest(book, Book::descriptor()); } diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectwriter.cc b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectwriter.cc index 6c9bc30e75..d4e15bca3f 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectwriter.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectwriter.cc @@ -173,7 +173,7 @@ Status GetNanosFromStringPiece(StringPiece s_nanos, *nanos = i_nanos * conversion; } - return Status::OK; + return Status(); } } // namespace @@ -409,7 +409,7 @@ void ProtoStreamObjectWriter::AnyWriter::Event::DeepCopy() { // string value stays valid, we make a copy of the string value and update // DataPiece to reference our own copy. if (value_.type() == DataPiece::TYPE_STRING) { - value_.str().AppendToString(&value_storage_); + StrAppend(&value_storage_, value_.str()); value_ = DataPiece(value_storage_, value_.use_strict_base64_decoding()); } else if (value_.type() == DataPiece::TYPE_BYTES) { value_storage_ = value_.ToBytes().ValueOrDie(); @@ -862,7 +862,7 @@ Status ProtoStreamObjectWriter::RenderStructValue(ProtoStreamObjectWriter* ow, ow->ProtoWriter::RenderDataPiece( "string_value", DataPiece(SimpleItoa(int_value.ValueOrDie()), true)); - return Status::OK; + return Status(); } } struct_field_name = "number_value"; @@ -877,13 +877,22 @@ Status ProtoStreamObjectWriter::RenderStructValue(ProtoStreamObjectWriter* ow, ow->ProtoWriter::RenderDataPiece( "string_value", DataPiece(SimpleItoa(int_value.ValueOrDie()), true)); - return Status::OK; + return Status(); } } struct_field_name = "number_value"; break; } case DataPiece::TYPE_DOUBLE: { + if (ow->options_.struct_integers_as_strings) { + StatusOr double_value = data.ToDouble(); + if (double_value.ok()) { + ow->ProtoWriter::RenderDataPiece( + "string_value", + DataPiece(SimpleDtoa(double_value.ValueOrDie()), true)); + return Status(); + } + } struct_field_name = "number_value"; break; } @@ -906,12 +915,12 @@ Status ProtoStreamObjectWriter::RenderStructValue(ProtoStreamObjectWriter* ow, } } ow->ProtoWriter::RenderDataPiece(struct_field_name, data); - return Status::OK; + return Status(); } Status ProtoStreamObjectWriter::RenderTimestamp(ProtoStreamObjectWriter* ow, const DataPiece& data) { - if (data.type() == DataPiece::TYPE_NULL) return Status::OK; + if (data.type() == DataPiece::TYPE_NULL) return Status(); if (data.type() != DataPiece::TYPE_STRING) { return Status(INVALID_ARGUMENT, StrCat("Invalid data type for timestamp, value is ", @@ -930,19 +939,19 @@ Status ProtoStreamObjectWriter::RenderTimestamp(ProtoStreamObjectWriter* ow, ow->ProtoWriter::RenderDataPiece("seconds", DataPiece(seconds)); ow->ProtoWriter::RenderDataPiece("nanos", DataPiece(nanos)); - return Status::OK; + return Status(); } static inline util::Status RenderOneFieldPath(ProtoStreamObjectWriter* ow, StringPiece path) { ow->ProtoWriter::RenderDataPiece( "paths", DataPiece(ConvertFieldMaskPath(path, &ToSnakeCase), true)); - return Status::OK; + return Status(); } Status ProtoStreamObjectWriter::RenderFieldMask(ProtoStreamObjectWriter* ow, const DataPiece& data) { - if (data.type() == DataPiece::TYPE_NULL) return Status::OK; + if (data.type() == DataPiece::TYPE_NULL) return Status(); if (data.type() != DataPiece::TYPE_STRING) { return Status(INVALID_ARGUMENT, StrCat("Invalid data type for field mask, value is ", @@ -959,7 +968,7 @@ Status ProtoStreamObjectWriter::RenderFieldMask(ProtoStreamObjectWriter* ow, Status ProtoStreamObjectWriter::RenderDuration(ProtoStreamObjectWriter* ow, const DataPiece& data) { - if (data.type() == DataPiece::TYPE_NULL) return Status::OK; + if (data.type() == DataPiece::TYPE_NULL) return Status(); if (data.type() != DataPiece::TYPE_STRING) { return Status(INVALID_ARGUMENT, StrCat("Invalid data type for duration, value is ", @@ -1004,14 +1013,14 @@ Status ProtoStreamObjectWriter::RenderDuration(ProtoStreamObjectWriter* ow, ow->ProtoWriter::RenderDataPiece("seconds", DataPiece(seconds)); ow->ProtoWriter::RenderDataPiece("nanos", DataPiece(nanos)); - return Status::OK; + return Status(); } Status ProtoStreamObjectWriter::RenderWrapperType(ProtoStreamObjectWriter* ow, const DataPiece& data) { - if (data.type() == DataPiece::TYPE_NULL) return Status::OK; + if (data.type() == DataPiece::TYPE_NULL) return Status(); ow->ProtoWriter::RenderDataPiece("value", data); - return Status::OK; + return Status(); } ProtoStreamObjectWriter* ProtoStreamObjectWriter::RenderDataPiece( diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectwriter.h b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectwriter.h index 732971e1b7..ab534912e6 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectwriter.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectwriter.h @@ -76,11 +76,14 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter { public: // Options that control ProtoStreamObjectWriter class's behavior. struct Options { - // Treats integer inputs in google.protobuf.Struct as strings. Normally, - // integer values are returned in double field "number_value" of + // Treats numeric inputs in google.protobuf.Struct as strings. Normally, + // numeric values are returned in double field "number_value" of // google.protobuf.Struct. However, this can cause precision loss for - // int64/uint64 inputs. This option is provided for cases that want to - // preserve integer precision. + // int64/uint64/double inputs. This option is provided for cases that want + // to preserve number precision. + // + // TODO(skarvaje): Rename to struct_numbers_as_strings as it covers double + // as well. bool struct_integers_as_strings; // Not treat unknown fields as an error. If there is an unknown fields, diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectwriter_test.cc b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectwriter_test.cc index 97ef8fff8b..87d35b08bc 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectwriter_test.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/protostream_objectwriter_test.cc @@ -279,17 +279,13 @@ TEST_P(ProtoStreamObjectWriterTest, ConflictingJsonName) { ResetTypeInfo(TestJsonName1::descriptor()); TestJsonName1 message1; message1.set_one_value(12345); - ow_->StartObject("") - ->RenderInt32("value", 12345) - ->EndObject(); + ow_->StartObject("")->RenderInt32("value", 12345)->EndObject(); CheckOutput(message1); ResetTypeInfo(TestJsonName2::descriptor()); TestJsonName2 message2; message2.set_another_value(12345); - ow_->StartObject("") - ->RenderInt32("value", 12345) - ->EndObject(); + ow_->StartObject("")->RenderInt32("value", 12345)->EndObject(); CheckOutput(message2); } @@ -1615,7 +1611,7 @@ TEST_P(ProtoStreamObjectWriterStructTest, RepeatedStructMapObjectKeyTest) { TEST_P(ProtoStreamObjectWriterStructTest, OptionStructIntAsStringsTest) { StructType struct_type; google::protobuf::Struct* s = struct_type.mutable_object(); - s->mutable_fields()->operator[]("k1").set_number_value(123); + s->mutable_fields()->operator[]("k1").set_string_value("123"); s->mutable_fields()->operator[]("k2").set_bool_value(true); s->mutable_fields()->operator[]("k3").set_string_value("-222222222"); s->mutable_fields()->operator[]("k4").set_string_value("33333333"); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/type_info.cc b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/type_info.cc index a5d903f146..85d0d5c945 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/type_info.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/type_info.cc @@ -107,10 +107,12 @@ class TypeInfoForTypeResolver : public TypeInfo { virtual const google::protobuf::Field* FindField( const google::protobuf::Type* type, StringPiece camel_case_name) const { - std::map::const_iterator it = indexed_types_.find(type); - const CamelCaseNameTable& camel_case_name_table = (it == indexed_types_.end()) - ? PopulateNameLookupTable(type, &indexed_types_[type]) : it->second; + std::map::const_iterator + it = indexed_types_.find(type); + const CamelCaseNameTable& camel_case_name_table = + (it == indexed_types_.end()) + ? PopulateNameLookupTable(type, &indexed_types_[type]) + : it->second; StringPiece name = FindWithDefault(camel_case_name_table, camel_case_name, StringPiece()); if (name.empty()) { @@ -142,8 +144,8 @@ class TypeInfoForTypeResolver : public TypeInfo { const google::protobuf::Field& field = type->fields(i); StringPiece name = field.name(); StringPiece camel_case_name = field.json_name(); - const StringPiece* existing = InsertOrReturnExisting( - camel_case_name_table, camel_case_name, name); + const StringPiece* existing = + InsertOrReturnExisting(camel_case_name_table, camel_case_name, name); if (existing && *existing != name) { GOOGLE_LOG(WARNING) << "Field '" << name << "' and '" << *existing << "' map to the same camel case name '" << camel_case_name @@ -162,8 +164,8 @@ class TypeInfoForTypeResolver : public TypeInfo { mutable std::map cached_types_; mutable std::map cached_enums_; - mutable std::map indexed_types_; + mutable std::map + indexed_types_; }; } // namespace diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/utility.cc b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/utility.cc index 6daf24eb56..8cf42e491e 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/utility.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/util/internal/utility.cc @@ -48,16 +48,6 @@ namespace protobuf { namespace util { namespace converter { -namespace { -const StringPiece SkipWhiteSpace(StringPiece str) { - StringPiece::size_type i; - for (i = 0; i < str.size() && isspace(str[i]); ++i) { - } - GOOGLE_DCHECK(i == str.size() || !isspace(str[i])); - return str.substr(i); -} -} // namespace - bool GetBoolOptionOrDefault( const google::protobuf::RepeatedPtrField& options, const string& option_name, bool default_value) { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/util/json_util.cc b/third_party/protobuf/3.2.0/src/google/protobuf/util/json_util.cc index 8595a8813d..c85f18994c 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/util/json_util.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/util/json_util.cc @@ -84,7 +84,7 @@ util::Status BinaryToJsonStream(TypeResolver* resolver, converter::ProtoStreamObjectSource proto_source(&in_stream, resolver, type); proto_source.set_use_ints_for_enums(options.always_print_enums_as_ints); proto_source.set_preserve_proto_field_names( - options.preserve_proto_field_names); + options.preserve_proto_field_names); io::CodedOutputStream out_stream(json_output); converter::JsonObjectWriter json_writer(options.add_whitespace ? " " : "", &out_stream); @@ -92,7 +92,7 @@ util::Status BinaryToJsonStream(TypeResolver* resolver, converter::DefaultValueObjectWriter default_value_writer( resolver, type, &json_writer); default_value_writer.set_preserve_proto_field_names( - options.preserve_proto_field_names); + options.preserve_proto_field_names); return proto_source.WriteTo(&default_value_writer); } else { return proto_source.WriteTo(&json_writer); @@ -113,7 +113,7 @@ util::Status BinaryToJsonString(TypeResolver* resolver, namespace { class StatusErrorListener : public converter::ErrorListener { public: - StatusErrorListener() : status_(util::Status::OK) {} + StatusErrorListener() {} virtual ~StatusErrorListener() {} util::Status GetStatus() { return status_; } diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/util/json_util.h b/third_party/protobuf/3.2.0/src/google/protobuf/util/json_util.h index dd9a736f24..f4f4380a73 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/util/json_util.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/util/json_util.h @@ -67,11 +67,11 @@ struct JsonPrintOptions { // Whether to preserve proto field names bool preserve_proto_field_names; - JsonPrintOptions() : add_whitespace(false), - always_print_primitive_fields(false), - always_print_enums_as_ints(false), - preserve_proto_field_names(false) { - } + JsonPrintOptions() + : add_whitespace(false), + always_print_primitive_fields(false), + always_print_enums_as_ints(false), + preserve_proto_field_names(false) {} }; // DEPRECATED. Use JsonPrintOptions instead. diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/util/json_util_test.cc b/third_party/protobuf/3.2.0/src/google/protobuf/util/json_util_test.cc index 7c03d674b6..25c7e96c0d 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/util/json_util_test.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/util/json_util_test.cc @@ -52,14 +52,10 @@ using proto3::BAR; using proto3::TestMessage; using proto3::TestMap; using proto3::TestOneof; -using testing::MapIn; +using google::protobuf::testing::MapIn; static const char kTypeUrlPrefix[] = "type.googleapis.com"; -static string GetTypeUrl(const Descriptor* message) { - return string(kTypeUrlPrefix) + "/" + message->full_name(); -} - // As functions defined in json_util.h are just thin wrappers around the // JSON conversion code in //net/proto2/util/converter, in this test we // only cover some very basic cases to make sure the wrappers have forwarded @@ -207,8 +203,7 @@ TEST_F(JsonUtilTest, TestAlwaysPrintEnumsAsInts) { JsonPrintOptions print_options; print_options.always_print_enums_as_ints = true; - string expected_json = - "{\"enumValue\":1,\"repeatedEnumValue\":[0,1]}"; + string expected_json = "{\"enumValue\":1,\"repeatedEnumValue\":[0,1]}"; EXPECT_EQ(expected_json, ToJson(orig, print_options)); TestMessage parsed; @@ -264,7 +259,8 @@ TEST_F(JsonUtilTest, ParsePrimitiveMapIn) { JsonPrintOptions print_options; print_options.always_print_primitive_fields = true; JsonParseOptions parse_options; - EXPECT_EQ("{\"other\":\"\",\"things\":[],\"mapInput\":{}}", ToJson(message, print_options)); + EXPECT_EQ("{\"other\":\"\",\"things\":[],\"mapInput\":{}}", + ToJson(message, print_options)); MapIn other; ASSERT_TRUE(FromJson(ToJson(message, print_options), &other, parse_options)); EXPECT_EQ(message.DebugString(), other.DebugString()); @@ -275,14 +271,10 @@ TEST_F(JsonUtilTest, PrintPrimitiveOneof) { JsonPrintOptions options; options.always_print_primitive_fields = true; message.mutable_oneof_message_value(); - EXPECT_EQ( - "{\"oneofMessageValue\":{\"value\":0}}", - ToJson(message, options)); + EXPECT_EQ("{\"oneofMessageValue\":{\"value\":0}}", ToJson(message, options)); message.set_oneof_int32_value(1); - EXPECT_EQ( - "{\"oneofInt32Value\":1}", - ToJson(message, options)); + EXPECT_EQ("{\"oneofInt32Value\":1}", ToJson(message, options)); } TEST_F(JsonUtilTest, TestParseIgnoreUnknownFields) { diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/util/message_differencer.cc b/third_party/protobuf/3.2.0/src/google/protobuf/util/message_differencer.cc index 203d838870..830850be24 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/util/message_differencer.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/util/message_differencer.cc @@ -467,6 +467,10 @@ bool MessageDifferencer::Compare( google::protobuf::scoped_ptr data1; google::protobuf::scoped_ptr data2; if (UnpackAny(message1, &data1) && UnpackAny(message2, &data2)) { + // Avoid DFATAL for different descriptors in google.protobuf.Any payloads. + if (data1->GetDescriptor() != data2->GetDescriptor()) { + return false; + } return Compare(*data1, *data2, parent_fields); } } @@ -849,7 +853,8 @@ bool MessageDifferencer::CompareRepeatedField( parent_fields->pop_back(); fieldDifferent = true; } else if (reporter_ != NULL && - specific_field.index != specific_field.new_index) { + specific_field.index != specific_field.new_index && + !specific_field.field->is_map()) { parent_fields->push_back(specific_field); reporter_->ReportMoved(message1, message2, *parent_fields); parent_fields->pop_back(); @@ -1503,6 +1508,10 @@ void MessageDifferencer::StreamReporter::PrintPath( } else { printer_->PrintRaw(specific_field.field->name()); } + if (specific_field.field->is_map()) { + // Don't print index in a map field; they are semantically unordered. + continue; + } } else { printer_->PrintRaw(SimpleItoa(specific_field.unknown_field_number)); } diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/util/message_differencer_unittest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/util/message_differencer_unittest.cc index 30b27dbaad..850b397705 100755 --- a/third_party/protobuf/3.2.0/src/google/protobuf/util/message_differencer_unittest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/util/message_differencer_unittest.cc @@ -38,6 +38,7 @@ #include #include +#include #include #include @@ -54,7 +55,6 @@ #include #include -#include #include #include @@ -2042,6 +2042,9 @@ class ComparisonTest : public testing::Test { unittest::TestEmptyMessage empty1_; unittest::TestEmptyMessage empty2_; + unittest::TestMap map_proto1_; + unittest::TestMap map_proto2_; + UnknownFieldSet* unknown1_; UnknownFieldSet* unknown2_; @@ -2802,6 +2805,24 @@ TEST_F(ComparisonTest, EquivalentIgnoresUnknown) { EXPECT_TRUE(util::MessageDifferencer::Equivalent(message1, message2)); } +TEST_F(ComparisonTest, MapTest) { + repeated_field_as_set(); + + Map& map1 = *map_proto1_.mutable_map_string_string(); + map1["1"] = "1"; + map1["2"] = "2"; + map1["3"] = "3"; + Map& map2 = *map_proto2_.mutable_map_string_string(); + map2["3"] = "0"; + map2["2"] = "2"; + map2["1"] = "1"; + + EXPECT_EQ( + "added: map_string_string: { key: \"3\" value: \"0\" }\n" + "deleted: map_string_string: { key: \"3\" value: \"3\" }\n", + Run(map_proto1_, map_proto2_)); +} + class MatchingTest : public testing::Test { public: typedef util::MessageDifferencer MessageDifferencer; @@ -3146,6 +3167,24 @@ TEST(Anytest, TreatAsSet) { EXPECT_TRUE(message_differencer.Compare(m1, m2)); } +TEST(Anytest, TreatAsSet_DifferentType) { + protobuf_unittest::TestField value1; + value1.set_a(20); + value1.set_b(30); + protobuf_unittest::TestDiffMessage value2; + value2.add_rv(40); + + protobuf_unittest::TestAny m1, m2; + m1.add_repeated_any_value()->PackFrom(value1); + m1.add_repeated_any_value()->PackFrom(value2); + m2.add_repeated_any_value()->PackFrom(value2); + m2.add_repeated_any_value()->PackFrom(value1); + + util::MessageDifferencer message_differencer; + message_differencer.TreatAsSet(GetFieldDescriptor(m1, "repeated_any_value")); + EXPECT_TRUE(message_differencer.Compare(m1, m2)); +} + } // namespace } // namespace protobuf diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/util/time_util.cc b/third_party/protobuf/3.2.0/src/google/protobuf/util/time_util.cc index 82f1f4fb48..46a6f5a8a5 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/util/time_util.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/util/time_util.cc @@ -374,19 +374,6 @@ namespace { using google::protobuf::util::kNanosPerSecond; using google::protobuf::util::CreateNormalized; -// Convert a Timestamp to uint128. -void ToUint128(const Timestamp& value, uint128* result, bool* negative) { - if (value.seconds() < 0) { - *negative = true; - *result = static_cast(-value.seconds()); - *result = *result * kNanosPerSecond - static_cast(value.nanos()); - } else { - *negative = false; - *result = static_cast(value.seconds()); - *result = *result * kNanosPerSecond + static_cast(value.nanos()); - } -} - // Convert a Duration to uint128. void ToUint128(const Duration& value, uint128* result, bool* negative) { if (value.seconds() < 0 || value.nanos() < 0) { @@ -400,21 +387,6 @@ void ToUint128(const Duration& value, uint128* result, bool* negative) { } } -void ToTimestamp(const uint128& value, bool negative, Timestamp* timestamp) { - int64 seconds = static_cast(Uint128Low64(value / kNanosPerSecond)); - int32 nanos = static_cast(Uint128Low64(value % kNanosPerSecond)); - if (negative) { - seconds = -seconds; - nanos = -nanos; - if (nanos < 0) { - nanos += kNanosPerSecond; - seconds -= 1; - } - } - timestamp->set_seconds(seconds); - timestamp->set_nanos(nanos); -} - void ToDuration(const uint128& value, bool negative, Duration* duration) { int64 seconds = static_cast(Uint128Low64(value / kNanosPerSecond)); int32 nanos = static_cast(Uint128Low64(value % kNanosPerSecond)); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/wire_format.cc b/third_party/protobuf/3.2.0/src/google/protobuf/wire_format.cc index bd5b248916..01704c9470 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/wire_format.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/wire_format.cc @@ -54,9 +54,17 @@ namespace google { +const size_t kMapEntryTagByteSize = 2; + namespace protobuf { namespace internal { +// Forward declare static functions +static size_t MapKeyDataOnlyByteSize(const FieldDescriptor* field, + const MapKey& value); +static size_t MapValueRefDataOnlyByteSize(const FieldDescriptor* field, + const MapValueRef& value); + // =================================================================== bool UnknownFieldSetFieldSkipper::SkipField( @@ -76,6 +84,8 @@ void UnknownFieldSetFieldSkipper::SkipUnknownEnum( bool WireFormat::SkipField(io::CodedInputStream* input, uint32 tag, UnknownFieldSet* unknown_fields) { int number = WireFormatLite::GetTagFieldNumber(tag); + // Field number 0 is illegal. + if (number == 0) return false; switch (WireFormatLite::GetTagWireType(tag)) { case WireFormatLite::WIRETYPE_VARINT: { @@ -795,7 +805,16 @@ void WireFormat::SerializeWithCachedSizes( int expected_endpoint = output->ByteCount() + size; std::vector fields; - message_reflection->ListFields(message, &fields); + + // Fields of map entry should always be serialized. + if (descriptor->options().map_entry()) { + for (int i = 0; i < descriptor->field_count(); i++) { + fields.push_back(descriptor->field(i)); + } + } else { + message_reflection->ListFields(message, &fields); + } + for (int i = 0; i < fields.size(); i++) { SerializeFieldWithCachedSizes(fields[i], message, output); } @@ -814,6 +833,129 @@ void WireFormat::SerializeWithCachedSizes( "during serialization?"; } +static void SerializeMapKeyWithCachedSizes(const FieldDescriptor* field, + const MapKey& value, + io::CodedOutputStream* output) { + switch (field->type()) { + case FieldDescriptor::TYPE_DOUBLE: + case FieldDescriptor::TYPE_FLOAT: + case FieldDescriptor::TYPE_GROUP: + case FieldDescriptor::TYPE_MESSAGE: + case FieldDescriptor::TYPE_BYTES: + case FieldDescriptor::TYPE_ENUM: + GOOGLE_LOG(FATAL) << "Unsupported"; + break; +#define CASE_TYPE(FieldType, CamelFieldType, CamelCppType) \ + case FieldDescriptor::TYPE_##FieldType: \ + WireFormatLite::Write##CamelFieldType(1, value.Get##CamelCppType##Value(), \ + output); \ + break; + CASE_TYPE(INT64, Int64, Int64) + CASE_TYPE(UINT64, UInt64, UInt64) + CASE_TYPE(INT32, Int32, Int32) + CASE_TYPE(FIXED64, Fixed64, UInt64) + CASE_TYPE(FIXED32, Fixed32, UInt32) + CASE_TYPE(BOOL, Bool, Bool) + CASE_TYPE(UINT32, UInt32, UInt32) + CASE_TYPE(SFIXED32, SFixed32, Int32) + CASE_TYPE(SFIXED64, SFixed64, Int64) + CASE_TYPE(SINT32, SInt32, Int32) + CASE_TYPE(SINT64, SInt64, Int64) + CASE_TYPE(STRING, String, String) +#undef CASE_TYPE + } +} + +static void SerializeMapValueRefWithCachedSizes(const FieldDescriptor* field, + const MapValueRef& value, + io::CodedOutputStream* output) { + switch (field->type()) { +#define CASE_TYPE(FieldType, CamelFieldType, CamelCppType) \ + case FieldDescriptor::TYPE_##FieldType: \ + WireFormatLite::Write##CamelFieldType(2, value.Get##CamelCppType##Value(), \ + output); \ + break; + CASE_TYPE(INT64, Int64, Int64) + CASE_TYPE(UINT64, UInt64, UInt64) + CASE_TYPE(INT32, Int32, Int32) + CASE_TYPE(FIXED64, Fixed64, UInt64) + CASE_TYPE(FIXED32, Fixed32, UInt32) + CASE_TYPE(BOOL, Bool, Bool) + CASE_TYPE(UINT32, UInt32, UInt32) + CASE_TYPE(SFIXED32, SFixed32, Int32) + CASE_TYPE(SFIXED64, SFixed64, Int64) + CASE_TYPE(SINT32, SInt32, Int32) + CASE_TYPE(SINT64, SInt64, Int64) + CASE_TYPE(ENUM, Enum, Enum) + CASE_TYPE(DOUBLE, Double, Double) + CASE_TYPE(FLOAT, Float, Float) + CASE_TYPE(STRING, String, String) + CASE_TYPE(BYTES, Bytes, String) + CASE_TYPE(MESSAGE, Message, Message) + CASE_TYPE(GROUP, Group, Message) +#undef CASE_TYPE + } +} + +class MapKeySorter { + public: + static std::vector SortKey(const Message& message, + const Reflection* reflection, + const FieldDescriptor* field) { + std::vector sorted_key_list; + for (MapIterator it = + reflection->MapBegin(const_cast(&message), field); + it != reflection->MapEnd(const_cast(&message), field); + ++it) { + sorted_key_list.push_back(it.GetKey()); + } + MapKeyComparator comparator; + std::sort(sorted_key_list.begin(), sorted_key_list.end(), comparator); + return sorted_key_list; + } + + private: + class MapKeyComparator { + public: + bool operator()(const MapKey& a, const MapKey& b) const { + GOOGLE_DCHECK(a.type() == b.type()); + switch (a.type()) { +#define CASE_TYPE(CppType, CamelCppType) \ + case FieldDescriptor::CPPTYPE_##CppType: { \ + return a.Get##CamelCppType##Value() < b.Get##CamelCppType##Value(); \ + } + CASE_TYPE(STRING, String) + CASE_TYPE(INT64, Int64) + CASE_TYPE(INT32, Int32) + CASE_TYPE(UINT64, UInt64) + CASE_TYPE(UINT32, UInt32) + CASE_TYPE(BOOL, Bool) +#undef CASE_TYPE + + default: + GOOGLE_LOG(DFATAL) << "Invalid key for map field."; + return true; + } + } + }; +}; + +static void SerializeMapEntry(const FieldDescriptor* field, const MapKey& key, + const MapValueRef& value, + io::CodedOutputStream* output) { + const FieldDescriptor* key_field = field->message_type()->field(0); + const FieldDescriptor* value_field = field->message_type()->field(1); + + WireFormatLite::WriteTag(field->number(), + WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output); + size_t size = kMapEntryTagByteSize; + size += MapKeyDataOnlyByteSize(key_field, key); + size += MapValueRefDataOnlyByteSize(value_field, value); + output->WriteVarint32(size); + SerializeMapKeyWithCachedSizes(key_field, key, output); + SerializeMapValueRefWithCachedSizes(value_field, value, output); +} + void WireFormat::SerializeFieldWithCachedSizes( const FieldDescriptor* field, const Message& message, @@ -828,10 +970,55 @@ void WireFormat::SerializeFieldWithCachedSizes( return; } + // For map fields, we can use either repeated field reflection or map + // reflection. Our choice has some subtle effects. If we use repeated field + // reflection here, then the repeated field representation becomes + // authoritative for this field: any existing references that came from map + // reflection remain valid for reading, but mutations to them are lost and + // will be overwritten next time we call map reflection! + // + // So far this mainly affects Python, which keeps long-term references to map + // values around, and always uses map reflection. See: b/35918691 + // + // Here we choose to use map reflection API as long as the internal + // map is valid. In this way, the serialization doesn't change map field's + // internal state and existing references that came from map reflection remain + // valid for both reading and writing. + if (field->is_map()) { + MapFieldBase* map_field = + message_reflection->MapData(const_cast(&message), field); + if (map_field->IsMapValid()) { + if (output->IsSerializationDeterministic()) { + std::vector sorted_key_list = + MapKeySorter::SortKey(message, message_reflection, field); + for (std::vector::iterator it = sorted_key_list.begin(); + it != sorted_key_list.end(); ++it) { + MapValueRef map_value; + message_reflection->InsertOrLookupMapValue( + const_cast(&message), field, *it, &map_value); + SerializeMapEntry(field, *it, map_value, output); + } + } else { + for (MapIterator it = message_reflection->MapBegin( + const_cast(&message), field); + it != + message_reflection->MapEnd(const_cast(&message), field); + ++it) { + SerializeMapEntry(field, it.GetKey(), it.GetValueRef(), output); + } + } + + return; + } + } + int count = 0; if (field->is_repeated()) { count = message_reflection->FieldSize(message, field); + } else if (field->containing_type()->options().map_entry()) { + // Map entry fields always need to be serialized. + count = 1; } else if (message_reflection->HasField(message, field)) { count = 1; } @@ -982,7 +1169,16 @@ size_t WireFormat::ByteSize(const Message& message) { size_t our_size = 0; std::vector fields; - message_reflection->ListFields(message, &fields); + + // Fields of map entry should always be serialized. + if (descriptor->options().map_entry()) { + for (int i = 0; i < descriptor->field_count(); i++) { + fields.push_back(descriptor->field(i)); + } + } else { + message_reflection->ListFields(message, &fields); + } + for (int i = 0; i < fields.size(); i++) { our_size += FieldByteSize(fields[i], message); } @@ -1013,6 +1209,9 @@ size_t WireFormat::FieldByteSize( size_t count = 0; if (field->is_repeated()) { count = FromIntSize(message_reflection->FieldSize(message, field)); + } else if (field->containing_type()->options().map_entry()) { + // Map entry fields always need to be serialized. + count = 1; } else if (message_reflection->HasField(message, field)) { count = 1; } @@ -1033,20 +1232,124 @@ size_t WireFormat::FieldByteSize( return our_size; } +static size_t MapKeyDataOnlyByteSize(const FieldDescriptor* field, + const MapKey& value) { + GOOGLE_DCHECK_EQ(FieldDescriptor::TypeToCppType(field->type()), value.type()); + switch (field->type()) { + case FieldDescriptor::TYPE_DOUBLE: + case FieldDescriptor::TYPE_FLOAT: + case FieldDescriptor::TYPE_GROUP: + case FieldDescriptor::TYPE_MESSAGE: + case FieldDescriptor::TYPE_BYTES: + case FieldDescriptor::TYPE_ENUM: + GOOGLE_LOG(FATAL) << "Unsupported"; + return 0; +#define CASE_TYPE(FieldType, CamelFieldType, CamelCppType) \ + case FieldDescriptor::TYPE_##FieldType: \ + return WireFormatLite::CamelFieldType##Size( \ + value.Get##CamelCppType##Value()); + +#define FIXED_CASE_TYPE(FieldType, CamelFieldType) \ + case FieldDescriptor::TYPE_##FieldType: \ + return WireFormatLite::k##CamelFieldType##Size; + + CASE_TYPE(INT32, Int32, Int32); + CASE_TYPE(INT64, Int64, Int64); + CASE_TYPE(UINT32, UInt32, UInt32); + CASE_TYPE(UINT64, UInt64, UInt64); + CASE_TYPE(SINT32, SInt32, Int32); + CASE_TYPE(SINT64, SInt64, Int64); + CASE_TYPE(STRING, String, String); + FIXED_CASE_TYPE(FIXED32, Fixed32); + FIXED_CASE_TYPE(FIXED64, Fixed64); + FIXED_CASE_TYPE(SFIXED32, SFixed32); + FIXED_CASE_TYPE(SFIXED64, SFixed64); + FIXED_CASE_TYPE(BOOL, Bool); + +#undef CASE_TYPE +#undef FIXED_CASE_TYPE + } + GOOGLE_LOG(FATAL) << "Cannot get here"; + return 0; +} + +static size_t MapValueRefDataOnlyByteSize(const FieldDescriptor* field, + const MapValueRef& value) { + switch (field->type()) { + case FieldDescriptor::TYPE_GROUP: + GOOGLE_LOG(FATAL) << "Unsupported"; + return 0; +#define CASE_TYPE(FieldType, CamelFieldType, CamelCppType) \ + case FieldDescriptor::TYPE_##FieldType: \ + return WireFormatLite::CamelFieldType##Size( \ + value.Get##CamelCppType##Value()); + +#define FIXED_CASE_TYPE(FieldType, CamelFieldType) \ + case FieldDescriptor::TYPE_##FieldType: \ + return WireFormatLite::k##CamelFieldType##Size; + + CASE_TYPE(INT32, Int32, Int32); + CASE_TYPE(INT64, Int64, Int64); + CASE_TYPE(UINT32, UInt32, UInt32); + CASE_TYPE(UINT64, UInt64, UInt64); + CASE_TYPE(SINT32, SInt32, Int32); + CASE_TYPE(SINT64, SInt64, Int64); + CASE_TYPE(STRING, String, String); + CASE_TYPE(BYTES, Bytes, String); + CASE_TYPE(ENUM, Enum, Enum); + CASE_TYPE(MESSAGE, Message, Message); + FIXED_CASE_TYPE(FIXED32, Fixed32); + FIXED_CASE_TYPE(FIXED64, Fixed64); + FIXED_CASE_TYPE(SFIXED32, SFixed32); + FIXED_CASE_TYPE(SFIXED64, SFixed64); + FIXED_CASE_TYPE(DOUBLE, Double); + FIXED_CASE_TYPE(FLOAT, Float); + FIXED_CASE_TYPE(BOOL, Bool); + +#undef CASE_TYPE +#undef FIXED_CASE_TYPE + } + GOOGLE_LOG(FATAL) << "Cannot get here"; + return 0; +} + size_t WireFormat::FieldDataOnlyByteSize( const FieldDescriptor* field, const Message& message) { const Reflection* message_reflection = message.GetReflection(); + size_t data_size = 0; + + if (field->is_map()) { + MapFieldBase* map_field = + message_reflection->MapData(const_cast(&message), field); + if (map_field->IsMapValid()) { + MapIterator iter(const_cast(&message), field); + MapIterator end(const_cast(&message), field); + const FieldDescriptor* key_field = field->message_type()->field(0); + const FieldDescriptor* value_field = field->message_type()->field(1); + for (map_field->MapBegin(&iter), map_field->MapEnd(&end); iter != end; + ++iter) { + size_t size = kMapEntryTagByteSize; + size += MapKeyDataOnlyByteSize(key_field, iter.GetKey()); + size += MapValueRefDataOnlyByteSize(value_field, iter.GetValueRef()); + data_size += WireFormatLite::LengthDelimitedSize(size); + } + return data_size; + } + } + size_t count = 0; if (field->is_repeated()) { count = internal::FromIntSize(message_reflection->FieldSize(message, field)); + } else if (field->containing_type()->options().map_entry()) { + // Map entry fields always need to be serialized. + count = 1; } else if (message_reflection->HasField(message, field)) { count = 1; } - size_t data_size = 0; switch (field->type()) { #define HANDLE_TYPE(TYPE, TYPE_METHOD, CPPTYPE_METHOD) \ case FieldDescriptor::TYPE_##TYPE: \ diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/wire_format_lite.cc b/third_party/protobuf/3.2.0/src/google/protobuf/wire_format_lite.cc index e46ac40010..7987f7c4ad 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/wire_format_lite.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/wire_format_lite.cc @@ -47,8 +47,8 @@ #include #include - namespace google { + namespace protobuf { namespace internal { @@ -123,6 +123,8 @@ WireFormatLite::kWireTypeForFieldType[MAX_FIELD_TYPE + 1] = { bool WireFormatLite::SkipField( io::CodedInputStream* input, uint32 tag) { + // Field number 0 is illegal. + if (WireFormatLite::GetTagFieldNumber(tag) == 0) return false; switch (WireFormatLite::GetTagWireType(tag)) { case WireFormatLite::WIRETYPE_VARINT: { uint64 value; @@ -168,6 +170,8 @@ bool WireFormatLite::SkipField( bool WireFormatLite::SkipField( io::CodedInputStream* input, uint32 tag, io::CodedOutputStream* output) { + // Field number 0 is illegal. + if (WireFormatLite::GetTagFieldNumber(tag) == 0) return false; switch (WireFormatLite::GetTagWireType(tag)) { case WireFormatLite::WIRETYPE_VARINT: { uint64 value; @@ -340,6 +344,8 @@ bool WireFormatLite::ReadPackedEnumPreserveUnknowns( return true; } +#if !defined(PROTOBUF_LITTLE_ENDIAN) + namespace { void EncodeFixedSizeValue(float v, uint8* dest) { WireFormatLite::WriteFloatNoTagToArray(v, dest); @@ -370,6 +376,8 @@ void EncodeFixedSizeValue(bool v, uint8* dest) { } } // anonymous namespace +#endif // !defined(PROTOBUF_LITTLE_ENDIAN) + template static void WriteArray(const CType* a, int n, io::CodedOutputStream* output) { #if defined(PROTOBUF_LITTLE_ENDIAN) @@ -378,7 +386,7 @@ static void WriteArray(const CType* a, int n, io::CodedOutputStream* output) { const int kAtATime = 128; uint8 buf[sizeof(CType) * kAtATime]; for (int i = 0; i < n; i += kAtATime) { - int to_do = min(kAtATime, n - i); + int to_do = std::min(kAtATime, n - i); uint8* ptr = buf; for (int j = 0; j < to_do; j++) { EncodeFixedSizeValue(a[i+j], ptr); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/wire_format_lite.h b/third_party/protobuf/3.2.0/src/google/protobuf/wire_format_lite.h index 60355144a5..18b38eae7c 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/wire_format_lite.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/wire_format_lite.h @@ -250,10 +250,6 @@ class LIBPROTOBUF_EXPORT WireFormatLite { // of these methods are defined in wire_format_lite_inl.h; you must #include // that file to use these. -// Avoid ugly line wrapping -#define input io::CodedInputStream* input_arg -#define output io::CodedOutputStream* output_arg -#define field_number int field_number_arg #ifdef NDEBUG #define INL GOOGLE_ATTRIBUTE_ALWAYS_INLINE #else @@ -270,24 +266,22 @@ class LIBPROTOBUF_EXPORT WireFormatLite { // For primitive fields, we just use a templatized routine parameterized by // the represented type and the FieldType. These are specialized with the // appropriate definition for each declared type. - template INL - static bool ReadPrimitive(input, CType* value); + template + INL static bool ReadPrimitive(io::CodedInputStream* input, CType* value); // Reads repeated primitive values, with optimizations for repeats. // tag_size and tag should both be compile-time constants provided by the // protocol compiler. - template INL - static bool ReadRepeatedPrimitive(int tag_size, - uint32 tag, - input, - RepeatedField* value); + template + INL static bool ReadRepeatedPrimitive(int tag_size, uint32 tag, + io::CodedInputStream* input, + RepeatedField* value); // Identical to ReadRepeatedPrimitive, except will not inline the // implementation. template - static bool ReadRepeatedPrimitiveNoInline(int tag_size, - uint32 tag, - input, + static bool ReadRepeatedPrimitiveNoInline(int tag_size, uint32 tag, + io::CodedInputStream* input, RepeatedField* value); // Reads a primitive value directly from the provided buffer. It returns a @@ -301,39 +295,39 @@ class LIBPROTOBUF_EXPORT WireFormatLite { // Reads a primitive packed field. // // This is only implemented for packable types. - template INL - static bool ReadPackedPrimitive(input, RepeatedField* value); + template + INL static bool ReadPackedPrimitive(io::CodedInputStream* input, + RepeatedField* value); // Identical to ReadPackedPrimitive, except will not inline the // implementation. template - static bool ReadPackedPrimitiveNoInline(input, RepeatedField* value); + static bool ReadPackedPrimitiveNoInline(io::CodedInputStream* input, + RepeatedField* value); // Read a packed enum field. If the is_valid function is not NULL, values for // which is_valid(value) returns false are silently dropped. - static bool ReadPackedEnumNoInline(input, + static bool ReadPackedEnumNoInline(io::CodedInputStream* input, bool (*is_valid)(int), RepeatedField* values); // Read a packed enum field. If the is_valid function is not NULL, values for // which is_valid(value) returns false are appended to unknown_fields_stream. static bool ReadPackedEnumPreserveUnknowns( - input, - field_number, - bool (*is_valid)(int), - io::CodedOutputStream* unknown_fields_stream, - RepeatedField* values); + io::CodedInputStream* input, int field_number, bool (*is_valid)(int), + io::CodedOutputStream* unknown_fields_stream, RepeatedField* values); // Read a string. ReadString(..., string* value) requires an existing string. - static inline bool ReadString(input, string* value); + static inline bool ReadString(io::CodedInputStream* input, string* value); // ReadString(..., string** p) is internal-only, and should only be called // from generated code. It starts by setting *p to "new string" // if *p == &GetEmptyStringAlreadyInited(). It then invokes - // ReadString(input, *p). This is useful for reducing code size. - static inline bool ReadString(input, string** p); + // ReadString(io::CodedInputStream* input, *p). This is useful for reducing + // code size. + static inline bool ReadString(io::CodedInputStream* input, string** p); // Analogous to ReadString(). - static bool ReadBytes(input, string* value); - static bool ReadBytes(input, string** p); + static bool ReadBytes(io::CodedInputStream* input, string* value); + static bool ReadBytes(io::CodedInputStream* input, string** p); enum Operation { @@ -346,195 +340,322 @@ class LIBPROTOBUF_EXPORT WireFormatLite { Operation op, const char* field_name); - static inline bool ReadGroup (field_number, input, MessageLite* value); - static inline bool ReadMessage(input, MessageLite* value); + static inline bool ReadGroup(int field_number, io::CodedInputStream* input, + MessageLite* value); + static inline bool ReadMessage(io::CodedInputStream* input, + MessageLite* value); // Like above, but de-virtualize the call to MergePartialFromCodedStream(). // The pointer must point at an instance of MessageType, *not* a subclass (or // the subclass must not override MergePartialFromCodedStream()). - template - static inline bool ReadGroupNoVirtual(field_number, input, + template + static inline bool ReadGroupNoVirtual(int field_number, + io::CodedInputStream* input, MessageType* value); template - static inline bool ReadMessageNoVirtual(input, MessageType* value); + static inline bool ReadMessageNoVirtual(io::CodedInputStream* input, + MessageType* value); // The same, but do not modify input's recursion depth. This is useful // when reading a bunch of groups or messages in a loop, because then the // recursion depth can be incremented before the loop and decremented after. template - static inline bool ReadGroupNoVirtualNoRecursionDepth(field_number, input, - MessageType* value); + static inline bool ReadGroupNoVirtualNoRecursionDepth( + int field_number, io::CodedInputStream* input, MessageType* value); template - static inline bool ReadMessageNoVirtualNoRecursionDepth(input, - MessageType* value); + static inline bool ReadMessageNoVirtualNoRecursionDepth( + io::CodedInputStream* input, MessageType* value); // Write a tag. The Write*() functions typically include the tag, so // normally there's no need to call this unless using the Write*NoTag() // variants. - INL static void WriteTag(field_number, WireType type, output); + INL static void WriteTag(int field_number, WireType type, + io::CodedOutputStream* output); // Write fields, without tags. - INL static void WriteInt32NoTag (int32 value, output); - INL static void WriteInt64NoTag (int64 value, output); - INL static void WriteUInt32NoTag (uint32 value, output); - INL static void WriteUInt64NoTag (uint64 value, output); - INL static void WriteSInt32NoTag (int32 value, output); - INL static void WriteSInt64NoTag (int64 value, output); - INL static void WriteFixed32NoTag (uint32 value, output); - INL static void WriteFixed64NoTag (uint64 value, output); - INL static void WriteSFixed32NoTag(int32 value, output); - INL static void WriteSFixed64NoTag(int64 value, output); - INL static void WriteFloatNoTag (float value, output); - INL static void WriteDoubleNoTag (double value, output); - INL static void WriteBoolNoTag (bool value, output); - INL static void WriteEnumNoTag (int value, output); + INL static void WriteInt32NoTag(int32 value, io::CodedOutputStream* output); + INL static void WriteInt64NoTag(int64 value, io::CodedOutputStream* output); + INL static void WriteUInt32NoTag(uint32 value, io::CodedOutputStream* output); + INL static void WriteUInt64NoTag(uint64 value, io::CodedOutputStream* output); + INL static void WriteSInt32NoTag(int32 value, io::CodedOutputStream* output); + INL static void WriteSInt64NoTag(int64 value, io::CodedOutputStream* output); + INL static void WriteFixed32NoTag(uint32 value, + io::CodedOutputStream* output); + INL static void WriteFixed64NoTag(uint64 value, + io::CodedOutputStream* output); + INL static void WriteSFixed32NoTag(int32 value, + io::CodedOutputStream* output); + INL static void WriteSFixed64NoTag(int64 value, + io::CodedOutputStream* output); + INL static void WriteFloatNoTag(float value, io::CodedOutputStream* output); + INL static void WriteDoubleNoTag(double value, io::CodedOutputStream* output); + INL static void WriteBoolNoTag(bool value, io::CodedOutputStream* output); + INL static void WriteEnumNoTag(int value, io::CodedOutputStream* output); // Write array of primitive fields, without tags - static void WriteFloatArray (const float* a, int n, output); - static void WriteDoubleArray (const double* a, int n, output); - static void WriteFixed32Array (const uint32* a, int n, output); - static void WriteFixed64Array (const uint64* a, int n, output); - static void WriteSFixed32Array(const int32* a, int n, output); - static void WriteSFixed64Array(const int64* a, int n, output); - static void WriteBoolArray (const bool* a, int n, output); + static void WriteFloatArray(const float* a, int n, + io::CodedOutputStream* output); + static void WriteDoubleArray(const double* a, int n, + io::CodedOutputStream* output); + static void WriteFixed32Array(const uint32* a, int n, + io::CodedOutputStream* output); + static void WriteFixed64Array(const uint64* a, int n, + io::CodedOutputStream* output); + static void WriteSFixed32Array(const int32* a, int n, + io::CodedOutputStream* output); + static void WriteSFixed64Array(const int64* a, int n, + io::CodedOutputStream* output); + static void WriteBoolArray(const bool* a, int n, + io::CodedOutputStream* output); // Write fields, including tags. - static void WriteInt32 (field_number, int32 value, output); - static void WriteInt64 (field_number, int64 value, output); - static void WriteUInt32 (field_number, uint32 value, output); - static void WriteUInt64 (field_number, uint64 value, output); - static void WriteSInt32 (field_number, int32 value, output); - static void WriteSInt64 (field_number, int64 value, output); - static void WriteFixed32 (field_number, uint32 value, output); - static void WriteFixed64 (field_number, uint64 value, output); - static void WriteSFixed32(field_number, int32 value, output); - static void WriteSFixed64(field_number, int64 value, output); - static void WriteFloat (field_number, float value, output); - static void WriteDouble (field_number, double value, output); - static void WriteBool (field_number, bool value, output); - static void WriteEnum (field_number, int value, output); - - static void WriteString(field_number, const string& value, output); - static void WriteBytes (field_number, const string& value, output); - static void WriteStringMaybeAliased( - field_number, const string& value, output); - static void WriteBytesMaybeAliased( - field_number, const string& value, output); - - static void WriteGroup( - field_number, const MessageLite& value, output); - static void WriteMessage( - field_number, const MessageLite& value, output); + static void WriteInt32(int field_number, int32 value, + io::CodedOutputStream* output); + static void WriteInt64(int field_number, int64 value, + io::CodedOutputStream* output); + static void WriteUInt32(int field_number, uint32 value, + io::CodedOutputStream* output); + static void WriteUInt64(int field_number, uint64 value, + io::CodedOutputStream* output); + static void WriteSInt32(int field_number, int32 value, + io::CodedOutputStream* output); + static void WriteSInt64(int field_number, int64 value, + io::CodedOutputStream* output); + static void WriteFixed32(int field_number, uint32 value, + io::CodedOutputStream* output); + static void WriteFixed64(int field_number, uint64 value, + io::CodedOutputStream* output); + static void WriteSFixed32(int field_number, int32 value, + io::CodedOutputStream* output); + static void WriteSFixed64(int field_number, int64 value, + io::CodedOutputStream* output); + static void WriteFloat(int field_number, float value, + io::CodedOutputStream* output); + static void WriteDouble(int field_number, double value, + io::CodedOutputStream* output); + static void WriteBool(int field_number, bool value, + io::CodedOutputStream* output); + static void WriteEnum(int field_number, int value, + io::CodedOutputStream* output); + + static void WriteString(int field_number, const string& value, + io::CodedOutputStream* output); + static void WriteBytes(int field_number, const string& value, + io::CodedOutputStream* output); + static void WriteStringMaybeAliased(int field_number, const string& value, + io::CodedOutputStream* output); + static void WriteBytesMaybeAliased(int field_number, const string& value, + io::CodedOutputStream* output); + + static void WriteGroup(int field_number, const MessageLite& value, + io::CodedOutputStream* output); + static void WriteMessage(int field_number, const MessageLite& value, + io::CodedOutputStream* output); // Like above, but these will check if the output stream has enough // space to write directly to a flat array. - static void WriteGroupMaybeToArray( - field_number, const MessageLite& value, output); - static void WriteMessageMaybeToArray( - field_number, const MessageLite& value, output); + static void WriteGroupMaybeToArray(int field_number, const MessageLite& value, + io::CodedOutputStream* output); + static void WriteMessageMaybeToArray(int field_number, + const MessageLite& value, + io::CodedOutputStream* output); // Like above, but de-virtualize the call to SerializeWithCachedSizes(). The // pointer must point at an instance of MessageType, *not* a subclass (or // the subclass must not override SerializeWithCachedSizes()). - template - static inline void WriteGroupNoVirtual( - field_number, const MessageType& value, output); - template - static inline void WriteMessageNoVirtual( - field_number, const MessageType& value, output); - -#undef output -#define output uint8* target + template + static inline void WriteGroupNoVirtual(int field_number, + const MessageType& value, + io::CodedOutputStream* output); + template + static inline void WriteMessageNoVirtual(int field_number, + const MessageType& value, + io::CodedOutputStream* output); // Like above, but use only *ToArray methods of CodedOutputStream. - INL static uint8* WriteTagToArray(field_number, WireType type, output); + INL static uint8* WriteTagToArray(int field_number, WireType type, + uint8* target); // Write fields, without tags. - INL static uint8* WriteInt32NoTagToArray (int32 value, output); - INL static uint8* WriteInt64NoTagToArray (int64 value, output); - INL static uint8* WriteUInt32NoTagToArray (uint32 value, output); - INL static uint8* WriteUInt64NoTagToArray (uint64 value, output); - INL static uint8* WriteSInt32NoTagToArray (int32 value, output); - INL static uint8* WriteSInt64NoTagToArray (int64 value, output); - INL static uint8* WriteFixed32NoTagToArray (uint32 value, output); - INL static uint8* WriteFixed64NoTagToArray (uint64 value, output); - INL static uint8* WriteSFixed32NoTagToArray(int32 value, output); - INL static uint8* WriteSFixed64NoTagToArray(int64 value, output); - INL static uint8* WriteFloatNoTagToArray (float value, output); - INL static uint8* WriteDoubleNoTagToArray (double value, output); - INL static uint8* WriteBoolNoTagToArray (bool value, output); - INL static uint8* WriteEnumNoTagToArray (int value, output); + INL static uint8* WriteInt32NoTagToArray(int32 value, uint8* target); + INL static uint8* WriteInt64NoTagToArray(int64 value, uint8* target); + INL static uint8* WriteUInt32NoTagToArray(uint32 value, uint8* target); + INL static uint8* WriteUInt64NoTagToArray(uint64 value, uint8* target); + INL static uint8* WriteSInt32NoTagToArray(int32 value, uint8* target); + INL static uint8* WriteSInt64NoTagToArray(int64 value, uint8* target); + INL static uint8* WriteFixed32NoTagToArray(uint32 value, uint8* target); + INL static uint8* WriteFixed64NoTagToArray(uint64 value, uint8* target); + INL static uint8* WriteSFixed32NoTagToArray(int32 value, uint8* target); + INL static uint8* WriteSFixed64NoTagToArray(int64 value, uint8* target); + INL static uint8* WriteFloatNoTagToArray(float value, uint8* target); + INL static uint8* WriteDoubleNoTagToArray(double value, uint8* target); + INL static uint8* WriteBoolNoTagToArray(bool value, uint8* target); + INL static uint8* WriteEnumNoTagToArray(int value, uint8* target); + + // Write fields, without tags. These require that value.size() > 0. + template + INL static uint8* WritePrimitiveNoTagToArray( + const RepeatedField& value, + uint8* (*Writer)(T, uint8*), uint8* target); + template + INL static uint8* WriteFixedNoTagToArray( + const RepeatedField& value, + uint8* (*Writer)(T, uint8*), uint8* target); + + INL static uint8* WriteInt32NoTagToArray( + const RepeatedField< int32>& value, uint8* output); + INL static uint8* WriteInt64NoTagToArray( + const RepeatedField< int64>& value, uint8* output); + INL static uint8* WriteUInt32NoTagToArray( + const RepeatedField& value, uint8* output); + INL static uint8* WriteUInt64NoTagToArray( + const RepeatedField& value, uint8* output); + INL static uint8* WriteSInt32NoTagToArray( + const RepeatedField< int32>& value, uint8* output); + INL static uint8* WriteSInt64NoTagToArray( + const RepeatedField< int64>& value, uint8* output); + INL static uint8* WriteFixed32NoTagToArray( + const RepeatedField& value, uint8* output); + INL static uint8* WriteFixed64NoTagToArray( + const RepeatedField& value, uint8* output); + INL static uint8* WriteSFixed32NoTagToArray( + const RepeatedField< int32>& value, uint8* output); + INL static uint8* WriteSFixed64NoTagToArray( + const RepeatedField< int64>& value, uint8* output); + INL static uint8* WriteFloatNoTagToArray( + const RepeatedField< float>& value, uint8* output); + INL static uint8* WriteDoubleNoTagToArray( + const RepeatedField& value, uint8* output); + INL static uint8* WriteBoolNoTagToArray( + const RepeatedField< bool>& value, uint8* output); + INL static uint8* WriteEnumNoTagToArray( + const RepeatedField< int>& value, uint8* output); // Write fields, including tags. - INL static uint8* WriteInt32ToArray(field_number, int32 value, output); - INL static uint8* WriteInt64ToArray(field_number, int64 value, output); - INL static uint8* WriteUInt32ToArray(field_number, uint32 value, output); - INL static uint8* WriteUInt64ToArray(field_number, uint64 value, output); - INL static uint8* WriteSInt32ToArray(field_number, int32 value, output); - INL static uint8* WriteSInt64ToArray(field_number, int64 value, output); - INL static uint8* WriteFixed32ToArray(field_number, uint32 value, output); - INL static uint8* WriteFixed64ToArray(field_number, uint64 value, output); - INL static uint8* WriteSFixed32ToArray(field_number, int32 value, output); - INL static uint8* WriteSFixed64ToArray(field_number, int64 value, output); - INL static uint8* WriteFloatToArray(field_number, float value, output); - INL static uint8* WriteDoubleToArray(field_number, double value, output); - INL static uint8* WriteBoolToArray(field_number, bool value, output); - INL static uint8* WriteEnumToArray(field_number, int value, output); - - INL static uint8* WriteStringToArray( - field_number, const string& value, output); - INL static uint8* WriteBytesToArray( - field_number, const string& value, output); + INL static uint8* WriteInt32ToArray(int field_number, int32 value, + uint8* target); + INL static uint8* WriteInt64ToArray(int field_number, int64 value, + uint8* target); + INL static uint8* WriteUInt32ToArray(int field_number, uint32 value, + uint8* target); + INL static uint8* WriteUInt64ToArray(int field_number, uint64 value, + uint8* target); + INL static uint8* WriteSInt32ToArray(int field_number, int32 value, + uint8* target); + INL static uint8* WriteSInt64ToArray(int field_number, int64 value, + uint8* target); + INL static uint8* WriteFixed32ToArray(int field_number, uint32 value, + uint8* target); + INL static uint8* WriteFixed64ToArray(int field_number, uint64 value, + uint8* target); + INL static uint8* WriteSFixed32ToArray(int field_number, int32 value, + uint8* target); + INL static uint8* WriteSFixed64ToArray(int field_number, int64 value, + uint8* target); + INL static uint8* WriteFloatToArray(int field_number, float value, + uint8* target); + INL static uint8* WriteDoubleToArray(int field_number, double value, + uint8* target); + INL static uint8* WriteBoolToArray(int field_number, bool value, + uint8* target); + INL static uint8* WriteEnumToArray(int field_number, int value, + uint8* target); + + template + INL static uint8* WritePrimitiveToArray( + int field_number, + const RepeatedField& value, + uint8* (*Writer)(int, T, uint8*), uint8* target); + + INL static uint8* WriteInt32ToArray( + int field_number, const RepeatedField< int32>& value, uint8* output); + INL static uint8* WriteInt64ToArray( + int field_number, const RepeatedField< int64>& value, uint8* output); + INL static uint8* WriteUInt32ToArray( + int field_number, const RepeatedField& value, uint8* output); + INL static uint8* WriteUInt64ToArray( + int field_number, const RepeatedField& value, uint8* output); + INL static uint8* WriteSInt32ToArray( + int field_number, const RepeatedField< int32>& value, uint8* output); + INL static uint8* WriteSInt64ToArray( + int field_number, const RepeatedField< int64>& value, uint8* output); + INL static uint8* WriteFixed32ToArray( + int field_number, const RepeatedField& value, uint8* output); + INL static uint8* WriteFixed64ToArray( + int field_number, const RepeatedField& value, uint8* output); + INL static uint8* WriteSFixed32ToArray( + int field_number, const RepeatedField< int32>& value, uint8* output); + INL static uint8* WriteSFixed64ToArray( + int field_number, const RepeatedField< int64>& value, uint8* output); + INL static uint8* WriteFloatToArray( + int field_number, const RepeatedField< float>& value, uint8* output); + INL static uint8* WriteDoubleToArray( + int field_number, const RepeatedField& value, uint8* output); + INL static uint8* WriteBoolToArray( + int field_number, const RepeatedField< bool>& value, uint8* output); + INL static uint8* WriteEnumToArray( + int field_number, const RepeatedField< int>& value, uint8* output); + + INL static uint8* WriteStringToArray(int field_number, const string& value, + uint8* target); + INL static uint8* WriteBytesToArray(int field_number, const string& value, + uint8* target); // Whether to serialize deterministically (e.g., map keys are // sorted) is a property of a CodedOutputStream, and in the process // of serialization, the "ToArray" variants may be invoked. But they don't // have a CodedOutputStream available, so they get an additional parameter // telling them whether to serialize deterministically. - INL static uint8* InternalWriteGroupToArray( - field_number, const MessageLite& value, bool deterministic, output); - INL static uint8* InternalWriteMessageToArray( - field_number, const MessageLite& value, bool deterministic, output); + INL static uint8* InternalWriteGroupToArray(int field_number, + const MessageLite& value, + bool deterministic, + uint8* target); + INL static uint8* InternalWriteMessageToArray(int field_number, + const MessageLite& value, + bool deterministic, + uint8* target); // Like above, but de-virtualize the call to SerializeWithCachedSizes(). The // pointer must point at an instance of MessageType, *not* a subclass (or // the subclass must not override SerializeWithCachedSizes()). - template - INL static uint8* InternalWriteGroupNoVirtualToArray( - field_number, const MessageType& value, bool deterministic, output); - template + template + INL static uint8* InternalWriteGroupNoVirtualToArray(int field_number, + const MessageType& value, + bool deterministic, + uint8* target); + template INL static uint8* InternalWriteMessageNoVirtualToArray( - field_number, const MessageType& value, bool deterministic, output); + int field_number, const MessageType& value, bool deterministic, + uint8* target); // For backward-compatibility, the last four methods also have versions // that are non-deterministic always. - INL static uint8* WriteGroupToArray( - field_number, const MessageLite& value, output) { - return InternalWriteGroupToArray(field_number_arg, value, false, target); + INL static uint8* WriteGroupToArray(int field_number, + const MessageLite& value, uint8* target) { + return InternalWriteGroupToArray(field_number, value, false, target); } - INL static uint8* WriteMessageToArray( - field_number, const MessageLite& value, output) { - return InternalWriteMessageToArray(field_number_arg, value, false, target); + INL static uint8* WriteMessageToArray(int field_number, + const MessageLite& value, + uint8* target) { + return InternalWriteMessageToArray(field_number, value, false, target); } - template - INL static uint8* WriteGroupNoVirtualToArray( - field_number, const MessageType& value, output) { - return InternalWriteGroupNoVirtualToArray(field_number_arg, value, false, + template + INL static uint8* WriteGroupNoVirtualToArray(int field_number, + const MessageType& value, + uint8* target) { + return InternalWriteGroupNoVirtualToArray(field_number, value, false, target); } - template - INL static uint8* WriteMessageNoVirtualToArray( - field_number, const MessageType& value, output) { - return InternalWriteMessageNoVirtualToArray(field_number_arg, value, false, + template + INL static uint8* WriteMessageNoVirtualToArray(int field_number, + const MessageType& value, + uint8* target) { + return InternalWriteMessageNoVirtualToArray(field_number, value, false, target); } -#undef output -#undef input #undef INL -#undef field_number - // Compute the byte size of a field. The XxSize() functions do NOT include // the tag, so you must also call TagSize(). (This is because, for repeated // fields, you should only call TagSize() once and multiply it by the element @@ -594,9 +715,9 @@ class LIBPROTOBUF_EXPORT WireFormatLite { RepeatedField* value); // Like ReadRepeatedFixedSizePrimitive but for packed primitive fields. - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - static bool ReadPackedFixedSizePrimitive(google::protobuf::io::CodedInputStream* input, - RepeatedField* value); + template + GOOGLE_ATTRIBUTE_ALWAYS_INLINE static bool ReadPackedFixedSizePrimitive( + google::protobuf::io::CodedInputStream* input, RepeatedField* value); static const CppType kFieldTypeToCppTypeMap[]; static const WireFormatLite::WireType kWireTypeForFieldType[]; diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/wire_format_lite_inl.h b/third_party/protobuf/3.2.0/src/google/protobuf/wire_format_lite_inl.h index aa3bb3a6e9..05049017c7 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/wire_format_lite_inl.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/wire_format_lite_inl.h @@ -36,11 +36,7 @@ #ifndef GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_INL_H__ #define GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_INL_H__ -#ifdef _MSC_VER -// This is required for min/max on VS2013 only. #include -#endif - #include #include #include @@ -452,7 +448,7 @@ inline bool WireFormatLite::ReadMessage(io::CodedInputStream* input, if (p.second < 0 || !value->MergePartialFromCodedStream(input)) return false; // Make sure that parsing stopped when the limit was hit, not at an endgroup // tag. - return input->DecrementRecursionDepthAndPopLimit(p.first); + return input->DecrementRecursionDepthAndPopLimit(p.first); } // We name the template parameter something long and extremely unlikely to occur @@ -502,6 +498,7 @@ inline bool WireFormatLite::ReadMessageNoVirtual( // tag. return input->DecrementRecursionDepthAndPopLimit(p.first); } + template inline bool WireFormatLite::ReadMessageNoVirtualNoRecursionDepth( io::CodedInputStream* input, MessageType_WorkAroundCppLookupDefect* value) { @@ -671,6 +668,98 @@ inline uint8* WireFormatLite::WriteEnumNoTagToArray(int value, return io::CodedOutputStream::WriteVarint32SignExtendedToArray(value, target); } +template +inline uint8* WireFormatLite::WritePrimitiveNoTagToArray( + const RepeatedField& value, + uint8* (*Writer)(T, uint8*), uint8* target) { + const int n = value.size(); + GOOGLE_DCHECK_GT(n, 0); + + const T* ii = value.unsafe_data(); + int i = 0; + do { + target = Writer(ii[i], target); + } while (++i < n); + + return target; +} + +template +inline uint8* WireFormatLite::WriteFixedNoTagToArray( + const RepeatedField& value, + uint8* (*Writer)(T, uint8*), uint8* target) { +#if defined(PROTOBUF_LITTLE_ENDIAN) + (void) Writer; + + const int n = value.size(); + GOOGLE_DCHECK_GT(n, 0); + + const T* ii = value.unsafe_data(); + const int bytes = n * sizeof(ii[0]); + memcpy(target, ii, bytes); + return target + bytes; +#else + return WritePrimitiveNoTagToArray(value, Writer, target); +#endif +} + +inline uint8* WireFormatLite::WriteInt32NoTagToArray( + const RepeatedField< int32>& value, uint8* target) { + return WritePrimitiveNoTagToArray(value, WriteInt32NoTagToArray, target); +} +inline uint8* WireFormatLite::WriteInt64NoTagToArray( + const RepeatedField< int64>& value, uint8* target) { + return WritePrimitiveNoTagToArray(value, WriteInt64NoTagToArray, target); +} +inline uint8* WireFormatLite::WriteUInt32NoTagToArray( + const RepeatedField& value, uint8* target) { + return WritePrimitiveNoTagToArray(value, WriteUInt32NoTagToArray, target); +} +inline uint8* WireFormatLite::WriteUInt64NoTagToArray( + const RepeatedField& value, uint8* target) { + return WritePrimitiveNoTagToArray(value, WriteUInt64NoTagToArray, target); +} +inline uint8* WireFormatLite::WriteSInt32NoTagToArray( + const RepeatedField< int32>& value, uint8* target) { + return WritePrimitiveNoTagToArray(value, WriteSInt32NoTagToArray, target); +} +inline uint8* WireFormatLite::WriteSInt64NoTagToArray( + const RepeatedField< int64>& value, uint8* target) { + return WritePrimitiveNoTagToArray(value, WriteSInt64NoTagToArray, target); +} +inline uint8* WireFormatLite::WriteFixed32NoTagToArray( + const RepeatedField& value, uint8* target) { + return WriteFixedNoTagToArray(value, WriteFixed32NoTagToArray, target); +} +inline uint8* WireFormatLite::WriteFixed64NoTagToArray( + const RepeatedField& value, uint8* target) { + return WriteFixedNoTagToArray(value, WriteFixed64NoTagToArray, target); +} +inline uint8* WireFormatLite::WriteSFixed32NoTagToArray( + const RepeatedField< int32>& value, uint8* target) { + return WriteFixedNoTagToArray(value, WriteSFixed32NoTagToArray, target); +} +inline uint8* WireFormatLite::WriteSFixed64NoTagToArray( + const RepeatedField< int64>& value, uint8* target) { + return WriteFixedNoTagToArray(value, WriteSFixed64NoTagToArray, target); +} +inline uint8* WireFormatLite::WriteFloatNoTagToArray( + const RepeatedField< float>& value, uint8* target) { + return WriteFixedNoTagToArray(value, WriteFloatNoTagToArray, target); +} +inline uint8* WireFormatLite::WriteDoubleNoTagToArray( + const RepeatedField& value, uint8* target) { + return WriteFixedNoTagToArray(value, WriteDoubleNoTagToArray, target); +} +inline uint8* WireFormatLite::WriteBoolNoTagToArray( + const RepeatedField< bool>& value, uint8* target) { + return WritePrimitiveNoTagToArray(value, WriteBoolNoTagToArray, target); +} +inline uint8* WireFormatLite::WriteEnumNoTagToArray( + const RepeatedField< int>& value, uint8* target) { + return WritePrimitiveNoTagToArray(value, WriteEnumNoTagToArray, target); +} + inline uint8* WireFormatLite::WriteInt32ToArray(int field_number, int32 value, uint8* target) { @@ -756,6 +845,85 @@ inline uint8* WireFormatLite::WriteEnumToArray(int field_number, return WriteEnumNoTagToArray(value, target); } +template +inline uint8* WireFormatLite::WritePrimitiveToArray( + int field_number, + const RepeatedField& value, + uint8* (*Writer)(int, T, uint8*), uint8* target) { + const int n = value.size(); + if (n == 0) { + return target; + } + + const T* ii = value.unsafe_data(); + int i = 0; + do { + target = Writer(field_number, ii[i], target); + } while (++i < n); + + return target; +} + +inline uint8* WireFormatLite::WriteInt32ToArray( + int field_number, const RepeatedField< int32>& value, uint8* target) { + return WritePrimitiveToArray(field_number, value, WriteInt32ToArray, target); +} +inline uint8* WireFormatLite::WriteInt64ToArray( + int field_number, const RepeatedField< int64>& value, uint8* target) { + return WritePrimitiveToArray(field_number, value, WriteInt64ToArray, target); +} +inline uint8* WireFormatLite::WriteUInt32ToArray( + int field_number, const RepeatedField& value, uint8* target) { + return WritePrimitiveToArray(field_number, value, WriteUInt32ToArray, target); +} +inline uint8* WireFormatLite::WriteUInt64ToArray( + int field_number, const RepeatedField& value, uint8* target) { + return WritePrimitiveToArray(field_number, value, WriteUInt64ToArray, target); +} +inline uint8* WireFormatLite::WriteSInt32ToArray( + int field_number, const RepeatedField< int32>& value, uint8* target) { + return WritePrimitiveToArray(field_number, value, WriteSInt32ToArray, target); +} +inline uint8* WireFormatLite::WriteSInt64ToArray( + int field_number, const RepeatedField< int64>& value, uint8* target) { + return WritePrimitiveToArray(field_number, value, WriteSInt64ToArray, target); +} +inline uint8* WireFormatLite::WriteFixed32ToArray( + int field_number, const RepeatedField& value, uint8* target) { + return WritePrimitiveToArray( + field_number, value, WriteFixed32ToArray, target); +} +inline uint8* WireFormatLite::WriteFixed64ToArray( + int field_number, const RepeatedField& value, uint8* target) { + return WritePrimitiveToArray( + field_number, value, WriteFixed64ToArray, target); +} +inline uint8* WireFormatLite::WriteSFixed32ToArray( + int field_number, const RepeatedField< int32>& value, uint8* target) { + return WritePrimitiveToArray( + field_number, value, WriteSFixed32ToArray, target); +} +inline uint8* WireFormatLite::WriteSFixed64ToArray( + int field_number, const RepeatedField< int64>& value, uint8* target) { + return WritePrimitiveToArray( + field_number, value, WriteSFixed64ToArray, target); +} +inline uint8* WireFormatLite::WriteFloatToArray( + int field_number, const RepeatedField< float>& value, uint8* target) { + return WritePrimitiveToArray(field_number, value, WriteFloatToArray, target); +} +inline uint8* WireFormatLite::WriteDoubleToArray( + int field_number, const RepeatedField& value, uint8* target) { + return WritePrimitiveToArray(field_number, value, WriteDoubleToArray, target); +} +inline uint8* WireFormatLite::WriteBoolToArray( + int field_number, const RepeatedField< bool>& value, uint8* target) { + return WritePrimitiveToArray(field_number, value, WriteBoolToArray, target); +} +inline uint8* WireFormatLite::WriteEnumToArray( + int field_number, const RepeatedField< int>& value, uint8* target) { + return WritePrimitiveToArray(field_number, value, WriteEnumToArray, target); +} inline uint8* WireFormatLite::WriteStringToArray(int field_number, const string& value, uint8* target) { @@ -797,7 +965,8 @@ inline uint8* WireFormatLite::InternalWriteGroupNoVirtualToArray( int field_number, const MessageType_WorkAroundCppLookupDefect& value, bool deterministic, uint8* target) { target = WriteTagToArray(field_number, WIRETYPE_START_GROUP, target); - target = value.InternalSerializeWithCachedSizesToArray(deterministic, target); + target = value.MessageType_WorkAroundCppLookupDefect:: + InternalSerializeWithCachedSizesToArray(deterministic, target); return WriteTagToArray(field_number, WIRETYPE_END_GROUP, target); } template @@ -807,7 +976,8 @@ inline uint8* WireFormatLite::InternalWriteMessageNoVirtualToArray( target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target); target = io::CodedOutputStream::WriteVarint32ToArray( value.MessageType_WorkAroundCppLookupDefect::GetCachedSize(), target); - return value.InternalSerializeWithCachedSizesToArray(deterministic, target); + return value.MessageType_WorkAroundCppLookupDefect:: + InternalSerializeWithCachedSizesToArray(deterministic, target); } // =================================================================== diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/wire_format_unittest.cc b/third_party/protobuf/3.2.0/src/google/protobuf/wire_format_unittest.cc index 897fec00c7..cafe9a48f9 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/wire_format_unittest.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/wire_format_unittest.cc @@ -1029,6 +1029,29 @@ TEST_F(WireFormatInvalidInputTest, InvalidSubMessage) { EXPECT_FALSE(message.ParseFromString(MakeInvalidEmbeddedMessage("\017", 1))); } +TEST_F(WireFormatInvalidInputTest, InvalidMessageWithExtraZero) { + string data; + { + // Serialize a valid proto + unittest::TestAllTypes message; + message.set_optional_int32(1); + message.SerializeToString(&data); + data.push_back(0); // Append invalid zero tag + } + + // Control case. + { + io::ArrayInputStream ais(data.data(), data.size()); + io::CodedInputStream is(&ais); + unittest::TestAllTypes message; + // It should fail but currently passes. + EXPECT_TRUE(message.MergePartialFromCodedStream(&is)); + // Parsing from the string should fail. + EXPECT_FALSE(message.ParseFromString(data)); + } +} + + TEST_F(WireFormatInvalidInputTest, InvalidGroup) { unittest::TestAllTypes message; diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/wrappers.pb.cc b/third_party/protobuf/3.2.0/src/google/protobuf/wrappers.pb.cc index d614de9dc9..12c04fd5f0 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/wrappers.pb.cc +++ b/third_party/protobuf/3.2.0/src/google/protobuf/wrappers.pb.cc @@ -47,64 +47,95 @@ namespace { } // namespace +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField + const TableStruct::entries[] = { + {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, +}; + +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField + const TableStruct::aux[] = { + ::google::protobuf::internal::AuxillaryParseTableField(), +}; +PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const + TableStruct::schema[] = { + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, + { NULL, NULL, 0, -1, -1, false }, +}; + const ::google::protobuf::uint32 TableStruct::offsets[] = { ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DoubleValue, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DoubleValue, value_), ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FloatValue, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FloatValue, value_), ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Int64Value, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Int64Value, value_), ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UInt64Value, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UInt64Value, value_), ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Int32Value, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Int32Value, value_), ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UInt32Value, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UInt32Value, value_), ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(BoolValue, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(BoolValue, value_), ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(StringValue, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(StringValue, value_), ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(BytesValue, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(BytesValue, value_), }; static const ::google::protobuf::internal::MigrationSchema schemas[] = { { 0, -1, sizeof(DoubleValue)}, - { 5, -1, sizeof(FloatValue)}, - { 10, -1, sizeof(Int64Value)}, - { 15, -1, sizeof(UInt64Value)}, - { 20, -1, sizeof(Int32Value)}, - { 25, -1, sizeof(UInt32Value)}, - { 30, -1, sizeof(BoolValue)}, - { 35, -1, sizeof(StringValue)}, - { 40, -1, sizeof(BytesValue)}, + { 6, -1, sizeof(FloatValue)}, + { 12, -1, sizeof(Int64Value)}, + { 18, -1, sizeof(UInt64Value)}, + { 24, -1, sizeof(Int32Value)}, + { 30, -1, sizeof(UInt32Value)}, + { 36, -1, sizeof(BoolValue)}, + { 42, -1, sizeof(StringValue)}, + { 48, -1, sizeof(BytesValue)}, }; static ::google::protobuf::Message const * const file_default_instances[] = { @@ -283,7 +314,7 @@ void DoubleValue::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* DoubleValue::descriptor() { protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[0].descriptor; + return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const DoubleValue& DoubleValue::default_instance() { @@ -348,6 +379,9 @@ failure: void DoubleValue::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.DoubleValue) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // double value = 1; if (this->value() != 0) { ::google::protobuf::internal::WireFormatLite::WriteDouble(1, this->value(), output); @@ -358,8 +392,10 @@ 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; + // double value = 1; if (this->value() != 0) { target = ::google::protobuf::internal::WireFormatLite::WriteDoubleToArray(1, this->value(), target); @@ -404,6 +440,9 @@ void DoubleValue::MergeFrom(const DoubleValue& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DoubleValue) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + if (from.value() != 0) { set_value(from.value()); } @@ -453,7 +492,7 @@ void DoubleValue::InternalSwap(DoubleValue* other) { ::google::protobuf::Metadata DoubleValue::GetMetadata() const { protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[0]; + return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -539,7 +578,7 @@ void FloatValue::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* FloatValue::descriptor() { protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[1].descriptor; + return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const FloatValue& FloatValue::default_instance() { @@ -604,6 +643,9 @@ failure: void FloatValue::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.FloatValue) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // float value = 1; if (this->value() != 0) { ::google::protobuf::internal::WireFormatLite::WriteFloat(1, this->value(), output); @@ -614,8 +656,10 @@ 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; + // float value = 1; if (this->value() != 0) { target = ::google::protobuf::internal::WireFormatLite::WriteFloatToArray(1, this->value(), target); @@ -660,6 +704,9 @@ void FloatValue::MergeFrom(const FloatValue& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FloatValue) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + if (from.value() != 0) { set_value(from.value()); } @@ -709,7 +756,7 @@ void FloatValue::InternalSwap(FloatValue* other) { ::google::protobuf::Metadata FloatValue::GetMetadata() const { protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[1]; + return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -795,7 +842,7 @@ void Int64Value::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* Int64Value::descriptor() { protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[2].descriptor; + return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const Int64Value& Int64Value::default_instance() { @@ -860,6 +907,9 @@ failure: void Int64Value::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.Int64Value) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // int64 value = 1; if (this->value() != 0) { ::google::protobuf::internal::WireFormatLite::WriteInt64(1, this->value(), output); @@ -870,8 +920,10 @@ 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; + // int64 value = 1; if (this->value() != 0) { target = ::google::protobuf::internal::WireFormatLite::WriteInt64ToArray(1, this->value(), target); @@ -918,6 +970,9 @@ void Int64Value::MergeFrom(const Int64Value& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Int64Value) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + if (from.value() != 0) { set_value(from.value()); } @@ -967,7 +1022,7 @@ void Int64Value::InternalSwap(Int64Value* other) { ::google::protobuf::Metadata Int64Value::GetMetadata() const { protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[2]; + return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -1053,7 +1108,7 @@ void UInt64Value::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* UInt64Value::descriptor() { protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[3].descriptor; + return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const UInt64Value& UInt64Value::default_instance() { @@ -1118,6 +1173,9 @@ failure: void UInt64Value::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.UInt64Value) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // uint64 value = 1; if (this->value() != 0) { ::google::protobuf::internal::WireFormatLite::WriteUInt64(1, this->value(), output); @@ -1128,8 +1186,10 @@ 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; + // uint64 value = 1; if (this->value() != 0) { target = ::google::protobuf::internal::WireFormatLite::WriteUInt64ToArray(1, this->value(), target); @@ -1176,6 +1236,9 @@ void UInt64Value::MergeFrom(const UInt64Value& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UInt64Value) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + if (from.value() != 0) { set_value(from.value()); } @@ -1225,7 +1288,7 @@ void UInt64Value::InternalSwap(UInt64Value* other) { ::google::protobuf::Metadata UInt64Value::GetMetadata() const { protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[3]; + return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -1311,7 +1374,7 @@ void Int32Value::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* Int32Value::descriptor() { protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[4].descriptor; + return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const Int32Value& Int32Value::default_instance() { @@ -1376,6 +1439,9 @@ failure: void Int32Value::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.Int32Value) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // int32 value = 1; if (this->value() != 0) { ::google::protobuf::internal::WireFormatLite::WriteInt32(1, this->value(), output); @@ -1386,8 +1452,10 @@ 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; + // int32 value = 1; if (this->value() != 0) { target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(1, this->value(), target); @@ -1434,6 +1502,9 @@ void Int32Value::MergeFrom(const Int32Value& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Int32Value) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + if (from.value() != 0) { set_value(from.value()); } @@ -1483,7 +1554,7 @@ void Int32Value::InternalSwap(Int32Value* other) { ::google::protobuf::Metadata Int32Value::GetMetadata() const { protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[4]; + return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -1569,7 +1640,7 @@ void UInt32Value::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* UInt32Value::descriptor() { protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[5].descriptor; + return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const UInt32Value& UInt32Value::default_instance() { @@ -1634,6 +1705,9 @@ failure: void UInt32Value::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.UInt32Value) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // uint32 value = 1; if (this->value() != 0) { ::google::protobuf::internal::WireFormatLite::WriteUInt32(1, this->value(), output); @@ -1644,8 +1718,10 @@ 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; + // uint32 value = 1; if (this->value() != 0) { target = ::google::protobuf::internal::WireFormatLite::WriteUInt32ToArray(1, this->value(), target); @@ -1692,6 +1768,9 @@ void UInt32Value::MergeFrom(const UInt32Value& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UInt32Value) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + if (from.value() != 0) { set_value(from.value()); } @@ -1741,7 +1820,7 @@ void UInt32Value::InternalSwap(UInt32Value* other) { ::google::protobuf::Metadata UInt32Value::GetMetadata() const { protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[5]; + return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -1827,7 +1906,7 @@ void BoolValue::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* BoolValue::descriptor() { protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[6].descriptor; + return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const BoolValue& BoolValue::default_instance() { @@ -1892,6 +1971,9 @@ failure: void BoolValue::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.BoolValue) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // bool value = 1; if (this->value() != 0) { ::google::protobuf::internal::WireFormatLite::WriteBool(1, this->value(), output); @@ -1902,8 +1984,10 @@ 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; + // bool value = 1; if (this->value() != 0) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(1, this->value(), target); @@ -1948,6 +2032,9 @@ void BoolValue::MergeFrom(const BoolValue& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.BoolValue) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + if (from.value() != 0) { set_value(from.value()); } @@ -1997,7 +2084,7 @@ void BoolValue::InternalSwap(BoolValue* other) { ::google::protobuf::Metadata BoolValue::GetMetadata() const { protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[6]; + return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -2088,7 +2175,7 @@ void StringValue::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* StringValue::descriptor() { protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[7].descriptor; + return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const StringValue& StringValue::default_instance() { @@ -2155,6 +2242,9 @@ failure: void StringValue::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.StringValue) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // string value = 1; if (this->value().size() > 0) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -2170,8 +2260,10 @@ 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; + // string value = 1; if (this->value().size() > 0) { ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -2224,6 +2316,9 @@ void StringValue::MergeFrom(const StringValue& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.StringValue) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + if (from.value().size() > 0) { set_value(from.value()); } @@ -2273,7 +2368,7 @@ void StringValue::InternalSwap(StringValue* other) { ::google::protobuf::Metadata StringValue::GetMetadata() const { protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[7]; + return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -2293,6 +2388,7 @@ void StringValue::set_value(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.StringValue.value) } void StringValue::set_value(const char* value) { + GOOGLE_DCHECK(value != NULL); value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArenaNoVirtual()); @@ -2416,7 +2512,7 @@ void BytesValue::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* BytesValue::descriptor() { protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[8].descriptor; + return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; } const BytesValue& BytesValue::default_instance() { @@ -2479,6 +2575,9 @@ failure: void BytesValue::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.BytesValue) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + // bytes value = 1; if (this->value().size() > 0) { ::google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased( @@ -2490,8 +2589,10 @@ 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; + // bytes value = 1; if (this->value().size() > 0) { target = @@ -2540,6 +2641,9 @@ void BytesValue::MergeFrom(const BytesValue& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.BytesValue) GOOGLE_DCHECK_NE(&from, this); _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + if (from.value().size() > 0) { set_value(from.value()); } @@ -2589,7 +2693,7 @@ void BytesValue::InternalSwap(BytesValue* other) { ::google::protobuf::Metadata BytesValue::GetMetadata() const { protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce(); - return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[8]; + return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[kIndexInFileMessages]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -2609,6 +2713,7 @@ void BytesValue::set_value(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.BytesValue.value) } void BytesValue::set_value(const char* value) { + GOOGLE_DCHECK(value != NULL); value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArenaNoVirtual()); diff --git a/third_party/protobuf/3.2.0/src/google/protobuf/wrappers.pb.h b/third_party/protobuf/3.2.0/src/google/protobuf/wrappers.pb.h index 61b0510dca..4202541b6c 100644 --- a/third_party/protobuf/3.2.0/src/google/protobuf/wrappers.pb.h +++ b/third_party/protobuf/3.2.0/src/google/protobuf/wrappers.pb.h @@ -8,12 +8,12 @@ #include -#if GOOGLE_PROTOBUF_VERSION < 3002000 +#if GOOGLE_PROTOBUF_VERSION < 3003000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION +#if 3003000 < 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. @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -67,6 +68,9 @@ namespace protobuf { namespace protobuf_google_2fprotobuf_2fwrappers_2eproto { // Internal implementation detail -- do not call these. struct LIBPROTOBUF_EXPORT TableStruct { + static const ::google::protobuf::internal::ParseTableField entries[]; + static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; + static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; static void InitDefaultsImpl(); static void Shutdown(); @@ -102,6 +106,8 @@ class LIBPROTOBUF_EXPORT DoubleValue : public ::google::protobuf::Message /* @@p return reinterpret_cast( &_DoubleValue_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 0; void UnsafeArenaSwap(DoubleValue* other); void Swap(DoubleValue* other); @@ -125,11 +131,6 @@ class LIBPROTOBUF_EXPORT DoubleValue : public ::google::protobuf::Message /* @@p ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -171,7 +172,7 @@ class LIBPROTOBUF_EXPORT DoubleValue : public ::google::protobuf::Message /* @@p typedef void DestructorSkippable_; double value_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct; }; // ------------------------------------------------------------------- @@ -200,6 +201,8 @@ class LIBPROTOBUF_EXPORT FloatValue : public ::google::protobuf::Message /* @@pr return reinterpret_cast( &_FloatValue_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 1; void UnsafeArenaSwap(FloatValue* other); void Swap(FloatValue* other); @@ -223,11 +226,6 @@ class LIBPROTOBUF_EXPORT FloatValue : public ::google::protobuf::Message /* @@pr ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -269,7 +267,7 @@ class LIBPROTOBUF_EXPORT FloatValue : public ::google::protobuf::Message /* @@pr typedef void DestructorSkippable_; float value_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct; }; // ------------------------------------------------------------------- @@ -298,6 +296,8 @@ class LIBPROTOBUF_EXPORT Int64Value : public ::google::protobuf::Message /* @@pr return reinterpret_cast( &_Int64Value_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 2; void UnsafeArenaSwap(Int64Value* other); void Swap(Int64Value* other); @@ -321,11 +321,6 @@ class LIBPROTOBUF_EXPORT Int64Value : public ::google::protobuf::Message /* @@pr ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -367,7 +362,7 @@ class LIBPROTOBUF_EXPORT Int64Value : public ::google::protobuf::Message /* @@pr typedef void DestructorSkippable_; ::google::protobuf::int64 value_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct; }; // ------------------------------------------------------------------- @@ -396,6 +391,8 @@ class LIBPROTOBUF_EXPORT UInt64Value : public ::google::protobuf::Message /* @@p return reinterpret_cast( &_UInt64Value_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 3; void UnsafeArenaSwap(UInt64Value* other); void Swap(UInt64Value* other); @@ -419,11 +416,6 @@ class LIBPROTOBUF_EXPORT UInt64Value : public ::google::protobuf::Message /* @@p ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -465,7 +457,7 @@ class LIBPROTOBUF_EXPORT UInt64Value : public ::google::protobuf::Message /* @@p typedef void DestructorSkippable_; ::google::protobuf::uint64 value_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct; }; // ------------------------------------------------------------------- @@ -494,6 +486,8 @@ class LIBPROTOBUF_EXPORT Int32Value : public ::google::protobuf::Message /* @@pr return reinterpret_cast( &_Int32Value_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 4; void UnsafeArenaSwap(Int32Value* other); void Swap(Int32Value* other); @@ -517,11 +511,6 @@ class LIBPROTOBUF_EXPORT Int32Value : public ::google::protobuf::Message /* @@pr ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -563,7 +552,7 @@ class LIBPROTOBUF_EXPORT Int32Value : public ::google::protobuf::Message /* @@pr typedef void DestructorSkippable_; ::google::protobuf::int32 value_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct; }; // ------------------------------------------------------------------- @@ -592,6 +581,8 @@ class LIBPROTOBUF_EXPORT UInt32Value : public ::google::protobuf::Message /* @@p return reinterpret_cast( &_UInt32Value_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 5; void UnsafeArenaSwap(UInt32Value* other); void Swap(UInt32Value* other); @@ -615,11 +606,6 @@ class LIBPROTOBUF_EXPORT UInt32Value : public ::google::protobuf::Message /* @@p ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -661,7 +647,7 @@ class LIBPROTOBUF_EXPORT UInt32Value : public ::google::protobuf::Message /* @@p typedef void DestructorSkippable_; ::google::protobuf::uint32 value_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct; }; // ------------------------------------------------------------------- @@ -690,6 +676,8 @@ class LIBPROTOBUF_EXPORT BoolValue : public ::google::protobuf::Message /* @@pro return reinterpret_cast( &_BoolValue_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 6; void UnsafeArenaSwap(BoolValue* other); void Swap(BoolValue* other); @@ -713,11 +701,6 @@ class LIBPROTOBUF_EXPORT BoolValue : public ::google::protobuf::Message /* @@pro ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -759,7 +742,7 @@ class LIBPROTOBUF_EXPORT BoolValue : public ::google::protobuf::Message /* @@pro typedef void DestructorSkippable_; bool value_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct; }; // ------------------------------------------------------------------- @@ -788,6 +771,8 @@ class LIBPROTOBUF_EXPORT StringValue : public ::google::protobuf::Message /* @@p return reinterpret_cast( &_StringValue_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 7; void UnsafeArenaSwap(StringValue* other); void Swap(StringValue* other); @@ -811,11 +796,6 @@ class LIBPROTOBUF_EXPORT StringValue : public ::google::protobuf::Message /* @@p ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -865,7 +845,7 @@ class LIBPROTOBUF_EXPORT StringValue : public ::google::protobuf::Message /* @@p typedef void DestructorSkippable_; ::google::protobuf::internal::ArenaStringPtr value_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct; }; // ------------------------------------------------------------------- @@ -894,6 +874,8 @@ class LIBPROTOBUF_EXPORT BytesValue : public ::google::protobuf::Message /* @@pr return reinterpret_cast( &_BytesValue_default_instance_); } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 8; void UnsafeArenaSwap(BytesValue* other); void Swap(BytesValue* other); @@ -917,11 +899,6 @@ class LIBPROTOBUF_EXPORT BytesValue : public ::google::protobuf::Message /* @@pr ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) - const PROTOBUF_FINAL { - return InternalSerializeWithCachedSizesToArray( - ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output); - } int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); @@ -971,7 +948,7 @@ class LIBPROTOBUF_EXPORT BytesValue : public ::google::protobuf::Message /* @@pr typedef void DestructorSkippable_; ::google::protobuf::internal::ArenaStringPtr value_; mutable int _cached_size_; - friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct; + friend struct protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct; }; // =================================================================== @@ -1121,6 +1098,7 @@ inline void StringValue::set_value(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.StringValue.value) } inline void StringValue::set_value(const char* value) { + GOOGLE_DCHECK(value != NULL); value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArenaNoVirtual()); @@ -1191,6 +1169,7 @@ inline void BytesValue::set_value(const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.BytesValue.value) } inline void BytesValue::set_value(const char* value) { + GOOGLE_DCHECK(value != NULL); value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArenaNoVirtual()); diff --git a/third_party/protobuf/3.2.0/tests.sh b/third_party/protobuf/3.2.0/tests.sh index 68ba7cc7b2..edb37da7ac 100755 --- a/third_party/protobuf/3.2.0/tests.sh +++ b/third_party/protobuf/3.2.0/tests.sh @@ -362,6 +362,7 @@ generate_php_test_proto() { ../../src/protoc --php_out=generated proto/test.proto proto/test_include.proto proto/test_no_namespace.proto proto/test_prefix.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 popd popd } @@ -371,12 +372,9 @@ use_php() { PHP=`which php` PHP_CONFIG=`which php-config` PHPIZE=`which phpize` - rm $PHP - rm $PHP_CONFIG - rm $PHPIZE - cp "/usr/bin/php$VERSION" $PHP - cp "/usr/bin/php-config$VERSION" $PHP_CONFIG - cp "/usr/bin/phpize$VERSION" $PHPIZE + ln -sfn "/usr/local/php-${VERSION}/bin/php" $PHP + ln -sfn "/usr/local/php-${VERSION}/bin/php-config" $PHP_CONFIG + ln -sfn "/usr/local/php-${VERSION}/bin/phpize" $PHPIZE generate_php_test_proto } @@ -403,18 +401,13 @@ use_php_bc() { } build_php5.5() { - PHP=`which php` - PHP_CONFIG=`which php-config` - PHPIZE=`which phpize` - ln -sfn "/usr/local/php-5.5/bin/php" $PHP - ln -sfn "/usr/local/php-5.5/bin/php-config" $PHP_CONFIG - ln -sfn "/usr/local/php-5.5/bin/phpize" $PHPIZE - generate_php_test_proto + use_php 5.5 pushd php rm -rf vendor cp -r /usr/local/vendor-5.5 vendor - ./vendor/bin/phpunit + wget https://phar.phpunit.de/phpunit-4.8.0.phar -O /usr/bin/phpunit + phpunit popd pushd conformance # TODO(teboring): Add it back @@ -423,51 +416,21 @@ build_php5.5() { } build_php5.5_c() { - PHP=`which php` - PHP_CONFIG=`which php-config` - PHPIZE=`which phpize` - ln -sfn "/usr/local/php-5.5/bin/php" $PHP - ln -sfn "/usr/local/php-5.5/bin/php-config" $PHP_CONFIG - ln -sfn "/usr/local/php-5.5/bin/phpize" $PHPIZE - generate_php_test_proto - wget https://phar.phpunit.de/phpunit-old.phar -O /usr/bin/phpunit - + use_php 5.5 + wget https://phar.phpunit.de/phpunit-4.8.0.phar -O /usr/bin/phpunit cd php/tests && /bin/bash ./test.sh && cd ../.. pushd conformance - make test_php_c + # make test_php_c popd } build_php5.5_zts_c() { use_php_zts 5.5 - wget https://phar.phpunit.de/phpunit-old.phar -O /usr/bin/phpunit + wget https://phar.phpunit.de/phpunit-4.8.0.phar -O /usr/bin/phpunit cd php/tests && /bin/bash ./test.sh && cd ../.. pushd conformance - make test_php_c - popd -} - -build_php5.5_32() { - use_php_bc 5.5 - pushd php - rm -rf vendor - cp -r /usr/local/vendor-5.5 vendor - ./vendor/bin/phpunit - popd - # TODO(teboring): Add conformance test. - # pushd conformance - # make test_php - # popd -} - -build_php5.5_c_32() { - use_php_bc 5.5 - wget https://phar.phpunit.de/phpunit-old.phar -O /usr/bin/phpunit - cd php/tests && /bin/bash ./test.sh && cd ../.. - # TODO(teboring): Add conformance test. - # pushd conformance # make test_php_c - # popd + popd } build_php5.6() { @@ -475,7 +438,8 @@ build_php5.6() { pushd php rm -rf vendor cp -r /usr/local/vendor-5.6 vendor - ./vendor/bin/phpunit + wget https://phar.phpunit.de/phpunit-5.7.0.phar -O /usr/bin/phpunit + phpunit popd pushd conformance # TODO(teboring): Add it back @@ -485,9 +449,19 @@ build_php5.6() { build_php5.6_c() { use_php 5.6 + wget https://phar.phpunit.de/phpunit-5.7.0.phar -O /usr/bin/phpunit cd php/tests && /bin/bash ./test.sh && cd ../.. pushd conformance - make test_php_c + # make test_php_c + popd +} + +build_php5.6_zts_c() { + use_php_zts 5.6 + wget https://phar.phpunit.de/phpunit-5.7.0.phar -O /usr/bin/phpunit + cd php/tests && /bin/bash ./test.sh && cd ../.. + pushd conformance + # make test_php_c popd } @@ -511,7 +485,7 @@ build_php5.6_mac() { # Test cd php/tests && /bin/bash ./test.sh && cd ../.. pushd conformance - make test_php_c + # make test_php_c popd } @@ -520,7 +494,8 @@ build_php7.0() { pushd php rm -rf vendor cp -r /usr/local/vendor-7.0 vendor - ./vendor/bin/phpunit + wget https://phar.phpunit.de/phpunit-5.6.0.phar -O /usr/bin/phpunit + phpunit popd pushd conformance # TODO(teboring): Add it back @@ -530,9 +505,43 @@ build_php7.0() { build_php7.0_c() { use_php 7.0 + 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 + # make test_php_c + popd +} + +build_php7.0_zts_c() { + use_php_zts 7.0 + 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.0_mac() { + generate_php_test_proto + # Install PHP + curl -s https://php-osx.liip.ch/install.sh | bash -s 7.0 + PHP_FOLDER=`find /usr/local -type d -name "php7-7.0*"` # The folder name may change upon time + export PATH="$PHP_FOLDER/bin:$PATH" + + # Install phpunit + curl https://phar.phpunit.de/phpunit-5.6.0.phar -L -o phpunit.phar + chmod +x phpunit.phar + sudo mv phpunit.phar /usr/local/bin/phpunit + + # Install valgrind + echo "#! /bin/bash" > valgrind + chmod ug+x valgrind + sudo mv valgrind /usr/local/bin/valgrind + + # Test + cd php/tests && /bin/bash ./test.sh && cd ../.. + pushd conformance + # make test_php_c popd } @@ -542,13 +551,10 @@ build_php_all() { build_php7.0 build_php5.5_c build_php5.6_c - # build_php7.0_c + build_php7.0_c build_php5.5_zts_c -} - -build_php_all_32() { - build_php5.5_32 - build_php5.5_c_32 + build_php5.6_zts_c + build_php7.0_zts_c } # Note: travis currently does not support testing more than one language so the diff --git a/third_party/protobuf/3.2.0/update_file_lists.sh b/third_party/protobuf/3.2.0/update_file_lists.sh index d76a1610a3..9c0fbdc586 100755 --- a/third_party/protobuf/3.2.0/update_file_lists.sh +++ b/third_party/protobuf/3.2.0/update_file_lists.sh @@ -135,7 +135,7 @@ for HEADER in $PUBLIC_HEADERS; do done | sort | uniq | sed "s/^/mkdir include\\\\/" >> $EXTRACT_INCLUDES_BAT for HEADER in $PUBLIC_HEADERS; do WINPATH=$(echo $HEADER | sed 's;/;\\;g') - echo "copy \${PROTOBUF_SOURCE_WIN32_PATH}\\..\\src\\$WINPATH include\\$WINPATH" >> $EXTRACT_INCLUDES_BAT + echo "copy \"\${PROTOBUF_SOURCE_WIN32_PATH}\\..\\src\\$WINPATH\" include\\$WINPATH" >> $EXTRACT_INCLUDES_BAT done ################################################################################ diff --git a/third_party/protobuf/3.2.0/util/python/BUILD b/third_party/protobuf/3.2.0/util/python/BUILD index d86a84757b..ea9fa641e2 100644 --- a/third_party/protobuf/3.2.0/util/python/BUILD +++ b/third_party/protobuf/3.2.0/util/python/BUILD @@ -12,7 +12,6 @@ # name = "python", # path = __workspace_dir__ + "/util/python", # ) - licenses(["notice"]) filegroup( diff --git a/third_party/protobuf/README.md b/third_party/protobuf/README.md index 367d542d06..159719d5e3 100644 --- a/third_party/protobuf/README.md +++ b/third_party/protobuf/README.md @@ -1,28 +1,37 @@ -### Updating the jar binary +# Updating protobuf -1. Go to http://search.maven.org/ -2. Search for g:"com.google.protobuf" -3. Download the "jar" link from protobuf-java and put them in `/third_party/protobuf/` -* * * -### Updating `protobuf.bzl` and the `src/` directory: +1) Fetch the desired protobuf version and copy it in a folder `new_proto` under +`third_party/protobuf`. +2) Bazel uses upstream protobuf from source, except for java, as we currently don't +build protobuf java when bootstrapping bazel. So instead we use already build jars. +So build the java proto library from source and in case you cloned an upstream version +of protobuf, remove the .git folders: +``` +cd new_proto +bazel build :protobuf_java :protobuf_java_util +cp bazel-bin/libprotobuf_java.jar . +cp bazel-bin/libprotobuf_java_util.jar . +bazel clean --expunge +rm -rf .git .gitignore .gitmodules +``` +3) Modify protobuf's `BUILD` file to not build java from source, but to use + the jars instead. To do that, in the BUILD file delete the rules listed + under `Java support`. Then, from the `third_party/protobuf//BUILD file` + copy the rules under "Modifications made by bazel" to the new BUILD file. + The java rules in there should have the same names as the ones you just deleted under "Java support". + You might need to update the names of the jars in the rules sources to the ones you just build. +4) Copy `third_party/protobuf/com_google_protobuf_java.BUILD` to the new + directory. +5) Name the `new_proto` directory according to the protobuf version number. +5) In `third_party/protobuf/BUILD` update PROTOBUF_VERSION to the name of the +directory you just created. +6) Update this file if you found the :instructions to be wrong or incomplete. -1. `git clone http://github.com/google/protobuf.git` -2. `git checkout ` (e.g. `v3.0.0` or `e8ae137`) -3. `mkdir -p third_party/protobuf//src/google` in the root of the Bazel tree. -4. `cp -R /src/google/protobuf third_party/protobuf/src/google` -5. Update the rules in `third_party/protobuf/BUILD` with the rules in the protobuf repository. +# Current protobuf version -Finally, update the rules: - -1. Add a BUILD file to `third_party/protobuf//`. Use the BUILD file - for the previous version as a template. Update the `cc_library` rules to - match the rules in the BUILD file in the protobuf repository. Also copy - `protobuf.bzl` from the protobuf repository into - `third_party/protobuf//`. -2. Modify `third_party/protobuf/BUILD` to point to the new rules. -3. Delete the old version of protobuf. - -* * * -### Updating anything else in the directory -Follow usual procedure as described on https://www.bazel.build/contributing.html +The current version of protobuf was obtained from @laszlocsomor's protobuf fork +`https://github.com/laszlocsomor/protobuf` at commit `a80186eb10e027`. Once +`https://github.com/google/protobuf/pull/2969` is merged into upstream +protobuf, we no longer need to use @laszlocsomor's fork but can directly clone +upstream. -- cgit v1.2.3