From 9086d9643903c608ab015b0b7d903547a4e7b6f3 Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Wed, 13 Jul 2016 13:47:51 -0700 Subject: [PATCH 01/18] Integrate from internal code base. --- cmake/examples.cmake | 114 +++++----- cmake/protobuf-options.cmake | 14 +- examples/CMakeLists.txt | 126 +++++------ .../google/protobuf/CodedOutputStream.java | 38 ++++ .../com/google/protobuf/DynamicMessage.java | 8 + .../google/protobuf/FieldPresenceTest.java | 50 +++++ .../protobuf/LazyStringArrayListTest.java | 3 +- .../com/google/protobuf/util/JsonFormat.java | 40 ++-- .../google/protobuf/util/JsonFormatTest.java | 22 +- js/message_test.js | 46 ++++ js/proto3_test.js | 15 ++ js/test.proto | 1 + .../protobuf/internal/json_format_test.py | 6 +- .../protobuf/internal/python_message.py | 26 ++- .../protobuf/internal/reflection_test.py | 1 + .../protobuf/internal/symbol_database_test.py | 26 ++- python/google/protobuf/pyext/cpp_message.py | 6 +- python/google/protobuf/pyext/map_container.cc | 3 +- python/google/protobuf/pyext/message.cc | 16 +- python/google/protobuf/pyext/message.h | 4 +- .../pyext/repeated_composite_container.cc | 4 +- python/google/protobuf/reflection.py | 8 +- python/google/protobuf/symbol_database.py | 82 +++---- src/google/protobuf/compiler/cpp/cpp_file.cc | 26 +-- .../protobuf/compiler/cpp/cpp_map_field.cc | 205 ++++++++++-------- .../protobuf/compiler/cpp/cpp_map_field.h | 4 + .../protobuf/compiler/cpp/cpp_message.cc | 8 +- .../protobuf/compiler/java/java_file.cc | 18 +- .../protobuf/compiler/java/java_generator.cc | 2 - .../protobuf/compiler/js/js_generator.cc | 24 +- .../compiler/python/python_generator.cc | 60 +++-- .../compiler/python/python_plugin_unittest.cc | 48 ++++ src/google/protobuf/descriptor.proto | 1 + src/google/protobuf/extension_set_heavy.cc | 2 +- src/google/protobuf/generated_message_util.cc | 6 + src/google/protobuf/generated_message_util.h | 6 +- src/google/protobuf/io/coded_stream.cc | 8 +- src/google/protobuf/io/coded_stream.h | 47 ++++ src/google/protobuf/map_entry_lite.h | 26 +++ src/google/protobuf/map_proto2_unittest.proto | 20 ++ src/google/protobuf/map_test.cc | 77 +++++++ src/google/protobuf/map_type_handler.h | 18 +- src/google/protobuf/message.cc | 2 - src/google/protobuf/message.h | 2 +- src/google/protobuf/message_lite.cc | 2 - src/google/protobuf/message_lite.h | 2 +- .../protobuf/testdata/golden_message_maps | Bin 0 -> 13619 bytes src/google/protobuf/text_format.cc | 14 ++ src/google/protobuf/unknown_field_set.cc | 28 +-- src/google/protobuf/unknown_field_set.h | 8 +- .../internal/default_value_objectwriter.cc | 29 ++- .../internal/default_value_objectwriter.h | 12 +- .../default_value_objectwriter_test.cc | 33 +++ .../protobuf/util/internal/proto_writer.cc | 34 ++- .../protobuf/util/internal/proto_writer.h | 9 +- src/google/protobuf/util/json_util.cc | 60 +++++ src/google/protobuf/util/json_util.h | 25 +++ src/google/protobuf/util/json_util_test.cc | 60 +++-- src/google/protobuf/wire_format_lite.cc | 6 +- 59 files changed, 1133 insertions(+), 458 deletions(-) create mode 100644 src/google/protobuf/testdata/golden_message_maps diff --git a/cmake/examples.cmake b/cmake/examples.cmake index 0a6510517f..e5cad63f67 100644 --- a/cmake/examples.cmake +++ b/cmake/examples.cmake @@ -1,57 +1,57 @@ -if(protobuf_VERBOSE) - message(STATUS "Protocol Buffers Examples Configuring...") -endif() - -get_filename_component(examples_dir "../examples" ABSOLUTE) - -if(protobuf_VERBOSE) - message(STATUS "Protocol Buffers Examples Configuring done") -endif() -include(ExternalProject) - -# Internal utility function: Create a custom target representing a build of examples with custom options. -function(add_examples_build NAME) - - ExternalProject_Add(${NAME} - PREFIX ${NAME} - SOURCE_DIR "${examples_dir}" - BINARY_DIR ${NAME} - STAMP_DIR ${NAME}/logs - INSTALL_COMMAND "" #Skip - LOG_CONFIGURE 1 - CMAKE_CACHE_ARGS "-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}" - "-Dprotobuf_VERBOSE:BOOL=${protobuf_VERBOSE}" - ${ARGN} - ) - set_property(TARGET ${NAME} PROPERTY FOLDER "Examples") - set_property(TARGET ${NAME} PROPERTY EXCLUDE_FROM_ALL TRUE) -endfunction() - -# Add examples as an external project. -# sub_directory cannot be used because the find_package(protobuf) call would cause failures with redefined targets. -add_examples_build(examples "-Dprotobuf_DIR:PATH=${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}") -add_dependencies(examples libprotobuf protoc) - -option(protobuf_BUILD_EXAMPLES_MULTITEST "Build Examples in multiple configurations. Useful for testing." OFF) -mark_as_advanced(protobuf_BUILD_EXAMPLES_MULTITEST) -if(protobuf_BUILD_EXAMPLES_MULTITEST) - set_property(GLOBAL PROPERTY USE_FOLDERS ON) - - #Build using the legacy compatibility module. - add_examples_build(examples-legacy - "-Dprotobuf_DIR:PATH=${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}" - "-Dprotobuf_MODULE_COMPATIBLE:BOOL=TRUE" - ) - add_dependencies(examples-legacy libprotobuf protoc) - - #Build using the installed library. - add_examples_build(examples-installed - "-Dprotobuf_DIR:PATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_CMAKEDIR}" - ) - - #Build using the installed library in legacy compatibility mode. - add_examples_build(examples-installed-legacy - "-Dprotobuf_DIR:PATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_CMAKEDIR}" - "-Dprotobuf_MODULE_COMPATIBLE:BOOL=TRUE" - ) -endif() +if(protobuf_VERBOSE) + message(STATUS "Protocol Buffers Examples Configuring...") +endif() + +get_filename_component(examples_dir "../examples" ABSOLUTE) + +if(protobuf_VERBOSE) + message(STATUS "Protocol Buffers Examples Configuring done") +endif() +include(ExternalProject) + +# Internal utility function: Create a custom target representing a build of examples with custom options. +function(add_examples_build NAME) + + ExternalProject_Add(${NAME} + PREFIX ${NAME} + SOURCE_DIR "${examples_dir}" + BINARY_DIR ${NAME} + STAMP_DIR ${NAME}/logs + INSTALL_COMMAND "" #Skip + LOG_CONFIGURE 1 + CMAKE_CACHE_ARGS "-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}" + "-Dprotobuf_VERBOSE:BOOL=${protobuf_VERBOSE}" + ${ARGN} + ) + set_property(TARGET ${NAME} PROPERTY FOLDER "Examples") + set_property(TARGET ${NAME} PROPERTY EXCLUDE_FROM_ALL TRUE) +endfunction() + +# Add examples as an external project. +# sub_directory cannot be used because the find_package(protobuf) call would cause failures with redefined targets. +add_examples_build(examples "-Dprotobuf_DIR:PATH=${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}") +add_dependencies(examples libprotobuf protoc) + +option(protobuf_BUILD_EXAMPLES_MULTITEST "Build Examples in multiple configurations. Useful for testing." OFF) +mark_as_advanced(protobuf_BUILD_EXAMPLES_MULTITEST) +if(protobuf_BUILD_EXAMPLES_MULTITEST) + set_property(GLOBAL PROPERTY USE_FOLDERS ON) + + #Build using the legacy compatibility module. + add_examples_build(examples-legacy + "-Dprotobuf_DIR:PATH=${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}" + "-Dprotobuf_MODULE_COMPATIBLE:BOOL=TRUE" + ) + add_dependencies(examples-legacy libprotobuf protoc) + + #Build using the installed library. + add_examples_build(examples-installed + "-Dprotobuf_DIR:PATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_CMAKEDIR}" + ) + + #Build using the installed library in legacy compatibility mode. + add_examples_build(examples-installed-legacy + "-Dprotobuf_DIR:PATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_CMAKEDIR}" + "-Dprotobuf_MODULE_COMPATIBLE:BOOL=TRUE" + ) +endif() diff --git a/cmake/protobuf-options.cmake b/cmake/protobuf-options.cmake index 99c85ebe67..47fb158257 100644 --- a/cmake/protobuf-options.cmake +++ b/cmake/protobuf-options.cmake @@ -1,7 +1,7 @@ -# Verbose output -option(protobuf_VERBOSE "Enable for verbose output" OFF) -mark_as_advanced(protobuf_VERBOSE) - -# FindProtobuf module compatibel -option(protobuf_MODULE_COMPATIBLE "CMake build-in FindProtobuf.cmake module compatible" OFF) -mark_as_advanced(protobuf_MODULE_COMPATIBLE) +# Verbose output +option(protobuf_VERBOSE "Enable for verbose output" OFF) +mark_as_advanced(protobuf_VERBOSE) + +# FindProtobuf module compatibel +option(protobuf_MODULE_COMPATIBLE "CMake build-in FindProtobuf.cmake module compatible" OFF) +mark_as_advanced(protobuf_MODULE_COMPATIBLE) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index c9d4688530..2cd2acc013 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,63 +1,63 @@ -# Minimum CMake required -cmake_minimum_required(VERSION 2.8.12) - -# Project -project(protobuf-examples) - -# Find required protobuf package -find_package(protobuf CONFIG REQUIRED) - -if(protobuf_VERBOSE) - message(STATUS "Using Protocol Buffers ${Protobuf_VERSION}") -endif() - -set(CMAKE_INCLUDE_CURRENT_DIR TRUE) - -# http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F -if(MSVC AND protobuf_MSVC_STATIC_RUNTIME) - foreach(flag_var - CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE - CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) - if(${flag_var} MATCHES "/MD") - string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") - endif(${flag_var} MATCHES "/MD") - endforeach() -endif() - -foreach(example add_person list_people) - set(${example}_SRCS ${example}.cc) - set(${example}_PROTOS addressbook.proto) - - #Code Generation - if(protobuf_MODULE_COMPATIBLE) #Legacy Support - protobuf_generate_cpp(${example}_PROTO_SRCS ${example}_PROTO_HDRS ${${example}_PROTOS}) - list(APPEND ${example}_SRCS ${${example}_PROTO_SRCS} ${${example}_PROTO_HDRS}) - else() - - foreach(proto_file ${${example}_PROTOS}) - get_filename_component(proto_file_abs ${proto_file} ABSOLUTE) - get_filename_component(basename ${proto_file} NAME_WE) - set(generated_files ${basename}.pb.cc ${basename}.pb.h) - list(APPEND ${example}_SRCS ${generated_files}) - - add_custom_command( - OUTPUT ${generated_files} - COMMAND protobuf::protoc - ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} -I ${CMAKE_CURRENT_SOURCE_DIR} ${proto_file_abs} - COMMENT "Generating ${generated_files} from ${proto_file}" - VERBATIM - ) - endforeach() - endif() - - #Executable setup - set(executable_name ${example}_cpp) - add_executable(${executable_name} ${${example}_SRCS} ${${example}_PROTOS}) - if(protobuf_MODULE_COMPATIBLE) #Legacy mode - target_include_directories(${executable_name} PUBLIC ${PROTOBUF_INCLUDE_DIRS}) - target_link_libraries(${executable_name} ${PROTOBUF_LIBRARIES}) - else() - target_link_libraries(${executable_name} protobuf::libprotobuf) - endif() - -endforeach() +# Minimum CMake required +cmake_minimum_required(VERSION 2.8.12) + +# Project +project(protobuf-examples) + +# Find required protobuf package +find_package(protobuf CONFIG REQUIRED) + +if(protobuf_VERBOSE) + message(STATUS "Using Protocol Buffers ${Protobuf_VERSION}") +endif() + +set(CMAKE_INCLUDE_CURRENT_DIR TRUE) + +# http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F +if(MSVC AND protobuf_MSVC_STATIC_RUNTIME) + foreach(flag_var + CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE + CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) + if(${flag_var} MATCHES "/MD") + string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") + endif(${flag_var} MATCHES "/MD") + endforeach() +endif() + +foreach(example add_person list_people) + set(${example}_SRCS ${example}.cc) + set(${example}_PROTOS addressbook.proto) + + #Code Generation + if(protobuf_MODULE_COMPATIBLE) #Legacy Support + protobuf_generate_cpp(${example}_PROTO_SRCS ${example}_PROTO_HDRS ${${example}_PROTOS}) + list(APPEND ${example}_SRCS ${${example}_PROTO_SRCS} ${${example}_PROTO_HDRS}) + else() + + foreach(proto_file ${${example}_PROTOS}) + get_filename_component(proto_file_abs ${proto_file} ABSOLUTE) + get_filename_component(basename ${proto_file} NAME_WE) + set(generated_files ${basename}.pb.cc ${basename}.pb.h) + list(APPEND ${example}_SRCS ${generated_files}) + + add_custom_command( + OUTPUT ${generated_files} + COMMAND protobuf::protoc + ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} -I ${CMAKE_CURRENT_SOURCE_DIR} ${proto_file_abs} + COMMENT "Generating ${generated_files} from ${proto_file}" + VERBATIM + ) + endforeach() + endif() + + #Executable setup + set(executable_name ${example}_cpp) + add_executable(${executable_name} ${${example}_SRCS} ${${example}_PROTOS}) + if(protobuf_MODULE_COMPATIBLE) #Legacy mode + target_include_directories(${executable_name} PUBLIC ${PROTOBUF_INCLUDE_DIRS}) + target_link_libraries(${executable_name} ${PROTOBUF_LIBRARIES}) + else() + target_link_libraries(${executable_name} protobuf::libprotobuf) + endif() + +endforeach() diff --git a/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java b/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java index 576a350f4e..4f5a9b770e 100644 --- a/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java +++ b/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java @@ -144,6 +144,44 @@ public abstract class CodedOutputStream extends ByteOutput { return new NioEncoder(byteBuffer); } + /** + * Configures serialization to be deterministic. + * + *

The deterministic serialization guarantees that for a given binary, equal (defined by the + * {@code equals()} methods in protos) messages will always be serialized to the same bytes. This + * implies: + * + *

+ * + *

Note the deterministic serialization is NOT canonical across languages; it is also unstable + * across different builds with schema changes due to unknown fields. Users who need canonical + * serialization, e.g. persistent storage in a canonical form, fingerprinting, etc, should define + * their own canonicalization specification and implement the serializer using reflection APIs + * rather than relying on this API. + * + *

Once set, the serializer will: (Note this is an implementation detail and may subject to + * change in the future) + * + *

+ */ + public final void useDeterministicSerialization() { + serializationDeterministic = true; + } + + boolean isSerializationDeterministic() { + return serializationDeterministic; + } + private boolean serializationDeterministic; + /** * Create a new {@code CodedOutputStream} that writes to the given {@link ByteBuffer}. * diff --git a/java/core/src/main/java/com/google/protobuf/DynamicMessage.java b/java/core/src/main/java/com/google/protobuf/DynamicMessage.java index 859a9e8fc5..c54da67fbb 100644 --- a/java/core/src/main/java/com/google/protobuf/DynamicMessage.java +++ b/java/core/src/main/java/com/google/protobuf/DynamicMessage.java @@ -526,6 +526,14 @@ public final class DynamicMessage extends AbstractMessage { fields.clearField(oldField); } oneofCases[index] = field; + } else if (field.getFile().getSyntax() == Descriptors.FileDescriptor.Syntax.PROTO3) { + if (!field.isRepeated() + && field.getJavaType() != FieldDescriptor.JavaType.MESSAGE + && value.equals(field.getDefaultValue())) { + // In proto3, setting a field to its default value is equivalent to clearing the field. + fields.clearField(field); + return this; + } } fields.setField(field, value); return this; diff --git a/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java b/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java index 82f4216b76..4a42c8970e 100644 --- a/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java +++ b/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java @@ -31,6 +31,8 @@ package com.google.protobuf; import com.google.protobuf.Descriptors.Descriptor; +import com.google.protobuf.Descriptors.EnumDescriptor; +import com.google.protobuf.Descriptors.EnumValueDescriptor; import com.google.protobuf.Descriptors.FieldDescriptor; import com.google.protobuf.FieldPresenceTestProto.TestAllTypes; import com.google.protobuf.FieldPresenceTestProto.TestOptionalFieldsOnly; @@ -253,6 +255,54 @@ public class FieldPresenceTest extends TestCase { assertEquals(4, message.getAllFields().size()); } + public void testFieldPresenceDynamicMessage() { + Descriptor descriptor = TestAllTypes.getDescriptor(); + FieldDescriptor optionalInt32Field = descriptor.findFieldByName("optional_int32"); + FieldDescriptor optionalStringField = descriptor.findFieldByName("optional_string"); + FieldDescriptor optionalBytesField = descriptor.findFieldByName("optional_bytes"); + FieldDescriptor optionalNestedEnumField = descriptor.findFieldByName("optional_nested_enum"); + EnumDescriptor enumDescriptor = optionalNestedEnumField.getEnumType(); + EnumValueDescriptor defaultEnumValueDescriptor = enumDescriptor.getValues().get(0); + EnumValueDescriptor nonDefaultEnumValueDescriptor = enumDescriptor.getValues().get(1); + + DynamicMessage defaultInstance = DynamicMessage.getDefaultInstance(descriptor); + // Field not present. + DynamicMessage message = defaultInstance.newBuilderForType().build(); + assertFalse(message.hasField(optionalInt32Field)); + assertFalse(message.hasField(optionalStringField)); + assertFalse(message.hasField(optionalBytesField)); + assertFalse(message.hasField(optionalNestedEnumField)); + assertEquals(0, message.getAllFields().size()); + + // Field set to non-default value is seen as present. + message = + defaultInstance + .newBuilderForType() + .setField(optionalInt32Field, 1) + .setField(optionalStringField, "x") + .setField(optionalBytesField, ByteString.copyFromUtf8("y")) + .setField(optionalNestedEnumField, nonDefaultEnumValueDescriptor) + .build(); + assertTrue(message.hasField(optionalInt32Field)); + assertTrue(message.hasField(optionalStringField)); + assertTrue(message.hasField(optionalBytesField)); + assertTrue(message.hasField(optionalNestedEnumField)); + assertEquals(4, message.getAllFields().size()); + + // Field set to default value is seen as not present. + message = message.toBuilder() + .setField(optionalInt32Field, 0) + .setField(optionalStringField, "") + .setField(optionalBytesField, ByteString.EMPTY) + .setField(optionalNestedEnumField, defaultEnumValueDescriptor) + .build(); + assertFalse(message.hasField(optionalInt32Field)); + assertFalse(message.hasField(optionalStringField)); + assertFalse(message.hasField(optionalBytesField)); + assertFalse(message.hasField(optionalNestedEnumField)); + assertEquals(0, message.getAllFields().size()); + } + public void testMessageField() { TestAllTypes.Builder builder = TestAllTypes.newBuilder(); assertFalse(builder.hasOptionalNestedMessage()); diff --git a/java/core/src/test/java/com/google/protobuf/LazyStringArrayListTest.java b/java/core/src/test/java/com/google/protobuf/LazyStringArrayListTest.java index 0f42ac5060..497c4df28e 100644 --- a/java/core/src/test/java/com/google/protobuf/LazyStringArrayListTest.java +++ b/java/core/src/test/java/com/google/protobuf/LazyStringArrayListTest.java @@ -35,6 +35,7 @@ import static java.util.Arrays.asList; import junit.framework.TestCase; import java.util.ArrayList; +import java.util.Collections; import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.List; @@ -233,7 +234,7 @@ public class LazyStringArrayListTest extends TestCase { } try { - list.addAllByteArray(asList(BYTE_STRING_A.toByteArray())); + list.addAllByteArray(Collections.singletonList(BYTE_STRING_A.toByteArray())); fail(); } catch (UnsupportedOperationException e) { // expected diff --git a/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java b/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java index 297545e52a..ad50cc0ea8 100644 --- a/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java +++ b/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java @@ -116,7 +116,8 @@ public class JsonFormat { private Printer( TypeRegistry registry, boolean includingDefaultValueFields, - boolean preservingProtoFieldNames, boolean omittingInsignificantWhitespace) { + boolean preservingProtoFieldNames, + boolean omittingInsignificantWhitespace) { this.registry = registry; this.includingDefaultValueFields = includingDefaultValueFields; this.preservingProtoFieldNames = preservingProtoFieldNames; @@ -133,7 +134,11 @@ public class JsonFormat { if (this.registry != TypeRegistry.getEmptyTypeRegistry()) { throw new IllegalArgumentException("Only one registry is allowed."); } - return new Printer(registry, includingDefaultValueFields, preservingProtoFieldNames, omittingInsignificantWhitespace); + return new Printer( + registry, + includingDefaultValueFields, + preservingProtoFieldNames, + omittingInsignificantWhitespace); } /** @@ -143,7 +148,8 @@ public class JsonFormat { * {@link Printer}. */ public Printer includingDefaultValueFields() { - return new Printer(registry, true, preservingProtoFieldNames, omittingInsignificantWhitespace); + return new Printer( + registry, true, preservingProtoFieldNames, omittingInsignificantWhitespace); } /** @@ -153,7 +159,8 @@ public class JsonFormat { * current {@link Printer}. */ public Printer preservingProtoFieldNames() { - return new Printer(registry, includingDefaultValueFields, true, omittingInsignificantWhitespace); + return new Printer( + registry, includingDefaultValueFields, true, omittingInsignificantWhitespace); } @@ -172,7 +179,7 @@ public class JsonFormat { * See https://tools.ietf.org/html/rfc7159 * current {@link Printer}. */ - public Printer omittingInsignificantWhitespace(){ + public Printer omittingInsignificantWhitespace() { return new Printer(registry, includingDefaultValueFields, preservingProtoFieldNames, true); } @@ -186,7 +193,12 @@ public class JsonFormat { public void appendTo(MessageOrBuilder message, Appendable output) throws IOException { // TODO(xiaofeng): Investigate the allocation overhead and optimize for // mobile. - new PrinterImpl(registry, includingDefaultValueFields, preservingProtoFieldNames, output, omittingInsignificantWhitespace) + new PrinterImpl( + registry, + includingDefaultValueFields, + preservingProtoFieldNames, + output, + omittingInsignificantWhitespace) .print(message); } @@ -379,18 +391,18 @@ public class JsonFormat { */ interface TextGenerator { void indent(); + void outdent(); + void print(final CharSequence text) throws IOException; } - /** * Format the json without indentation */ - private static final class CompactTextGenerator implements TextGenerator{ + private static final class CompactTextGenerator implements TextGenerator { private final Appendable output; - private CompactTextGenerator(final Appendable output) { this.output = output; } @@ -411,12 +423,11 @@ public class JsonFormat { public void print(final CharSequence text) throws IOException { output.append(text); } - } /** * A TextGenerator adds indentation when writing formatted text. */ - private static final class PrettyTextGenerator implements TextGenerator{ + private static final class PrettyTextGenerator implements TextGenerator { private final Appendable output; private final StringBuilder indent = new StringBuilder(); private boolean atStartOfLine = true; @@ -496,7 +507,8 @@ public class JsonFormat { TypeRegistry registry, boolean includingDefaultValueFields, boolean preservingProtoFieldNames, - Appendable jsonOutput, boolean omittingInsignificantWhitespace) { + Appendable jsonOutput, + boolean omittingInsignificantWhitespace) { this.registry = registry; this.includingDefaultValueFields = includingDefaultValueFields; this.preservingProtoFieldNames = preservingProtoFieldNames; @@ -734,9 +746,7 @@ public class JsonFormat { } /** Prints a regular message with an optional type URL. */ - - private void print(MessageOrBuilder message, String typeUrl) - throws IOException { + private void print(MessageOrBuilder message, String typeUrl) throws IOException { generator.print("{" + blankOrNewLine); generator.indent(); diff --git a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java index e68c7be122..6fc784efbf 100644 --- a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java +++ b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java @@ -140,7 +140,7 @@ public class JsonFormatTest extends TestCase { private String toJsonString(Message message) throws IOException { return JsonFormat.printer().print(message); } - private String toCompactJsonString(Message message) throws IOException{ + private String toCompactJsonString(Message message) throws IOException { return JsonFormat.printer().omittingInsignificantWhitespace().print(message); } @@ -1172,7 +1172,9 @@ public class JsonFormatTest extends TestCase { public void testOmittingInsignificantWhiteSpace() throws Exception { TestAllTypes message = TestAllTypes.newBuilder().setOptionalInt32(12345).build(); - assertEquals("{" + "\"optionalInt32\":12345" + "}", JsonFormat.printer().omittingInsignificantWhitespace().print(message)); + assertEquals( + "{" + "\"optionalInt32\":12345" + "}", + JsonFormat.printer().omittingInsignificantWhitespace().print(message)); TestAllTypes message1 = TestAllTypes.getDefaultInstance(); assertEquals("{}", JsonFormat.printer().omittingInsignificantWhitespace().print(message1)); TestAllTypes.Builder builder = TestAllTypes.newBuilder(); @@ -1224,4 +1226,20 @@ public class JsonFormatTest extends TestCase { toCompactJsonString(message2)); } + // Regression test for b/29892357 + public void testEmptyWrapperTypesInAny() throws Exception { + JsonFormat.TypeRegistry registry = + JsonFormat.TypeRegistry.newBuilder().add(TestAllTypes.getDescriptor()).build(); + JsonFormat.Parser parser = JsonFormat.parser().usingTypeRegistry(registry); + + Any.Builder builder = Any.newBuilder(); + parser.merge( + "{\n" + + " \"@type\": \"type.googleapis.com/google.protobuf.BoolValue\",\n" + + " \"value\": false\n" + + "}\n", + builder); + Any any = builder.build(); + assertEquals(0, any.getValue().size()); + } } diff --git a/js/message_test.js b/js/message_test.js index 0b0c01720c..11792423e4 100644 --- a/js/message_test.js +++ b/js/message_test.js @@ -215,6 +215,10 @@ describe('Message test suite', function() { 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]); @@ -222,6 +226,10 @@ describe('Message test suite', function() { 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]); @@ -229,6 +237,10 @@ describe('Message test suite', function() { 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]); @@ -238,6 +250,10 @@ describe('Message test suite', function() { 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]); @@ -247,6 +263,10 @@ describe('Message test suite', function() { 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() { @@ -269,6 +289,8 @@ describe('Message test suite', function() { assertUndefined(foo.getAString()); assertUndefined(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, @@ -291,6 +313,8 @@ describe('Message test suite', function() { assertNull(foo.getAString()); assertNull(foo.getABool()); assertNull(foo.getANestedMessage()); + assertFalse(foo.hasAString()); + assertFalse(foo.hasABool()); assertObjectEquals([], foo.getARepeatedMessageList()); assertObjectEquals([], foo.getARepeatedStringList()); assertObjectEquals([null, null, null, [], []], foo.toArray()); @@ -307,6 +331,8 @@ describe('Message test suite', function() { assertUndefined(foo.getAString()); assertUndefined(foo.getABool()); assertUndefined(foo.getANestedMessage()); + assertFalse(foo.hasAString()); + assertFalse(foo.hasABool()); assertObjectEquals([], foo.getARepeatedMessageList()); assertObjectEquals([], foo.getARepeatedStringList()); expected = [,,, [], []]; @@ -800,14 +826,20 @@ describe('Message test suite', function() { var message = new proto.jspb.test.TestMessageWithOneof; assertUndefined(message.getPone()); assertUndefined(message.getPthree()); + assertFalse(message.hasPone()); + assertFalse(message.hasPthree()); message.setPone('hi'); assertEquals('hi', message.getPone()); assertUndefined(message.getPthree()); + assertTrue(message.hasPone()); + assertFalse(message.hasPthree()); message.setPthree('bye'); assertUndefined(message.getPone()); assertEquals('bye', message.getPthree()); + assertFalse(message.hasPone()); + assertTrue(message.hasPthree()); }); it('testSettingOneofFieldDoesNotClearFieldsFromOtherUnions', function() { @@ -816,17 +848,23 @@ describe('Message test suite', function() { assertUndefined(message.getPone()); assertUndefined(message.getPthree()); assertUndefined(message.getRone()); + assertFalse(message.hasPone()); + assertFalse(message.hasPthree()); message.setPone('hi'); message.setRone(other); assertEquals('hi', message.getPone()); assertUndefined(message.getPthree()); assertEquals(other, message.getRone()); + assertTrue(message.hasPone()); + assertFalse(message.hasPthree()); message.setPthree('bye'); assertUndefined(message.getPone()); assertEquals('bye', message.getPthree()); assertEquals(other, message.getRone()); + assertFalse(message.hasPone()); + assertTrue(message.hasPthree()); }); it('testUnsetsOneofCaseWhenFieldIsCleared', function() { @@ -884,6 +922,8 @@ describe('Message test suite', function() { var message = new proto.jspb.test.TestMessageWithOneof; assertUndefined(message.getBone()); assertEquals(1234, message.getBtwo()); + assertFalse(message.hasBone()); + assertFalse(message.hasBtwo()); assertEquals( proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase .DEFAULT_ONEOF_B_NOT_SET, @@ -892,12 +932,16 @@ describe('Message test suite', function() { 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); assertUndefined(message.getBone()); + assertFalse(message.hasBone()); + assertTrue(message.hasBtwo()); assertEquals(3, message.getBtwo()); assertEquals( proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO, @@ -905,6 +949,8 @@ describe('Message test suite', function() { message.clearBtwo(); assertUndefined(message.getBone()); + assertFalse(message.hasBone()); + assertFalse(message.hasBtwo()); assertEquals(1234, message.getBtwo()); assertEquals( proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase diff --git a/js/proto3_test.js b/js/proto3_test.js index 4dd7790f16..7f76006a78 100644 --- a/js/proto3_test.js +++ b/js/proto3_test.js @@ -225,12 +225,18 @@ describe('proto3Test', function() { assertEquals(msg.getOneofForeignMessage(), undefined); assertEquals(msg.getOneofString(), undefined); assertEquals(msg.getOneofBytes(), undefined); + assertFalse(msg.hasOneofUint32()); + assertFalse(msg.hasOneofString()); + assertFalse(msg.hasOneofBytes()); msg.setOneofUint32(42); assertEquals(msg.getOneofUint32(), 42); assertEquals(msg.getOneofForeignMessage(), undefined); assertEquals(msg.getOneofString(), undefined); assertEquals(msg.getOneofBytes(), undefined); + assertTrue(msg.hasOneofUint32()); + assertFalse(msg.hasOneofString()); + assertFalse(msg.hasOneofBytes()); var submsg = new proto.jspb.test.ForeignMessage(); @@ -239,12 +245,18 @@ describe('proto3Test', function() { assertEquals(msg.getOneofForeignMessage(), submsg); assertEquals(msg.getOneofString(), undefined); assertEquals(msg.getOneofBytes(), undefined); + assertFalse(msg.hasOneofUint32()); + assertFalse(msg.hasOneofString()); + assertFalse(msg.hasOneofBytes()); msg.setOneofString('hello'); assertEquals(msg.getOneofUint32(), undefined); assertEquals(msg.getOneofForeignMessage(), undefined); assertEquals(msg.getOneofString(), 'hello'); assertEquals(msg.getOneofBytes(), undefined); + assertFalse(msg.hasOneofUint32()); + assertTrue(msg.hasOneofString()); + assertFalse(msg.hasOneofBytes()); msg.setOneofBytes(goog.crypt.base64.encodeString('\u00FF\u00FF')); assertEquals(msg.getOneofUint32(), undefined); @@ -252,6 +264,9 @@ describe('proto3Test', function() { assertEquals(msg.getOneofString(), undefined); assertEquals(msg.getOneofBytes_asB64(), goog.crypt.base64.encodeString('\u00FF\u00FF')); + assertFalse(msg.hasOneofUint32()); + assertFalse(msg.hasOneofString()); + assertTrue(msg.hasOneofBytes()); }); diff --git a/js/test.proto b/js/test.proto index cf2eafef6e..937ffb89ce 100644 --- a/js/test.proto +++ b/js/test.proto @@ -233,3 +233,4 @@ message TestEndsWithBytes { optional int32 value = 1; optional bytes data = 2; } + diff --git a/python/google/protobuf/internal/json_format_test.py b/python/google/protobuf/internal/json_format_test.py index 6df12bea43..a5ee8ace0e 100644 --- a/python/google/protobuf/internal/json_format_test.py +++ b/python/google/protobuf/internal/json_format_test.py @@ -252,10 +252,7 @@ class JsonFormatTest(JsonFormatBase): message = json_format_proto3_pb2.TestMessage() json_format.Parse('{"stringValue": "\\uD83D\\uDE01"}', message) self.assertEqual(message.string_value, - b'\xF0\x9F\x98\x81'.decode("utf-8", "strict")) - - # TODO: add test that UTF-8 encoded surrogate code points are rejected. - # UTF-8 does not allow them. + b'\xF0\x9F\x98\x81'.decode('utf-8', 'strict')) # Error case: unpaired high surrogate. self.CheckError( @@ -267,7 +264,6 @@ class JsonFormatTest(JsonFormatBase): '{"stringValue": "\\uDE01"}', r'Invalid \\uXXXX escape|Unpaired.*surrogate') - def testTimestampMessage(self): message = json_format_proto3_pb2.TestTimestamp() message.value.seconds = 0 diff --git a/python/google/protobuf/internal/python_message.py b/python/google/protobuf/internal/python_message.py index f8f73dd204..c0d0ad451f 100755 --- a/python/google/protobuf/internal/python_message.py +++ b/python/google/protobuf/internal/python_message.py @@ -76,7 +76,6 @@ from google.protobuf.internal import well_known_types from google.protobuf.internal import wire_format from google.protobuf import descriptor as descriptor_mod from google.protobuf import message as message_mod -from google.protobuf import symbol_database from google.protobuf import text_format _FieldDescriptor = descriptor_mod.FieldDescriptor @@ -98,16 +97,12 @@ class GeneratedProtocolMessageType(type): classes at runtime, as in this example: mydescriptor = Descriptor(.....) - class MyProtoClass(Message): - __metaclass__ = GeneratedProtocolMessageType - DESCRIPTOR = mydescriptor + factory = symbol_database.Default() + factory.pool.AddDescriptor(mydescriptor) + MyProtoClass = factory.GetPrototype(mydescriptor) myproto_instance = MyProtoClass() myproto.foo_field = 23 ... - - The above example will not work for nested types. If you wish to include them, - use reflection.MakeClass() instead of manually instantiating the class in - order to create the appropriate class structure. """ # Must be consistent with the protocol-compiler code in @@ -926,26 +921,33 @@ def _InternalUnpackAny(msg): Returns: The unpacked message. """ + # TODO(amauryfa): Don't use the factory of generated messages. + # To make Any work with custom factories, use the message factory of the + # parent message. + # pylint: disable=g-import-not-at-top + from google.protobuf import symbol_database + factory = symbol_database.Default() + type_url = msg.type_url - db = symbol_database.Default() if not type_url: return None # TODO(haberman): For now we just strip the hostname. Better logic will be # required. - type_name = type_url.split("/")[-1] - descriptor = db.pool.FindMessageTypeByName(type_name) + type_name = type_url.split('/')[-1] + descriptor = factory.pool.FindMessageTypeByName(type_name) if descriptor is None: return None - message_class = db.GetPrototype(descriptor) + message_class = factory.GetPrototype(descriptor) message = message_class() message.ParseFromString(msg.value) return message + def _AddEqualsMethod(message_descriptor, cls): """Helper for _AddMessageMethods().""" def __eq__(self, other): diff --git a/python/google/protobuf/internal/reflection_test.py b/python/google/protobuf/internal/reflection_test.py index 6dc2fffe2b..20e5d245d3 100755 --- a/python/google/protobuf/internal/reflection_test.py +++ b/python/google/protobuf/internal/reflection_test.py @@ -972,6 +972,7 @@ class ReflectionTest(unittest.TestCase): proto.repeated_nested_message.add(bb=23) self.assertEqual(1, len(proto.repeated_nested_message)) self.assertEqual(23, proto.repeated_nested_message[0].bb) + self.assertRaises(TypeError, proto.repeated_nested_message.add, 23) def testRepeatedCompositeRemove(self): proto = unittest_pb2.TestAllTypes() diff --git a/python/google/protobuf/internal/symbol_database_test.py b/python/google/protobuf/internal/symbol_database_test.py index c99b426dc4..4f5173b2a2 100644 --- a/python/google/protobuf/internal/symbol_database_test.py +++ b/python/google/protobuf/internal/symbol_database_test.py @@ -39,26 +39,28 @@ except ImportError: from google.protobuf import unittest_pb2 from google.protobuf import descriptor +from google.protobuf import descriptor_pool from google.protobuf import symbol_database + class SymbolDatabaseTest(unittest.TestCase): def _Database(self): - # TODO(b/17734095): Remove this difference when the C++ implementation - # supports multiple databases. if descriptor._USE_C_DESCRIPTORS: - return symbol_database.Default() + # The C++ implementation does not allow mixing descriptors from + # different pools. + db = symbol_database.SymbolDatabase(pool=descriptor_pool.Default()) else: db = symbol_database.SymbolDatabase() - # Register representative types from unittest_pb2. - db.RegisterFileDescriptor(unittest_pb2.DESCRIPTOR) - db.RegisterMessage(unittest_pb2.TestAllTypes) - db.RegisterMessage(unittest_pb2.TestAllTypes.NestedMessage) - db.RegisterMessage(unittest_pb2.TestAllTypes.OptionalGroup) - db.RegisterMessage(unittest_pb2.TestAllTypes.RepeatedGroup) - db.RegisterEnumDescriptor(unittest_pb2.ForeignEnum.DESCRIPTOR) - db.RegisterEnumDescriptor(unittest_pb2.TestAllTypes.NestedEnum.DESCRIPTOR) - return db + # Register representative types from unittest_pb2. + db.RegisterFileDescriptor(unittest_pb2.DESCRIPTOR) + db.RegisterMessage(unittest_pb2.TestAllTypes) + db.RegisterMessage(unittest_pb2.TestAllTypes.NestedMessage) + db.RegisterMessage(unittest_pb2.TestAllTypes.OptionalGroup) + db.RegisterMessage(unittest_pb2.TestAllTypes.RepeatedGroup) + db.RegisterEnumDescriptor(unittest_pb2.ForeignEnum.DESCRIPTOR) + db.RegisterEnumDescriptor(unittest_pb2.TestAllTypes.NestedEnum.DESCRIPTOR) + return db def testGetPrototype(self): instance = self._Database().GetPrototype( diff --git a/python/google/protobuf/pyext/cpp_message.py b/python/google/protobuf/pyext/cpp_message.py index b215211ee5..fc8eb32d79 100644 --- a/python/google/protobuf/pyext/cpp_message.py +++ b/python/google/protobuf/pyext/cpp_message.py @@ -48,9 +48,9 @@ class GeneratedProtocolMessageType(_message.MessageMeta): classes at runtime, as in this example: mydescriptor = Descriptor(.....) - class MyProtoClass(Message): - __metaclass__ = GeneratedProtocolMessageType - DESCRIPTOR = mydescriptor + factory = symbol_database.Default() + factory.pool.AddDescriptor(mydescriptor) + MyProtoClass = factory.GetPrototype(mydescriptor) myproto_instance = MyProtoClass() myproto.foo_field = 23 ... diff --git a/python/google/protobuf/pyext/map_container.cc b/python/google/protobuf/pyext/map_container.cc index 90438df17e..0987b89832 100644 --- a/python/google/protobuf/pyext/map_container.cc +++ b/python/google/protobuf/pyext/map_container.cc @@ -348,9 +348,10 @@ PyObject* MapReflectionFriend::Contains(PyObject* _self, PyObject* key) { } // Initializes the underlying Message object of "to" so it becomes a new parent -// repeated scalar, and copies all the values from "from" to it. A child scalar +// map container, and copies all the values from "from" to it. A child map // container can be released by passing it as both from and to (e.g. making it // the recipient of the new parent message and copying the values from itself). +// In fact, this is the only supported use at the moment. static int InitializeAndCopyToParentContainer(MapContainer* from, MapContainer* to) { // For now we require from == to, re-evaluate if we want to support deep copy diff --git a/python/google/protobuf/pyext/message.cc b/python/google/protobuf/pyext/message.cc index a9261f20cc..5535338d44 100644 --- a/python/google/protobuf/pyext/message.cc +++ b/python/google/protobuf/pyext/message.cc @@ -1041,7 +1041,12 @@ int InternalDeleteRepeatedField( } // Initializes fields of a message. Used in constructors. -int InitAttributes(CMessage* self, PyObject* kwargs) { +int InitAttributes(CMessage* self, PyObject* args, PyObject* kwargs) { + if (args != NULL && PyTuple_Size(args) != 0) { + PyErr_SetString(PyExc_TypeError, "No positional arguments allowed"); + return -1; + } + if (kwargs == NULL) { return 0; } @@ -1167,7 +1172,7 @@ int InitAttributes(CMessage* self, PyObject* kwargs) { } CMessage* cmessage = reinterpret_cast(message.get()); if (PyDict_Check(value)) { - if (InitAttributes(cmessage, value) < 0) { + if (InitAttributes(cmessage, NULL, value) < 0) { return -1; } } else { @@ -1245,12 +1250,7 @@ static PyObject* New(PyTypeObject* cls, // The __init__ method of Message classes. // It initializes fields from keywords passed to the constructor. static int Init(CMessage* self, PyObject* args, PyObject* kwargs) { - if (PyTuple_Size(args) != 0) { - PyErr_SetString(PyExc_TypeError, "No positional arguments allowed"); - return -1; - } - - return InitAttributes(self, kwargs); + return InitAttributes(self, args, kwargs); } // --------------------------------------------------------------------- diff --git a/python/google/protobuf/pyext/message.h b/python/google/protobuf/pyext/message.h index 8b399e05ce..c44a2ae2b7 100644 --- a/python/google/protobuf/pyext/message.h +++ b/python/google/protobuf/pyext/message.h @@ -237,7 +237,9 @@ PyObject* HasFieldByDescriptor( PyObject* HasField(CMessage* self, PyObject* arg); // Initializes values of fields on a newly constructed message. -int InitAttributes(CMessage* self, PyObject* kwargs); +// Note that positional arguments are disallowed: 'args' must be NULL or the +// empty tuple. +int InitAttributes(CMessage* self, PyObject* args, PyObject* kwargs); PyObject* MergeFrom(CMessage* self, PyObject* arg); diff --git a/python/google/protobuf/pyext/repeated_composite_container.cc b/python/google/protobuf/pyext/repeated_composite_container.cc index 4f339e7723..bb2f6db287 100644 --- a/python/google/protobuf/pyext/repeated_composite_container.cc +++ b/python/google/protobuf/pyext/repeated_composite_container.cc @@ -146,7 +146,7 @@ static PyObject* AddToAttached(RepeatedCompositeContainer* self, cmsg->owner = self->owner; cmsg->message = sub_message; cmsg->parent = self->parent; - if (cmessage::InitAttributes(cmsg, kwargs) < 0) { + if (cmessage::InitAttributes(cmsg, args, kwargs) < 0) { Py_DECREF(cmsg); return NULL; } @@ -166,7 +166,7 @@ static PyObject* AddToReleased(RepeatedCompositeContainer* self, // Create a new Message detached from the rest. PyObject* py_cmsg = PyEval_CallObjectWithKeywords( - self->child_message_class->AsPyObject(), NULL, kwargs); + self->child_message_class->AsPyObject(), args, kwargs); if (py_cmsg == NULL) return NULL; diff --git a/python/google/protobuf/reflection.py b/python/google/protobuf/reflection.py index 0c757264f4..51c8332120 100755 --- a/python/google/protobuf/reflection.py +++ b/python/google/protobuf/reflection.py @@ -58,13 +58,7 @@ else: from google.protobuf.internal import python_message as message_impl # The type of all Message classes. -# Part of the public interface. -# -# Used by generated files, but clients can also use it at runtime: -# mydescriptor = pool.FindDescriptor(.....) -# class MyProtoClass(Message): -# __metaclass__ = GeneratedProtocolMessageType -# DESCRIPTOR = mydescriptor +# Part of the public interface, but normally only used by message factories. GeneratedProtocolMessageType = message_impl.GeneratedProtocolMessageType diff --git a/python/google/protobuf/symbol_database.py b/python/google/protobuf/symbol_database.py index 87760f2630..aa466abd26 100644 --- a/python/google/protobuf/symbol_database.py +++ b/python/google/protobuf/symbol_database.py @@ -30,11 +30,9 @@ """A database of Python protocol buffer generated symbols. -SymbolDatabase makes it easy to create new instances of a registered type, given -only the type's protocol buffer symbol name. Once all symbols are registered, -they can be accessed using either the MessageFactory interface which -SymbolDatabase exposes, or the DescriptorPool interface of the underlying -pool. +SymbolDatabase is the MessageFactory for messages generated at compile time, +and makes it easy to create new instances of a registered type, given only the +type's protocol buffer symbol name. Example usage: @@ -61,27 +59,17 @@ Example usage: from google.protobuf import descriptor_pool +from google.protobuf import message_factory -class SymbolDatabase(object): - """A database of Python generated symbols. - - SymbolDatabase also models message_factory.MessageFactory. - - The symbol database can be used to keep a global registry of all protocol - buffer types used within a program. - """ - - def __init__(self, pool=None): - """Constructor.""" - - self._symbols = {} - self._symbols_by_file = {} - self.pool = pool or descriptor_pool.Default() +class SymbolDatabase(message_factory.MessageFactory): + """A database of Python generated symbols.""" def RegisterMessage(self, message): """Registers the given message type in the local database. + Calls to GetSymbol() and GetMessages() will return messages registered here. + Args: message: a message.Message, to be registered. @@ -90,10 +78,7 @@ class SymbolDatabase(object): """ desc = message.DESCRIPTOR - self._symbols[desc.full_name] = message - if desc.file.name not in self._symbols_by_file: - self._symbols_by_file[desc.file.name] = {} - self._symbols_by_file[desc.file.name][desc.full_name] = message + self._classes[desc.full_name] = message self.pool.AddDescriptor(desc) return message @@ -136,47 +121,46 @@ class SymbolDatabase(object): KeyError: if the symbol could not be found. """ - return self._symbols[symbol] - - def GetPrototype(self, descriptor): - """Builds a proto2 message class based on the passed in descriptor. - - Passing a descriptor with a fully qualified name matching a previous - invocation will cause the same class to be returned. - - Args: - descriptor: The descriptor to build from. - - Returns: - A class describing the passed in descriptor. - """ - - return self.GetSymbol(descriptor.full_name) + return self._classes[symbol] def GetMessages(self, files): - """Gets all the messages from a specified file. - - This will find and resolve dependencies, failing if they are not registered - in the symbol database. + # TODO(amauryfa): Fix the differences with MessageFactory. + """Gets all registered messages from a specified file. + Only messages already created and registered will be returned; (this is the + case for imported _pb2 modules) + But unlike MessageFactory, this version also returns nested messages. Args: files: The file names to extract messages from. Returns: - A dictionary mapping proto names to the message classes. This will include - any dependent messages as well as any messages defined in the same file as - a specified message. + A dictionary mapping proto names to the message classes. Raises: KeyError: if a file could not be found. """ + def _GetAllMessageNames(desc): + """Walk a message Descriptor and recursively yields all message names.""" + yield desc.full_name + for msg_desc in desc.nested_types: + for full_name in _GetAllMessageNames(msg_desc): + yield full_name + result = {} - for f in files: - result.update(self._symbols_by_file[f]) + for file_name in files: + file_desc = self.pool.FindFileByName(file_name) + for msg_desc in file_desc.message_types_by_name.values(): + for full_name in _GetAllMessageNames(msg_desc): + try: + result[full_name] = self._classes[full_name] + except KeyError: + # This descriptor has no registered class, skip it. + pass return result + _DEFAULT = SymbolDatabase(pool=descriptor_pool.Default()) diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc index 385b973ea0..b3eca660d3 100644 --- a/src/google/protobuf/compiler/cpp/cpp_file.cc +++ b/src/google/protobuf/compiler/cpp/cpp_file.cc @@ -336,19 +336,6 @@ void FileGenerator::GenerateSource(io::Printer* printer) { // Generate classes. for (int i = 0; i < file_->message_type_count(); i++) { - if (i == 0 && HasGeneratedMethods(file_, options_)) { - printer->Print( - "\n" - "namespace {\n" - "\n" - "static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD;\n" - "static void MergeFromFail(int line) {\n" - " GOOGLE_CHECK(false) << __FILE__ << \":\" << line;\n" - "}\n" - "\n" - "} // namespace\n" - "\n"); - } printer->Print("\n"); printer->Print(kThickSeparator); printer->Print("\n"); @@ -464,9 +451,10 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { // and we only use AddDescriptors() to allocate default instances. if (HasDescriptorMethods(file_, options_)) { printer->Print( - "\n" - "void $assigndescriptorsname$() {\n", - "assigndescriptorsname", GlobalAssignDescriptorsName(file_->name())); + "\n" + "void $assigndescriptorsname$() GOOGLE_ATTRIBUTE_COLD;\n" + "void $assigndescriptorsname$() {\n", + "assigndescriptorsname", GlobalAssignDescriptorsName(file_->name())); printer->Indent(); // Make sure the file has found its way into the pool. If a descriptor @@ -525,8 +513,9 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { // protobuf_RegisterTypes(): Calls // MessageFactory::InternalRegisterGeneratedType() for each message type. printer->Print( - "void protobuf_RegisterTypes(const ::std::string&) {\n" - " protobuf_AssignDescriptorsOnce();\n"); + "void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD;\n" + "void protobuf_RegisterTypes(const ::std::string&) {\n" + " protobuf_AssignDescriptorsOnce();\n"); printer->Indent(); for (int i = 0; i < file_->message_type_count(); i++) { @@ -566,6 +555,7 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { // Note that we don't need any special synchronization in the following // code // because it is called at static init time before any threads exist. + "void $adddescriptorsname$() GOOGLE_ATTRIBUTE_COLD;\n" "void $adddescriptorsname$() {\n" " static bool already_here = false;\n" " if (already_here) return;\n" diff --git a/src/google/protobuf/compiler/cpp/cpp_map_field.cc b/src/google/protobuf/compiler/cpp/cpp_map_field.cc index dd9f18872b..0588e34ecd 100644 --- a/src/google/protobuf/compiler/cpp/cpp_map_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_map_field.cc @@ -251,117 +251,148 @@ GenerateMergeFromCodedStream(io::Printer* printer) const { } } -void MapFieldGenerator:: -GenerateSerializeWithCachedSizes(io::Printer* printer) const { - printer->Print(variables_, - "{\n" - " ::google::protobuf::scoped_ptr<$map_classname$> entry;\n" - " for (::google::protobuf::Map< $key_cpp$, $val_cpp$ >::const_iterator\n" - " it = this->$name$().begin();\n" - " it != this->$name$().end(); ++it) {\n"); +static void GenerateSerializationLoop(io::Printer* printer, + const map& variables, + bool supports_arenas, + const string& utf8_check, + const string& loop_header, + const string& ptr, + bool loop_via_iterators) { + printer->Print(variables, + StrCat("::google::protobuf::scoped_ptr<$map_classname$> entry;\n", + loop_header, " {\n").c_str()); + printer->Indent(); + + printer->Print(variables, StrCat( + "entry.reset($name$_.New$wrapper$(\n" + " ", ptr, "->first, ", ptr, "->second));\n" + "$write_entry$;\n").c_str()); // If entry is allocated by arena, its desctructor should be avoided. - if (SupportsArenas(descriptor_)) { - printer->Print(variables_, - " if (entry.get() != NULL && entry->GetArena() != NULL) {\n" - " entry.release();\n" - " }\n"); + if (supports_arenas) { + printer->Print( + "if (entry->GetArena() != NULL) {\n" + " entry.release();\n" + "}\n"); } - printer->Print(variables_, - " entry.reset($name$_.New$wrapper$(it->first, it->second));\n" - " ::google::protobuf::internal::WireFormatLite::Write$stream_writer$(\n" - " $number$, *entry, output);\n"); - - printer->Indent(); - printer->Indent(); - - const FieldDescriptor* key_field = - descriptor_->message_type()->FindFieldByName("key"); - const FieldDescriptor* value_field = - descriptor_->message_type()->FindFieldByName("value"); - if (key_field->type() == FieldDescriptor::TYPE_STRING) { - GenerateUtf8CheckCodeForString(key_field, options_, false, variables_, - "it->first.data(), it->first.length(),\n", - printer); - } - if (value_field->type() == FieldDescriptor::TYPE_STRING) { - GenerateUtf8CheckCodeForString(value_field, options_, false, variables_, - "it->second.data(), it->second.length(),\n", - printer); + if (!utf8_check.empty()) { + // If loop_via_iterators is true then ptr is actually an iterator, and we + // create a pointer by prefixing it with "&*". + printer->Print( + StrCat(utf8_check, "(", (loop_via_iterators ? "&*" : ""), ptr, ");\n") + .c_str()); } printer->Outdent(); - printer->Outdent(); - printer->Print( - " }\n"); - - // If entry is allocated by arena, its desctructor should be avoided. - if (SupportsArenas(descriptor_)) { - printer->Print(variables_, - " if (entry.get() != NULL && entry->GetArena() != NULL) {\n" - " entry.release();\n" - " }\n"); - } + "}\n"); +} - printer->Print("}\n"); +void MapFieldGenerator:: +GenerateSerializeWithCachedSizes(io::Printer* printer) const { + map variables(variables_); + variables["write_entry"] = "::google::protobuf::internal::WireFormatLite::Write" + + variables["stream_writer"] + "(\n " + + variables["number"] + ", *entry, output)"; + variables["deterministic"] = "output->IsSerializationDeterminstic()"; + GenerateSerializeWithCachedSizes(printer, variables); } void MapFieldGenerator:: GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { - printer->Print(variables_, - "{\n" - " ::google::protobuf::scoped_ptr<$map_classname$> entry;\n" - " for (::google::protobuf::Map< $key_cpp$, $val_cpp$ >::const_iterator\n" - " it = this->$name$().begin();\n" - " it != this->$name$().end(); ++it) {\n"); - - // If entry is allocated by arena, its desctructor should be avoided. - if (SupportsArenas(descriptor_)) { - printer->Print(variables_, - " if (entry.get() != NULL && entry->GetArena() != NULL) {\n" - " entry.release();\n" - " }\n"); - } - - printer->Print(variables_, - " entry.reset($name$_.New$wrapper$(it->first, it->second));\n" - " target = ::google::protobuf::internal::WireFormatLite::\n" - " InternalWrite$declared_type$NoVirtualToArray(\n" - " $number$, *entry, false, target);\n"); + map variables(variables_); + variables["write_entry"] = + "target = ::google::protobuf::internal::WireFormatLite::\n" + " InternalWrite" + variables["declared_type"] + + "NoVirtualToArray(\n " + variables["number"] + + ", *entry, deterministic, target);\n"; + variables["deterministic"] = "deterministic"; + GenerateSerializeWithCachedSizes(printer, variables); +} +void MapFieldGenerator::GenerateSerializeWithCachedSizes( + io::Printer* printer, const map& variables) const { + printer->Print(variables, + "if (!this->$name$().empty()) {\n"); printer->Indent(); - printer->Indent(); - const FieldDescriptor* key_field = descriptor_->message_type()->FindFieldByName("key"); const FieldDescriptor* value_field = descriptor_->message_type()->FindFieldByName("value"); - if (key_field->type() == FieldDescriptor::TYPE_STRING) { - GenerateUtf8CheckCodeForString(key_field, options_, false, variables_, - "it->first.data(), it->first.length(),\n", - printer); + const bool string_key = key_field->type() == FieldDescriptor::TYPE_STRING; + const bool string_value = value_field->type() == FieldDescriptor::TYPE_STRING; + + printer->Print(variables, + "typedef ::google::protobuf::Map< $key_cpp$, $val_cpp$ >::const_pointer\n" + " ConstPtr;\n"); + if (string_key) { + printer->Print(variables, + "typedef ConstPtr SortItem;\n" + "typedef ::google::protobuf::internal::" + "CompareByDerefFirst Less;\n"); + } else { + printer->Print(variables, + "typedef ::google::protobuf::internal::SortItem< $key_cpp$, ConstPtr > " + "SortItem;\n" + "typedef ::google::protobuf::internal::CompareByFirstField Less;\n"); } - if (value_field->type() == FieldDescriptor::TYPE_STRING) { - GenerateUtf8CheckCodeForString(value_field, options_, false, variables_, - "it->second.data(), it->second.length(),\n", - printer); + string utf8_check; + if (string_key || string_value) { + printer->Print( + "struct Utf8Check {\n" + " static void Check(ConstPtr p) {\n"); + printer->Indent(); + printer->Indent(); + if (string_key) { + GenerateUtf8CheckCodeForString(key_field, options_, false, variables, + "p->first.data(), p->first.length(),\n", + printer); + } + if (string_value) { + GenerateUtf8CheckCodeForString(value_field, options_, false, variables, + "p->second.data(), p->second.length(),\n", + printer); + } + printer->Outdent(); + printer->Outdent(); + printer->Print( + " }\n" + "};\n"); + utf8_check = "Utf8Check::Check"; } - printer->Outdent(); + printer->Print(variables, + "\n" + "if ($deterministic$ &&\n" + " this->$name$().size() > 1) {\n" + " ::google::protobuf::scoped_array items(\n" + " new SortItem[this->$name$().size()]);\n" + " typedef ::google::protobuf::Map< $key_cpp$, $val_cpp$ >::size_type size_type;\n" + " size_type n = 0;\n" + " for (::google::protobuf::Map< $key_cpp$, $val_cpp$ >::const_iterator\n" + " it = this->$name$().begin();\n" + " it != this->$name$().end(); ++it, ++n) {\n" + " items[n] = SortItem(&*it);\n" + " }\n" + " ::std::sort(&items[0], &items[n], Less());\n"); + printer->Indent(); + GenerateSerializationLoop(printer, variables, SupportsArenas(descriptor_), + utf8_check, "for (size_type i = 0; i < n; i++)", + string_key ? "items[i]" : "items[i].second", false); printer->Outdent(); printer->Print( - " }\n"); - - // If entry is allocated by arena, its desctructor should be avoided. - if (SupportsArenas(descriptor_)) { - printer->Print(variables_, - " if (entry.get() != NULL && entry->GetArena() != NULL) {\n" - " entry.release();\n" - " }\n"); - } - + "} else {\n"); + printer->Indent(); + GenerateSerializationLoop( + printer, variables, SupportsArenas(descriptor_), utf8_check, + "for (::google::protobuf::Map< $key_cpp$, $val_cpp$ >::const_iterator\n" + " it = this->$name$().begin();\n" + " it != this->$name$().end(); ++it)", + "it", true); + printer->Outdent(); + printer->Print("}\n"); + printer->Outdent(); printer->Print("}\n"); } diff --git a/src/google/protobuf/compiler/cpp/cpp_map_field.h b/src/google/protobuf/compiler/cpp/cpp_map_field.h index 087dcde0f4..2930fe59e9 100644 --- a/src/google/protobuf/compiler/cpp/cpp_map_field.h +++ b/src/google/protobuf/compiler/cpp/cpp_map_field.h @@ -61,6 +61,10 @@ class MapFieldGenerator : public FieldGenerator { void GenerateByteSize(io::Printer* printer) const; private: + // A helper for GenerateSerializeWithCachedSizes{,ToArray}. + void GenerateSerializeWithCachedSizes( + io::Printer* printer, const map& variables) const; + const FieldDescriptor* descriptor_; const bool dependent_field_; map variables_; diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc index 32f63152f0..405a5fed55 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message.cc @@ -2715,7 +2715,9 @@ GenerateMergeFrom(io::Printer* printer) { "void $classname$::MergeFrom(const ::google::protobuf::Message& from) {\n" "// @@protoc_insertion_point(generalized_merge_from_start:" "$full_name$)\n" - " if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);\n", + " if (GOOGLE_PREDICT_FALSE(&from == this)) {\n" + " ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);\n" + " }\n", "classname", classname_, "full_name", descriptor_->full_name()); printer->Indent(); @@ -2756,7 +2758,9 @@ GenerateMergeFrom(io::Printer* printer) { "void $classname$::MergeFrom(const $classname$& from) {\n" "// @@protoc_insertion_point(class_specific_merge_from_start:" "$full_name$)\n" - " if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);\n", + " if (GOOGLE_PREDICT_FALSE(&from == this)) {\n" + " ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);\n" + " }\n", "classname", classname_, "full_name", descriptor_->full_name()); printer->Indent(); diff --git a/src/google/protobuf/compiler/java/java_file.cc b/src/google/protobuf/compiler/java/java_file.cc index a06c5f6dc0..5e387285bb 100644 --- a/src/google/protobuf/compiler/java/java_file.cc +++ b/src/google/protobuf/compiler/java/java_file.cc @@ -266,9 +266,7 @@ void FileGenerator::Generate(io::Printer* printer) { printer->Print( "public static void registerAllExtensions(\n" - " com.google.protobuf.ExtensionRegistry$lite$ registry) {\n", - "lite", - HasDescriptorMethods(file_, context_->EnforceLite()) ? "" : "Lite"); + " com.google.protobuf.ExtensionRegistryLite registry) {\n"); printer->Indent(); @@ -283,6 +281,20 @@ void FileGenerator::Generate(io::Printer* printer) { printer->Outdent(); printer->Print( "}\n"); + if (HasDescriptorMethods(file_, context_->EnforceLite())) { + // Overload registerAllExtensions for the non-lite usage to + // redundantly maintain the original signature (this is + // redundant because ExtensionRegistryLite now invokes + // ExtensionRegistry in the non-lite usage). Intent is + // to remove this in the future. + printer->Print( + "\n" + "public static void registerAllExtensions(\n" + " com.google.protobuf.ExtensionRegistry registry) {\n" + " registerAllExtensions(\n" + " (com.google.protobuf.ExtensionRegistryLite) registry);\n" + "}\n"); + } // ----------------------------------------------------------------- diff --git a/src/google/protobuf/compiler/java/java_generator.cc b/src/google/protobuf/compiler/java/java_generator.cc index 3c545e1589..b1ab404330 100644 --- a/src/google/protobuf/compiler/java/java_generator.cc +++ b/src/google/protobuf/compiler/java/java_generator.cc @@ -79,8 +79,6 @@ bool JavaGenerator::Generate(const FileDescriptor* file, file_options.generate_mutable_code = true; } else if (options[i].first == "shared") { file_options.generate_shared_code = true; - } else if (options[i].first == "lite") { - file_options.enforce_lite = true; } else if (options[i].first == "annotate_code") { file_options.annotate_code = true; } else if (options[i].first == "annotation_list_file") { diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index 8a2633d796..ad8cb166c2 100755 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -2031,9 +2031,8 @@ void Generator::GenerateClassFieldToObject(const GeneratorOptions& options, "getter", JSGetterName(options, field, BYTES_B64)); } else { if (field->has_default_value()) { - printer->Print("jspb.Message.getField(msg, $index$) == null ? " - "$defaultValue$ : ", - "index", JSFieldIndex(field), + printer->Print("!msg.has$name$() ? $defaultValue$ : ", + "name", JSGetterName(options, field), "defaultValue", JSFieldDefault(field)); } if (field->cpp_type() == FieldDescriptor::CPPTYPE_FLOAT || @@ -2408,9 +2407,8 @@ void Generator::GenerateClassField(const GeneratorOptions& options, "default", Proto3PrimitiveFieldDefault(field)); } else { if (field->has_default_value()) { - printer->Print("jspb.Message.getField(this, $index$) == null ? " - "$defaultValue$ : ", - "index", JSFieldIndex(field), + printer->Print("!this.has$name$() ? $defaultValue$ : ", + "name", JSGetterName(options, field), "defaultValue", JSFieldDefault(field)); } if (field->cpp_type() == FieldDescriptor::CPPTYPE_FLOAT || @@ -2515,6 +2513,20 @@ void Generator::GenerateClassField(const GeneratorOptions& options, "\n", "clearedvalue", (field->is_repeated() ? "[]" : "undefined"), "returnvalue", JSReturnClause(field)); + + printer->Print( + "/**\n" + " * Returns whether this field is set.\n" + " * @return{!boolean}\n" + " */\n" + "$class$.prototype.has$name$ = function() {\n" + " return jspb.Message.getField(this, $index$) != null;\n" + "};\n" + "\n" + "\n", + "class", GetPath(options, field->containing_type()), + "name", JSGetterName(options, field), + "index", JSFieldIndex(field)); } } } diff --git a/src/google/protobuf/compiler/python/python_generator.cc b/src/google/protobuf/compiler/python/python_generator.cc index cc54a8aba7..d5468a0cb0 100644 --- a/src/google/protobuf/compiler/python/python_generator.cc +++ b/src/google/protobuf/compiler/python/python_generator.cc @@ -44,6 +44,7 @@ // performance-minded Python code leverage the fast C++ implementation // directly. +#include #include #include #include @@ -107,20 +108,25 @@ string ModuleAlias(const string& filename) { return module_name; } - -// Returns an import statement of form "from X.Y.Z import T" for the given -// .proto filename. -string ModuleImportStatement(const string& filename) { - string module_name = ModuleName(filename); - int last_dot_pos = module_name.rfind('.'); - if (last_dot_pos == string::npos) { - // NOTE(petya): this is not tested as it would require a protocol buffer - // outside of any package, and I don't think that is easily achievable. - return "import " + module_name; - } else { - return "from " + module_name.substr(0, last_dot_pos) + " import " + - module_name.substr(last_dot_pos + 1); +// Keywords reserved by the Python language. +const char* const kKeywords[] = { + "False", "None", "True", "and", "as", "assert", "break", + "class", "continue", "def", "del", "elif", "else", "except", + "finally", "for", "from", "global", "if", "import", "in", + "is", "lambda", "nonlocal", "not", "or", "pass", "raise", + "return", "try", "while", "with", "yield", +}; +const char* const* kKeywordsEnd = + kKeywords + (sizeof(kKeywords) / sizeof(kKeywords[0])); + +bool ContainsPythonKeyword(const string& module_name) { + vector tokens = Split(module_name, "."); + for (int i = 0; i < tokens.size(); ++i) { + if (std::find(kKeywords, kKeywordsEnd, tokens[i]) != kKeywordsEnd) { + return true; + } } + return false; } @@ -359,10 +365,32 @@ bool Generator::Generate(const FileDescriptor* file, void Generator::PrintImports() const { for (int i = 0; i < file_->dependency_count(); ++i) { const string& filename = file_->dependency(i)->name(); - string import_statement = ModuleImportStatement(filename); + + string module_name = ModuleName(filename); string module_alias = ModuleAlias(filename); - printer_->Print("$statement$ as $alias$\n", "statement", - import_statement, "alias", module_alias); + if (ContainsPythonKeyword(module_name)) { + // If the module path contains a Python keyword, we have to quote the + // module name and import it using importlib. Otherwise the usual kind of + // import statement would result in a syntax error from the presence of + // the keyword. + printer_->Print("import importlib\n"); + printer_->Print("$alias$ = importlib.import_module('$name$')\n", "alias", + module_alias, "name", module_name); + } else { + int last_dot_pos = module_name.rfind('.'); + string import_statement; + if (last_dot_pos == string::npos) { + // NOTE(petya): this is not tested as it would require a protocol buffer + // outside of any package, and I don't think that is easily achievable. + import_statement = "import " + module_name; + } else { + import_statement = "from " + module_name.substr(0, last_dot_pos) + + " import " + module_name.substr(last_dot_pos + 1); + } + printer_->Print("$statement$ as $alias$\n", "statement", import_statement, + "alias", module_alias); + } + CopyPublicDependenciesAliases(module_alias, file_->dependency(i)); } printer_->Print("\n"); diff --git a/src/google/protobuf/compiler/python/python_plugin_unittest.cc b/src/google/protobuf/compiler/python/python_plugin_unittest.cc index 23f2449cde..34f857fddb 100644 --- a/src/google/protobuf/compiler/python/python_plugin_unittest.cc +++ b/src/google/protobuf/compiler/python/python_plugin_unittest.cc @@ -46,6 +46,7 @@ #include #include +#include #include #include @@ -115,6 +116,53 @@ TEST(PythonPluginTest, PluginTest) { EXPECT_EQ(0, cli.Run(5, argv)); } +// This test verifies that the generated Python output uses regular imports (as +// opposed to importlib) in the usual case where the .proto file paths do not +// not contain any Python keywords. +TEST(PythonPluginTest, ImportTest) { + // Create files test1.proto and test2.proto with the former importing the + // latter. + GOOGLE_CHECK_OK(File::SetContents(TestTempDir() + "/test1.proto", + "syntax = \"proto3\";\n" + "package foo;\n" + "import \"test2.proto\";" + "message Message1 {\n" + " Message2 message_2 = 1;\n" + "}\n", + true)); + GOOGLE_CHECK_OK(File::SetContents(TestTempDir() + "/test2.proto", + "syntax = \"proto3\";\n" + "package foo;\n" + "message Message2 {}\n", + true)); + + google::protobuf::compiler::CommandLineInterface cli; + cli.SetInputsAreProtoPathRelative(true); + python::Generator python_generator; + cli.RegisterGenerator("--python_out", &python_generator, ""); + string proto_path = "-I" + TestTempDir(); + string python_out = "--python_out=" + TestTempDir(); + const char* argv[] = {"protoc", proto_path.c_str(), "-I.", python_out.c_str(), + "test1.proto"}; + ASSERT_EQ(0, cli.Run(5, argv)); + + // Loop over the lines of the generated code and verify that we find an + // ordinary Python import but do not find the string "importlib". + string output; + GOOGLE_CHECK_OK(File::GetContents(TestTempDir() + "/test1_pb2.py", &output, + true)); + std::vector lines = Split(output, "\n"); + string expected_import = "import test2_pb2"; + bool found_expected_import = false; + for (int i = 0; i < lines.size(); ++i) { + if (lines[i].find(expected_import) != string::npos) { + found_expected_import = true; + } + EXPECT_EQ(string::npos, lines[i].find("importlib")); + } + EXPECT_TRUE(found_expected_import); +} + } // namespace } // namespace python } // namespace compiler diff --git a/src/google/protobuf/descriptor.proto b/src/google/protobuf/descriptor.proto index da853dbc0e..28410d4a9a 100644 --- a/src/google/protobuf/descriptor.proto +++ b/src/google/protobuf/descriptor.proto @@ -45,6 +45,7 @@ option java_package = "com.google.protobuf"; option java_outer_classname = "DescriptorProtos"; option csharp_namespace = "Google.Protobuf.Reflection"; option objc_class_prefix = "GPB"; +option java_generate_equals_and_hash = true; // descriptor.proto must be optimized for speed because reflection-based // algorithms don't work during bootstrapping. diff --git a/src/google/protobuf/extension_set_heavy.cc b/src/google/protobuf/extension_set_heavy.cc index 5dd171ed34..b26a246c7d 100644 --- a/src/google/protobuf/extension_set_heavy.cc +++ b/src/google/protobuf/extension_set_heavy.cc @@ -341,7 +341,7 @@ bool ExtensionSet::ParseMessageSet(io::CodedInputStream* input, int ExtensionSet::SpaceUsedExcludingSelf() const { int total_size = - extensions_.size() * sizeof(map::value_type); + extensions_.size() * sizeof(ExtensionMap::value_type); for (ExtensionMap::const_iterator iter = extensions_.begin(), end = extensions_.end(); iter != end; diff --git a/src/google/protobuf/generated_message_util.cc b/src/google/protobuf/generated_message_util.cc index 7b813f8af5..7ad6d61cbc 100644 --- a/src/google/protobuf/generated_message_util.cc +++ b/src/google/protobuf/generated_message_util.cc @@ -73,6 +73,12 @@ int StringSpaceUsedExcludingSelf(const string& str) { +void MergeFromFail(const char* file, int line) { + GOOGLE_CHECK(false) << file << ":" << line; + // Open-source GOOGLE_CHECK(false) is not NORETURN. + exit(1); +} + } // namespace internal } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/generated_message_util.h b/src/google/protobuf/generated_message_util.h index 56f5afd26a..dc81518914 100644 --- a/src/google/protobuf/generated_message_util.h +++ b/src/google/protobuf/generated_message_util.h @@ -41,8 +41,8 @@ #include #include -#include #include +#include namespace google { @@ -115,6 +115,10 @@ class ArenaString; ArenaString* ReadArenaString(::google::protobuf::io::CodedInputStream* input, ::google::protobuf::Arena* arena); +// Helper function to crash on merge failure. +// Moved out of generated code to reduce binary size. +void MergeFromFail(const char* file, int line) GOOGLE_ATTRIBUTE_NORETURN; + } // namespace internal } // namespace protobuf diff --git a/src/google/protobuf/io/coded_stream.cc b/src/google/protobuf/io/coded_stream.cc index 148eee0e12..a5675e79f8 100644 --- a/src/google/protobuf/io/coded_stream.cc +++ b/src/google/protobuf/io/coded_stream.cc @@ -649,13 +649,16 @@ bool CodedInputStream::Refresh() { // CodedOutputStream ================================================= +bool CodedOutputStream::default_serialization_deterministic_ = false; + CodedOutputStream::CodedOutputStream(ZeroCopyOutputStream* output) : output_(output), buffer_(NULL), buffer_size_(0), total_bytes_(0), had_error_(false), - aliasing_enabled_(false) { + aliasing_enabled_(false), + serialization_deterministic_is_overridden_(false) { // Eagerly Refresh() so buffer space is immediately available. Refresh(); // The Refresh() may have failed. If the client doesn't write any data, @@ -671,7 +674,8 @@ CodedOutputStream::CodedOutputStream(ZeroCopyOutputStream* output, buffer_size_(0), total_bytes_(0), had_error_(false), - aliasing_enabled_(false) { + aliasing_enabled_(false), + serialization_deterministic_is_overridden_(false) { if (do_eager_refresh) { // Eagerly Refresh() so buffer space is immediately available. Refresh(); diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h index eb32074526..316da76524 100644 --- a/src/google/protobuf/io/coded_stream.h +++ b/src/google/protobuf/io/coded_stream.h @@ -813,6 +813,44 @@ class LIBPROTOBUF_EXPORT CodedOutputStream { // created. bool HadError() const { return had_error_; } + // Deterministic serialization, if requested, guarantees that for a given + // binary, equal messages will always be serialized to the same bytes. This + // implies: + // . repeated serialization of a message will return the same bytes + // . different processes of the same binary (which may be executing on + // different machines) will serialize equal messages to the same bytes. + // + // Note the deterministic serialization is NOT canonical across languages; it + // is also unstable across different builds with schema changes due to unknown + // fields. Users who need canonical serialization, e.g., persistent storage in + // a canonical form, fingerprinting, etc., should define their own + // canonicalization specification and implement the serializer using + // reflection APIs rather than relying on this API. + // + // If determinisitc serialization is requested, the serializer will + // sort map entries by keys in lexicographical order or numerical order. + // (This is an implementation detail and may subject to change.) + // + // There are two ways to determine whether serialization should be + // deterministic for this CodedOutputStream. If SetSerializationDeterministic + // has not yet been called, then the default comes from the global default, + // which is false, until SetDefaultSerializationDeterministic has been called. + // Otherwise, SetSerializationDeterministic has been called, and the last + // value passed to it is all that matters. + void SetSerializationDeterministic(bool value) { + serialization_deterministic_is_overridden_ = true; + serialization_deterministic_override_ = value; + } + // See above. Also, note that users of this CodedOutputStream may need to + // call IsSerializationDeterminstic() to serialize in the intended way. This + // CodedOutputStream cannot enforce a desire for deterministic serialization + // by itself. + bool IsSerializationDeterminstic() const { + return serialization_deterministic_is_overridden_ ? + serialization_deterministic_override_ : + default_serialization_deterministic_; + } + private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodedOutputStream); @@ -822,6 +860,10 @@ class LIBPROTOBUF_EXPORT CodedOutputStream { int total_bytes_; // Sum of sizes of all buffers seen so far. bool had_error_; // Whether an error occurred during output. bool aliasing_enabled_; // See EnableAliasing(). + // See SetSerializationDeterministic() regarding these three fields. + bool serialization_deterministic_is_overridden_; + bool serialization_deterministic_override_; + static bool default_serialization_deterministic_; // Advance the buffer by a given number of bytes. void Advance(int amount); @@ -849,6 +891,11 @@ class LIBPROTOBUF_EXPORT CodedOutputStream { uint64 value, uint8* target); static int VarintSize32Fallback(uint32 value); + + // See above. Other projects may use "friend" to allow them to call this. + static void SetDefaultSerializationDeterministic() { + default_serialization_deterministic_ = true; + } }; // inline methods ==================================================== diff --git a/src/google/protobuf/map_entry_lite.h b/src/google/protobuf/map_entry_lite.h index 23ac7b8abb..4dedfd5702 100644 --- a/src/google/protobuf/map_entry_lite.h +++ b/src/google/protobuf/map_entry_lite.h @@ -535,6 +535,32 @@ class MapEntryLite : public MessageLite { GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntryLite); }; +// Helpers for deterministic serialization ============================= + +// This struct can be used with any generic sorting algorithm. If the Key +// type is relatively small and easy to copy then copying Keys into an +// array of SortItems can be beneficial. Then all the data the sorting +// algorithm needs to touch is in that one array. +template struct SortItem { + SortItem() {} + explicit SortItem(PtrToKeyValuePair p) : first(p->first), second(p) {} + + Key first; + PtrToKeyValuePair second; +}; + +template struct CompareByFirstField { + bool operator()(const T& a, const T& b) const { + return a.first < b.first; + } +}; + +template struct CompareByDerefFirst { + bool operator()(const T& a, const T& b) const { + return a->first < b->first; + } +}; + } // namespace internal } // namespace protobuf diff --git a/src/google/protobuf/map_proto2_unittest.proto b/src/google/protobuf/map_proto2_unittest.proto index 916cc54637..ddc2a58247 100644 --- a/src/google/protobuf/map_proto2_unittest.proto +++ b/src/google/protobuf/map_proto2_unittest.proto @@ -64,3 +64,23 @@ message TestEnumMapPlusExtra { message TestImportEnumMap { map import_enum_amp = 1; } + +message TestIntIntMap { + map m = 1; +} + +// Test all key types: string, plus the non-floating-point scalars. +message TestMaps { + map m_int32 = 1; + map m_int64 = 2; + map m_uint32 = 3; + map m_uint64 = 4; + map m_sint32 = 5; + map m_sint64 = 6; + map m_fixed32 = 7; + map m_fixed64 = 8; + map m_sfixed32 = 9; + map m_sfixed64 = 10; + map m_bool = 11; + map m_string = 12; +} diff --git a/src/google/protobuf/map_test.cc b/src/google/protobuf/map_test.cc index cdd1ccd574..03954e75f1 100644 --- a/src/google/protobuf/map_test.cc +++ b/src/google/protobuf/map_test.cc @@ -74,6 +74,7 @@ #include #include #include +#include #include #include #include @@ -2869,6 +2870,82 @@ TEST(WireFormatForMapFieldTest, MapParseHelpers) { } } +// Deterministic Serialization Test ========================================== + +template +static string DeterministicSerialization(const T& t) { + const int size = t.ByteSize(); + string result(size, '\0'); + io::ArrayOutputStream array_stream(string_as_array(&result), size); + io::CodedOutputStream output_stream(&array_stream); + output_stream.SetSerializationDeterministic(true); + t.SerializeWithCachedSizes(&output_stream); + EXPECT_FALSE(output_stream.HadError()); + EXPECT_EQ(size, output_stream.ByteCount()); + return result; +} + +// Helper to test the serialization of the first arg against a golden file. +static void TestDeterministicSerialization(const protobuf_unittest::TestMaps& t, + const string& filename) { + string expected; + GOOGLE_CHECK_OK(File::GetContents( + TestSourceDir() + "/google/protobuf/testdata/" + filename, + &expected, true)); + const string actual = DeterministicSerialization(t); + EXPECT_EQ(expected, actual); + protobuf_unittest::TestMaps u; + EXPECT_TRUE(u.ParseFromString(actual)); + EXPECT_TRUE(google::protobuf::util::MessageDifferencer::Equals(u, t)); +} + +// Helper for MapSerializationTest. Return a 7-bit ASCII string. +static string ConstructKey(uint64 n) { + string s(n % static_cast(9), '\0'); + if (s.empty()) { + return StrCat(n); + } else { + while (n != 0) { + s[n % s.size()] = (n >> 10) & 0x7f; + n /= 888; + } + return s; + } +} + +TEST(MapSerializationTest, Deterministic) { + const int kIters = 25; + protobuf_unittest::TestMaps t; + protobuf_unittest::TestIntIntMap inner; + (*inner.mutable_m())[0] = (*inner.mutable_m())[10] = + (*inner.mutable_m())[-200] = 0; + uint64 frog = 9; + const uint64 multiplier = 0xa29cd16f; + for (int i = 0; i < kIters; i++) { + const int32 i32 = static_cast(frog & 0xffffffff); + const uint32 u32 = static_cast(i32) * 91919; + const int64 i64 = static_cast(frog); + const uint64 u64 = frog * static_cast(187321); + const bool b = i32 > 0; + const string s = ConstructKey(frog); + (*inner.mutable_m())[i] = i32; + (*t.mutable_m_int32())[i32] = (*t.mutable_m_sint32())[i32] = + (*t.mutable_m_sfixed32())[i32] = inner; + (*t.mutable_m_uint32())[u32] = (*t.mutable_m_fixed32())[u32] = inner; + (*t.mutable_m_int64())[i64] = (*t.mutable_m_sint64())[i64] = + (*t.mutable_m_sfixed64())[i64] = inner; + (*t.mutable_m_uint64())[u64] = (*t.mutable_m_fixed64())[u64] = inner; + (*t.mutable_m_bool())[b] = inner; + (*t.mutable_m_string())[s] = inner; + (*t.mutable_m_string())[s + string(1 << (u32 % static_cast(9)), + b)] = inner; + inner.mutable_m()->erase(i); + frog = frog * multiplier + i; + frog ^= (frog >> 41); + } + TestDeterministicSerialization(t, "golden_message_maps"); +} + // Text Format Test ================================================= TEST(TextFormatMapTest, SerializeAndParse) { diff --git a/src/google/protobuf/map_type_handler.h b/src/google/protobuf/map_type_handler.h index 74e8bb508d..685a770fb9 100644 --- a/src/google/protobuf/map_type_handler.h +++ b/src/google/protobuf/map_type_handler.h @@ -166,10 +166,10 @@ class MapTypeHandler { io::CodedOutputStream* output); static inline uint8* InternalWriteToArray(int field, const MapEntryAccessorType& value, - bool deterministic, uint8* output); + bool deterministic, uint8* target); static inline uint8* WriteToArray(int field, const MapEntryAccessorType& value, - uint8* output); + uint8* target); // Functions to manipulate data on memory. ======================== static inline const Type& GetExternalReference(const Type* value); @@ -227,11 +227,11 @@ class MapTypeHandler { int field, \ const MapEntryAccessorType& value, \ bool deterministic, \ - uint8* output); \ + uint8* target); \ static inline uint8* WriteToArray(int field, \ const MapEntryAccessorType& value, \ - uint8* output) { \ - return InternalWriteToArray(field, value, false, output); \ + uint8* target) { \ + return InternalWriteToArray(field, value, false, target); \ } \ static inline const MapEntryAccessorType& GetExternalReference( \ const TypeOnMemory& value); \ @@ -374,9 +374,9 @@ template inline uint8* MapTypeHandler::InternalWriteToArray( int field, const MapEntryAccessorType& value, bool deterministic, - uint8* output) { + uint8* target) { return WireFormatLite::InternalWriteMessageToArray(field, value, - deterministic, output); + deterministic, target); } #define WRITE_METHOD(FieldType, DeclaredType) \ @@ -390,8 +390,8 @@ MapTypeHandler::InternalWriteToArray( inline uint8* \ MapTypeHandler::InternalWriteToArray( \ - int field, const MapEntryAccessorType& value, bool, uint8* output) { \ - return WireFormatLite::Write##DeclaredType##ToArray(field, value, output); \ + int field, const MapEntryAccessorType& value, bool, uint8* target) { \ + return WireFormatLite::Write##DeclaredType##ToArray(field, value, target); \ } WRITE_METHOD(STRING , String) diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc index d62ca79c80..f18077dd20 100644 --- a/src/google/protobuf/message.cc +++ b/src/google/protobuf/message.cc @@ -62,8 +62,6 @@ namespace protobuf { using internal::WireFormat; using internal::ReflectionOps; -Message::~Message() {} - void Message::MergeFrom(const Message& from) { const Descriptor* descriptor = GetDescriptor(); GOOGLE_CHECK_EQ(from.GetDescriptor(), descriptor) diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index dcdffe1c5c..9705e97e43 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -179,7 +179,7 @@ struct Metadata { class LIBPROTOBUF_EXPORT Message : public MessageLite { public: inline Message() {} - virtual ~Message(); + virtual ~Message() {} // Basic Operations ------------------------------------------------ diff --git a/src/google/protobuf/message_lite.cc b/src/google/protobuf/message_lite.cc index 3913be1b39..ba56db952d 100644 --- a/src/google/protobuf/message_lite.cc +++ b/src/google/protobuf/message_lite.cc @@ -46,8 +46,6 @@ namespace google { namespace protobuf { -MessageLite::~MessageLite() {} - string MessageLite::InitializationErrorString() const { return "(cannot determine missing fields for lite message)"; } diff --git a/src/google/protobuf/message_lite.h b/src/google/protobuf/message_lite.h index f606aeec2c..2bdfe49614 100644 --- a/src/google/protobuf/message_lite.h +++ b/src/google/protobuf/message_lite.h @@ -81,7 +81,7 @@ namespace internal { class LIBPROTOBUF_EXPORT MessageLite { public: inline MessageLite() {} - virtual ~MessageLite(); + virtual ~MessageLite() {} // Basic Operations ------------------------------------------------ diff --git a/src/google/protobuf/testdata/golden_message_maps b/src/google/protobuf/testdata/golden_message_maps new file mode 100644 index 0000000000000000000000000000000000000000..c70a4d7cde5b36e9b4970862826b8f8d1be169b3 GIT binary patch literal 13619 zcmd^FdsviJ8vh0d`R3EnugP1aagoczpef@8VV^dlT6>_I^i;cA+cvq`u4VOJS%xYprl7H1=6px9w z%;U$`0bCY*>cZsUx%~J#=fV!gZ)v1p#27Pve0|KA?^{l9ADGmbIsEuK7;`dzv|@7b z!~FO<7<1xm%~c9UjA8llb!vAkFSrpoZeI& zH9V=y)A{jraJjwcK(_WwCD>sp`0;gcxv{q8E(Ig@oAcxA)EFyPrg(H>4oF#smyH2p z3%flO^Cn^}*qJ<8;T+k^gWS!p2F~EMOPmcm6kc0w zhC$@Kb_pPj9T|-%WHzr|0!Y%p?z2-cDYJO(57| z$!K;2B?bjZCOH38;KAZGe1IBOU4enq*YIu!g`-5|&Fl6S5AVe(J)uNPFTvg(Jb4Xgcd1 zJ4hvY(%jJ!T8T=fc?39;+nL#UevK%O=03PYnDk0eXExvvS{5=b2qlS?efaS9R#YfW zJjEhyRt1LD?1REXDpW7EKq{#Y|J*Y_Lo-3jlva4WQ^yL;c^d9pe5#d<2F|JojVL2iPG{mIEJ2vnyN?2txdw zt*uF4VMd7if~5@`RID=C87%GC#`b?1Q*G(M4yPQSg+*2`_beB&*W>&yqV+G15t!$f z7T1j?DJ4{Z?9VMqLK_7wO@M^eoGwHmG}XcUp}eTuW|*78g0ysG4}@R3XNLKymq8$~ zJT`O36ilEnEg>F>C0A3XV8c-jlnI`bjapLNW%u=@GY6q?lfD zc0&X+uk`IP$MTf&8bqeI?sB;~78yN41B@7iO_uVSp7u0lux#14Tz)!>pi%296yWI#G18qpRmN%rRk=gT>cFqYI9w_cgzc zSu9RO*m2>;=r^5_u@z`r7jqJr-MM$9AnsIC=?2Vfn!W(5jqa&Ec&X>?CJaW)3nF&3 zv@Y%R?Uv9$bUYIFI{;Vz*w>bRuQogw1q+!Lz{!3Qdz&u#7004rA*D>F9i>*E_({{?Urz;k{w0IjE&V zp0Rad%e!}sM3fx4tTC~xf^(g@(amuwnRhBs=V)tHE@F?@Bd$)R13L;cB}$CK zVgp=%XLr+dEO&)R0NO(|{iV}Q%Uh6In$y`d4U;OY2*3?)_ig4doG`UOyMKG_4;-dl zTmyj4+}08#!_Z=G2K2tW)i+Sq70*CmaYE7MN^{I&VIlx7H8?%W=)?iqORKVD%rINU z45qYV6$ZPA(wfcfY4SCY{7OeQqdy*IE973Hm-k8=c0_Zy7QN6@@&m~I__R^<5>ERH zK#tY_atxhSC>H_bhn~X`XcMCYAwYUU{I{YFjP^P3t8ZK95f<}HkJv$0O=w*!(Dtq?K*6&6dyNkMe4V;|HfepG= z{Y}xYoe{MtQP7a9T(reN0fua6{B+2)@%DnZs<9bp#+X43#hL zV<4YY&Az=mN8rs0xn>JX2mHJjS-!jS>hWlxXN2u_VFOCKxAS6DsDI~oD2?kKI|O-a z-%w9pa`vsaFrhS!0OnglMl)Zf)Y9hpJ4w5r#{3adCx|@MyYF1ozJ1r1 zVIpbLL5!l)legb(xs>f>G^qp z0~TW*3hNO(JaB6B<3>{m#Ff7=U4@AgrX>U-(Yk**76>uXx?9O3*SH&a*axMaA63$Z(wSXq_mf7rf&Ka zb4AD$U|rt}Eni~RQDy{0*}B=O7=pGuK-9Tb9>fr|SwLJ%xNqw)V}!j29L%|$-+(zN z?rNabEaYZ4rj^z`hzn5<^kd@0?CR+t^DTIUAs>T#heH}^v-ERZv+9tgmv$4`9d_fZAHa{uJ-v~cY6+`f3^g^XG07zgT2 z7GPojzq5X}SmBd{Stw)^IG^%WWiQDJGc;JGiu)uvpLK!f-O8_3U@p;K>E$f{MOomB zi4>E+m%ZF0EItA=Rmj2sd#3DSGzJsK98?d^EQ!Tbi}?{`ey^%Zz+?)08NfWR7N=q` zVG@DrKiWqg!c>ds!lMUR`-0F`3?@u> zQ2p19f9b?jiyNw!tz2fTIe1ygAANH^J9(;mImj;$m(DSo=3dtFCo}%O082wUGyq~K zs23f`XtMxBZNe`40?O3y*Q?9)d-#B}LR#~>+iZPeG8Bs!4zER>OhatodjF!^Em*vUwU zEp6K)Fi|wjK1*bzGCY=h?7jvLsOt!E_z&jG8ur2Q%z`WB1N+~19d+FDQGO@7h9Wh8G$+9VGb|of}CJdlRY9}>F z8!;43Z*YV#;uHD*Xv7>5vLXm1nYA%zek&%BW|xmrMsnx9m%ZCDNA&UsB$B$wurD6P zB+}aOagY&0ARmJhBOD@OLvw;N>7oz5lcw=S6gCd9l+=uCo5Ak}fIvcrH$Pru z^s507CPGl(uK&vTHv_;i(g{z#lw#r+17HK8`gNQ0O#EH|aSteL?H^Yg`dR?EM_QQo zMk}M=3IGcT#*4na04`J;B*3k2V+K#h;qksD;_yc)Qqcoyk#Lc8A3H=yC zFCj7?-oU(Q;?-B}!a=fXH{fX~<|(xkHY$|LGTGj59+10bDczt^9Jf<&^(7V?u(V+rX5(5RDK_ zDdWUE%sht$Q#jzN-MG0FI?*PhTcJHoWu)pg4A!3X9u3rsIXDLbB@s3bx96sS1DFBA z+oRfnlLE{*4w695yvRT_koHfnVk8M3fD9#p4(!O8%iY$^LRAZAe6=e#TMINLxOy9* z`OaV%Ys_Lg{;KUcmO!*2MI6(?mT}Wm%U7&ew$gRw(xt9g28rJU)SqzPf=v^x|8IXc zQ7O!6%b9r$ TYPE_INTEGER // -12345 => TYPE_SYMBOL + TYPE_INTEGER diff --git a/src/google/protobuf/unknown_field_set.cc b/src/google/protobuf/unknown_field_set.cc index d4e383da23..8ee99d48b1 100644 --- a/src/google/protobuf/unknown_field_set.cc +++ b/src/google/protobuf/unknown_field_set.cc @@ -69,28 +69,14 @@ const UnknownFieldSet* UnknownFieldSet::default_instance() { return default_unknown_field_set_instance_; } -UnknownFieldSet::UnknownFieldSet() - : fields_(NULL) {} - -UnknownFieldSet::~UnknownFieldSet() { - Clear(); - delete fields_; -} - void UnknownFieldSet::ClearFallback() { - if (fields_ != NULL) { - for (int i = 0; i < fields_->size(); i++) { - (*fields_)[i].Delete(); - } - delete fields_; - fields_ = NULL; - } -} - -void UnknownFieldSet::ClearAndFreeMemory() { - if (fields_ != NULL) { - Clear(); - } + GOOGLE_DCHECK(fields_ != NULL && fields_->size() > 0); + int n = fields_->size(); + do { + (*fields_)[--n].Delete(); + } while (n > 0); + delete fields_; + fields_ = NULL; } void UnknownFieldSet::InternalMergeFrom(const UnknownFieldSet& other) { diff --git a/src/google/protobuf/unknown_field_set.h b/src/google/protobuf/unknown_field_set.h index 612a942a77..aa7529165b 100644 --- a/src/google/protobuf/unknown_field_set.h +++ b/src/google/protobuf/unknown_field_set.h @@ -241,8 +241,14 @@ class LIBPROTOBUF_EXPORT UnknownField { // =================================================================== // inline implementations +inline UnknownFieldSet::UnknownFieldSet() : fields_(NULL) {} + +inline UnknownFieldSet::~UnknownFieldSet() { Clear(); } + +inline void UnknownFieldSet::ClearAndFreeMemory() { Clear(); } + inline void UnknownFieldSet::Clear() { - if (fields_) { + if (fields_ != NULL) { ClearFallback(); } } diff --git a/src/google/protobuf/util/internal/default_value_objectwriter.cc b/src/google/protobuf/util/internal/default_value_objectwriter.cc index 21d7a2e4ab..1e8dab701a 100644 --- a/src/google/protobuf/util/internal/default_value_objectwriter.cc +++ b/src/google/protobuf/util/internal/default_value_objectwriter.cc @@ -64,6 +64,7 @@ DefaultValueObjectWriter::DefaultValueObjectWriter( type_(type), current_(NULL), root_(NULL), + suppress_empty_list_(false), field_scrub_callback_(NULL), ow_(ow) {} @@ -184,12 +185,10 @@ void DefaultValueObjectWriter::RegisterFieldScrubCallBack( field_scrub_callback_.reset(field_scrub_callback.release()); } -DefaultValueObjectWriter::Node::Node(const string& name, - const google::protobuf::Type* type, - NodeKind kind, const DataPiece& data, - bool is_placeholder, - const vector& path, - FieldScrubCallBack* field_scrub_callback) +DefaultValueObjectWriter::Node::Node( + const string& name, const google::protobuf::Type* type, NodeKind kind, + const DataPiece& data, bool is_placeholder, const vector& path, + bool suppress_empty_list, FieldScrubCallBack* field_scrub_callback) : name_(name), type_(type), kind_(kind), @@ -197,6 +196,7 @@ DefaultValueObjectWriter::Node::Node(const string& name, data_(data), is_placeholder_(is_placeholder), path_(path), + suppress_empty_list_(suppress_empty_list), field_scrub_callback_(field_scrub_callback) {} DefaultValueObjectWriter::Node* DefaultValueObjectWriter::Node::FindChild( @@ -230,6 +230,9 @@ void DefaultValueObjectWriter::Node::WriteTo(ObjectWriter* ow) { // Write out lists. If we didn't have any list in response, write out empty // list. if (kind_ == LIST) { + // Suppress empty lists if requested. + if (suppress_empty_list_ && is_placeholder_) return; + ow->StartList(name_); WriteChildren(ow); ow->EndList(); @@ -366,7 +369,7 @@ void DefaultValueObjectWriter::Node::PopulateChildren( field.json_name(), field_type, kind, kind == PRIMITIVE ? CreateDefaultDataPieceForField(field, typeinfo) : DataPiece::NullData(), - true, path, field_scrub_callback_)); + true, path, suppress_empty_list_, field_scrub_callback_)); new_children.push_back(child.release()); } // Adds all leftover nodes in children_ to the beginning of new_child. @@ -462,7 +465,8 @@ DefaultValueObjectWriter* DefaultValueObjectWriter::StartObject( if (current_ == NULL) { vector path; root_.reset(new Node(name.ToString(), &type_, OBJECT, DataPiece::NullData(), - false, path, field_scrub_callback_.get())); + false, path, suppress_empty_list_, + field_scrub_callback_.get())); root_->PopulateChildren(typeinfo_); current_ = root_.get(); return this; @@ -478,7 +482,7 @@ DefaultValueObjectWriter* DefaultValueObjectWriter::StartObject( : NULL), OBJECT, DataPiece::NullData(), false, child == NULL ? current_->path() : child->path(), - field_scrub_callback_.get())); + suppress_empty_list_, field_scrub_callback_.get())); child = node.get(); current_->AddChild(node.release()); } @@ -509,7 +513,8 @@ DefaultValueObjectWriter* DefaultValueObjectWriter::StartList( if (current_ == NULL) { vector path; root_.reset(new Node(name.ToString(), &type_, LIST, DataPiece::NullData(), - false, path, field_scrub_callback_.get())); + false, path, suppress_empty_list_, + field_scrub_callback_.get())); current_ = root_.get(); return this; } @@ -519,7 +524,7 @@ DefaultValueObjectWriter* DefaultValueObjectWriter::StartList( google::protobuf::scoped_ptr node( new Node(name.ToString(), NULL, LIST, DataPiece::NullData(), false, child == NULL ? current_->path() : child->path(), - field_scrub_callback_.get())); + suppress_empty_list_, field_scrub_callback_.get())); child = node.get(); current_->AddChild(node.release()); } @@ -577,7 +582,7 @@ void DefaultValueObjectWriter::RenderDataPiece(StringPiece name, google::protobuf::scoped_ptr node( new Node(name.ToString(), NULL, PRIMITIVE, data, false, child == NULL ? current_->path() : child->path(), - field_scrub_callback_.get())); + suppress_empty_list_, field_scrub_callback_.get())); child = node.get(); current_->AddChild(node.release()); } else { diff --git a/src/google/protobuf/util/internal/default_value_objectwriter.h b/src/google/protobuf/util/internal/default_value_objectwriter.h index 1d85bed85f..5f3b25f378 100644 --- a/src/google/protobuf/util/internal/default_value_objectwriter.h +++ b/src/google/protobuf/util/internal/default_value_objectwriter.h @@ -122,6 +122,10 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter { // field_scrub_callback pointer is also transferred to this class void RegisterFieldScrubCallBack(FieldScrubCallBackPtr field_scrub_callback); + // If set to true, empty lists are suppressed from output when default values + // are written. + void set_suppress_empty_list(bool value) { suppress_empty_list_ = value; } + private: enum NodeKind { PRIMITIVE = 0, @@ -136,7 +140,7 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter { public: Node(const string& name, const google::protobuf::Type* type, NodeKind kind, const DataPiece& data, bool is_placeholder, const vector& path, - FieldScrubCallBack* field_scrub_callback); + bool suppress_empty_list, FieldScrubCallBack* field_scrub_callback); virtual ~Node() { for (int i = 0; i < children_.size(); ++i) { delete children_[i]; @@ -212,6 +216,9 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter { // Path of the field of this node std::vector path_; + // Whether to suppress empty list output. + bool suppress_empty_list_; + // Pointer to function for determining whether a field needs to be scrubbed // or not. This callback is owned by the creator of this node. FieldScrubCallBack* field_scrub_callback_; @@ -257,6 +264,9 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter { // The stack to hold the path of Nodes from current_ to root_; std::stack stack_; + // Whether to suppress output of empty lists. + bool suppress_empty_list_; + // Unique Pointer to function for determining whether a field needs to be // scrubbed or not. FieldScrubCallBackPtr field_scrub_callback_; diff --git a/src/google/protobuf/util/internal/default_value_objectwriter_test.cc b/src/google/protobuf/util/internal/default_value_objectwriter_test.cc index 8254c0fa2e..e1dd697aec 100644 --- a/src/google/protobuf/util/internal/default_value_objectwriter_test.cc +++ b/src/google/protobuf/util/internal/default_value_objectwriter_test.cc @@ -149,6 +149,39 @@ TEST_P(DefaultValueObjectWriterTest, ShouldRetainUnknownField) { } +class DefaultValueObjectWriterSuppressListTest + : public BaseDefaultValueObjectWriterTest { + protected: + DefaultValueObjectWriterSuppressListTest() + : BaseDefaultValueObjectWriterTest(DefaultValueTest::descriptor()) { + testing_->set_suppress_empty_list(true); + } + ~DefaultValueObjectWriterSuppressListTest() {} +}; + +INSTANTIATE_TEST_CASE_P(DifferentTypeInfoSourceTest, + DefaultValueObjectWriterSuppressListTest, + ::testing::Values( + testing::USE_TYPE_RESOLVER)); + +TEST_P(DefaultValueObjectWriterSuppressListTest, Empty) { + // Set expectation. Emtpy lists should be suppressed. + expects_.StartObject("") + ->RenderDouble("doubleValue", 0.0) + ->RenderFloat("floatValue", 0.0) + ->RenderInt64("int64Value", 0) + ->RenderUint64("uint64Value", 0) + ->RenderInt32("int32Value", 0) + ->RenderUint32("uint32Value", 0) + ->RenderBool("boolValue", false) + ->RenderString("stringValue", "") + ->RenderBytes("bytesValue", "") + ->RenderString("enumValue", "ENUM_FIRST") + ->EndObject(); + + // Actual testing + testing_->StartObject("")->EndObject(); +} } // namespace testing } // namespace converter } // namespace util diff --git a/src/google/protobuf/util/internal/proto_writer.cc b/src/google/protobuf/util/internal/proto_writer.cc index 7a1a6cbdda..0c38aeb900 100644 --- a/src/google/protobuf/util/internal/proto_writer.cc +++ b/src/google/protobuf/util/internal/proto_writer.cc @@ -298,7 +298,9 @@ ProtoWriter::ProtoElement::ProtoElement(const TypeInfo* typeinfo, proto3_(type.syntax() == google::protobuf::SYNTAX_PROTO3), type_(type), size_index_(-1), - array_index_(-1) { + array_index_(-1), + // oneof_indices_ values are 1-indexed (0 means not present). + oneof_indices_(type.oneofs_size() + 1) { if (!proto3_) { required_fields_ = GetRequiredFields(type_); } @@ -312,13 +314,15 @@ ProtoWriter::ProtoElement::ProtoElement(ProtoWriter::ProtoElement* parent, ow_(this->parent()->ow_), parent_field_(field), typeinfo_(this->parent()->typeinfo_), - proto3_(this->parent()->proto3_), + proto3_(type.syntax() == google::protobuf::SYNTAX_PROTO3), type_(type), size_index_( !is_list && field->kind() == google::protobuf::Field_Kind_TYPE_MESSAGE ? ow_->size_insert_.size() : -1), - array_index_(is_list ? 0 : -1) { + array_index_(is_list ? 0 : -1), + // oneof_indices_ values are 1-indexed (0 means not present). + oneof_indices_(type_.oneofs_size() + 1) { if (!is_list) { if (ow_->IsRepeated(*field)) { // Update array_index_ if it is an explicit list. @@ -411,11 +415,11 @@ string ProtoWriter::ProtoElement::ToString() const { } bool ProtoWriter::ProtoElement::IsOneofIndexTaken(int32 index) { - return ContainsKey(oneof_indices_, index); + return oneof_indices_[index]; } void ProtoWriter::ProtoElement::TakeOneofIndex(int32 index) { - InsertIfNotPresent(&oneof_indices_, index); + oneof_indices_[index] = true; } void ProtoWriter::InvalidName(StringPiece unknown_name, StringPiece message) { @@ -573,10 +577,19 @@ ProtoWriter* ProtoWriter::RenderPrimitiveField( // Pushing a ProtoElement and then pop it off at the end for 2 purposes: // error location reporting and required field accounting. - element_.reset(new ProtoElement(element_.release(), &field, type, false)); + // + // For proto3, since there is no required field tracking, we only need to push + // ProtoElement for error cases. + if (!element_->proto3()) { + element_.reset(new ProtoElement(element_.release(), &field, type, false)); + } if (field.kind() == google::protobuf::Field_Kind_TYPE_UNKNOWN || field.kind() == google::protobuf::Field_Kind_TYPE_MESSAGE) { + // Push a ProtoElement for location reporting purposes. + if (element_->proto3()) { + element_.reset(new ProtoElement(element_.release(), &field, type, false)); + } InvalidValue(field.type_url().empty() ? google::protobuf::Field_Kind_Name(field.kind()) : field.type_url(), @@ -657,11 +670,18 @@ ProtoWriter* ProtoWriter::RenderPrimitiveField( } if (!status.ok()) { + // Push a ProtoElement for location reporting purposes. + if (element_->proto3()) { + element_.reset(new ProtoElement(element_.release(), &field, type, false)); + } InvalidValue(google::protobuf::Field_Kind_Name(field.kind()), status.error_message()); + element_.reset(element()->pop()); + return this; } - element_.reset(element()->pop()); + if (!element_->proto3()) element_.reset(element()->pop()); + return this; } diff --git a/src/google/protobuf/util/internal/proto_writer.h b/src/google/protobuf/util/internal/proto_writer.h index 8b7c6c34df..7f1108abfe 100644 --- a/src/google/protobuf/util/internal/proto_writer.h +++ b/src/google/protobuf/util/internal/proto_writer.h @@ -32,8 +32,8 @@ #define GOOGLE_PROTOBUF_UTIL_CONVERTER_PROTO_WRITER_H__ #include -#include #include +#include #include #include @@ -45,6 +45,7 @@ #include #include #include +#include namespace google { namespace protobuf { @@ -191,6 +192,8 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter { // generate an error. void TakeOneofIndex(int32 index); + bool proto3() { return proto3_; } + private: // Used for access to variables of the enclosing instance of // ProtoWriter. @@ -203,7 +206,7 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter { // TypeInfo to lookup types. const TypeInfo* typeinfo_; - // Whether the root type is a proto3 or not. + // Whether the type_ is proto3 or not. bool proto3_; // Additional variables if this element is a message: @@ -221,7 +224,7 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter { // Set of oneof indices already seen for the type_. Used to validate // incoming messages so no more than one oneof is set. - hash_set oneof_indices_; + std::vector oneof_indices_; GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(ProtoElement); }; diff --git a/src/google/protobuf/util/json_util.cc b/src/google/protobuf/util/json_util.cc index 6d45a4f95b..d7ac2dba66 100644 --- a/src/google/protobuf/util/json_util.cc +++ b/src/google/protobuf/util/json_util.cc @@ -177,6 +177,66 @@ util::Status JsonToBinaryString(TypeResolver* resolver, resolver, type_url, &input_stream, &output_stream, options); } +namespace { +const char* kTypeUrlPrefix = "type.googleapis.com"; +TypeResolver* generated_type_resolver_ = NULL; +GOOGLE_PROTOBUF_DECLARE_ONCE(generated_type_resolver_init_); + +string GetTypeUrl(const Message& message) { + return string(kTypeUrlPrefix) + "/" + message.GetDescriptor()->full_name(); +} + +void DeleteGeneratedTypeResolver() { delete generated_type_resolver_; } + +void InitGeneratedTypeResolver() { + generated_type_resolver_ = NewTypeResolverForDescriptorPool( + kTypeUrlPrefix, DescriptorPool::generated_pool()); + ::google::protobuf::internal::OnShutdown(&DeleteGeneratedTypeResolver); +} + +TypeResolver* GetGeneratedTypeResolver() { + ::google::protobuf::GoogleOnceInit(&generated_type_resolver_init_, &InitGeneratedTypeResolver); + return generated_type_resolver_; +} +} // namespace + +util::Status MessageToJsonString(const Message& message, string* output, + const JsonOptions& options) { + const DescriptorPool* pool = message.GetDescriptor()->file()->pool(); + TypeResolver* resolver = + pool == DescriptorPool::generated_pool() + ? GetGeneratedTypeResolver() + : NewTypeResolverForDescriptorPool(kTypeUrlPrefix, pool); + util::Status result = + BinaryToJsonString(resolver, GetTypeUrl(message), + message.SerializeAsString(), output, options); + if (pool != DescriptorPool::generated_pool()) { + delete resolver; + } + return result; +} + +util::Status JsonStringToMessage(const string& input, Message* message, + const JsonParseOptions& options) { + const DescriptorPool* pool = message->GetDescriptor()->file()->pool(); + TypeResolver* resolver = + pool == DescriptorPool::generated_pool() + ? GetGeneratedTypeResolver() + : NewTypeResolverForDescriptorPool(kTypeUrlPrefix, pool); + string binary; + util::Status result = JsonToBinaryString( + resolver, GetTypeUrl(*message), input, &binary, options); + if (result.ok() && !message->ParseFromString(binary)) { + result = + util::Status(util::error::INVALID_ARGUMENT, + "JSON transcoder produced invalid protobuf output."); + } + if (pool != DescriptorPool::generated_pool()) { + delete resolver; + } + return result; +} + } // namespace util } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/util/json_util.h b/src/google/protobuf/util/json_util.h index b4c2579b47..170ae91b7c 100644 --- a/src/google/protobuf/util/json_util.h +++ b/src/google/protobuf/util/json_util.h @@ -33,6 +33,7 @@ #ifndef GOOGLE_PROTOBUF_UTIL_JSON_UTIL_H__ #define GOOGLE_PROTOBUF_UTIL_JSON_UTIL_H__ +#include #include #include @@ -69,6 +70,30 @@ struct JsonPrintOptions { // DEPRECATED. Use JsonPrintOptions instead. typedef JsonPrintOptions JsonOptions; +// Converts from protobuf message to JSON. This is a simple wrapper of +// BinaryToJsonString(). It will use the DescriptorPool of the passed-in +// message to resolve Any types. +util::Status MessageToJsonString(const Message& message, + string* output, + const JsonOptions& options); + +inline util::Status MessageToJsonString(const Message& message, + string* output) { + return MessageToJsonString(message, output, JsonOptions()); +} + +// Converts from JSON to protobuf message. This is a simple wrapper of +// JsonStringToBinary(). It will use the DescriptorPool of the passed-in +// message to resolve Any types. +util::Status JsonStringToMessage(const string& input, + Message* message, + const JsonParseOptions& options); + +inline util::Status JsonStringToMessage(const string& input, + Message* message) { + return JsonStringToMessage(input, message, JsonParseOptions()); +} + // Converts protobuf binary data to JSON. // The conversion will fail if: // 1. TypeResolver fails to resolve a type. diff --git a/src/google/protobuf/util/json_util_test.cc b/src/google/protobuf/util/json_util_test.cc index c7d5c59e1d..dacac5e01a 100644 --- a/src/google/protobuf/util/json_util_test.cc +++ b/src/google/protobuf/util/json_util_test.cc @@ -34,6 +34,8 @@ #include #include +#include +#include #include #include #include @@ -63,28 +65,21 @@ static string GetTypeUrl(const Descriptor* message) { class JsonUtilTest : public testing::Test { protected: JsonUtilTest() { - resolver_.reset(NewTypeResolverForDescriptorPool( - kTypeUrlPrefix, DescriptorPool::generated_pool())); } string ToJson(const Message& message, const JsonPrintOptions& options) { string result; - GOOGLE_CHECK_OK(BinaryToJsonString(resolver_.get(), - GetTypeUrl(message.GetDescriptor()), - message.SerializeAsString(), &result, options)); + GOOGLE_CHECK_OK(MessageToJsonString(message, &result, options)); return result; } bool FromJson(const string& json, Message* message, const JsonParseOptions& options) { - string binary; - if (!JsonToBinaryString(resolver_.get(), - GetTypeUrl(message->GetDescriptor()), json, &binary, - options) - .ok()) { - return false; - } - return message->ParseFromString(binary); + return JsonStringToMessage(json, message, options).ok(); + } + + bool FromJson(const string& json, Message* message) { + return FromJson(json, message, JsonParseOptions()); } google::protobuf::scoped_ptr resolver_; @@ -189,6 +184,45 @@ TEST_F(JsonUtilTest, TestParseErrors) { EXPECT_FALSE(FromJson("{\"int32Value\":2147483648}", &m, options)); } +TEST_F(JsonUtilTest, TestDynamicMessage) { + // Some random message but good enough to test the wrapper functions. + string input = + "{\n" + " \"int32Value\": 1024,\n" + " \"repeatedInt32Value\": [1, 2],\n" + " \"messageValue\": {\n" + " \"value\": 2048\n" + " },\n" + " \"repeatedMessageValue\": [\n" + " {\"value\": 40}, {\"value\": 96}\n" + " ]\n" + "}\n"; + + // Create a new DescriptorPool with the same protos as the generated one. + DescriptorPoolDatabase database(*DescriptorPool::generated_pool()); + DescriptorPool pool(&database); + // A dynamic version of the test proto. + DynamicMessageFactory factory; + google::protobuf::scoped_ptr message(factory.GetPrototype( + pool.FindMessageTypeByName("proto3.TestMessage"))->New()); + EXPECT_TRUE(FromJson(input, message.get())); + + // Convert to generated message for easy inspection. + TestMessage generated; + EXPECT_TRUE(generated.ParseFromString(message->SerializeAsString())); + EXPECT_EQ(1024, generated.int32_value()); + ASSERT_EQ(2, generated.repeated_int32_value_size()); + EXPECT_EQ(1, generated.repeated_int32_value(0)); + EXPECT_EQ(2, generated.repeated_int32_value(1)); + EXPECT_EQ(2048, generated.message_value().value()); + ASSERT_EQ(2, generated.repeated_message_value_size()); + EXPECT_EQ(40, generated.repeated_message_value(0).value()); + EXPECT_EQ(96, generated.repeated_message_value(1).value()); + + JsonOptions options; + EXPECT_EQ(ToJson(generated, options), ToJson(*message, options)); +} + typedef pair Segment; // A ZeroCopyOutputStream that writes to multiple buffers. class SegmentedZeroCopyOutputStream : public io::ZeroCopyOutputStream { diff --git a/src/google/protobuf/wire_format_lite.cc b/src/google/protobuf/wire_format_lite.cc index f251707469..05cc0854cb 100644 --- a/src/google/protobuf/wire_format_lite.cc +++ b/src/google/protobuf/wire_format_lite.cc @@ -466,7 +466,8 @@ void WireFormatLite::WriteGroupMaybeToArray(int field_number, const int size = value.GetCachedSize(); uint8* target = output->GetDirectBufferForNBytesAndAdvance(size); if (target != NULL) { - uint8* end = value.SerializeWithCachedSizesToArray(target); + uint8* end = value.InternalSerializeWithCachedSizesToArray( + output->IsSerializationDeterminstic(), target); GOOGLE_DCHECK_EQ(end - target, size); } else { value.SerializeWithCachedSizes(output); @@ -482,7 +483,8 @@ void WireFormatLite::WriteMessageMaybeToArray(int field_number, output->WriteVarint32(size); uint8* target = output->GetDirectBufferForNBytesAndAdvance(size); if (target != NULL) { - uint8* end = value.SerializeWithCachedSizesToArray(target); + uint8* end = value.InternalSerializeWithCachedSizesToArray( + output->IsSerializationDeterminstic(), target); GOOGLE_DCHECK_EQ(end - target, size); } else { value.SerializeWithCachedSizes(output); From 443eb27c7cdf279de979fdee43c99a812cfeb001 Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Wed, 13 Jul 2016 15:37:29 -0700 Subject: [PATCH 02/18] Update generated files. --- .../Google.Protobuf/Reflection/Descriptor.cs | 6 +- src/google/protobuf/any.pb.cc | 21 +- src/google/protobuf/api.pb.cc | 37 +-- src/google/protobuf/compiler/plugin.pb.cc | 37 +-- src/google/protobuf/descriptor.pb.cc | 219 +++++++++++++----- src/google/protobuf/duration.pb.cc | 21 +- src/google/protobuf/empty.pb.cc | 21 +- src/google/protobuf/field_mask.pb.cc | 21 +- src/google/protobuf/source_context.pb.cc | 21 +- src/google/protobuf/struct.pb.cc | 156 +++++++++---- src/google/protobuf/timestamp.pb.cc | 21 +- src/google/protobuf/type.pb.cc | 53 +++-- src/google/protobuf/wrappers.pb.cc | 85 ++++--- 13 files changed, 460 insertions(+), 259 deletions(-) diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs index 7ce75739ee..83e7928a72 100644 --- a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs @@ -137,9 +137,9 @@ namespace Google.Protobuf.Reflection { "dGVkQ29kZUluZm8SQQoKYW5ub3RhdGlvbhgBIAMoCzItLmdvb2dsZS5wcm90", "b2J1Zi5HZW5lcmF0ZWRDb2RlSW5mby5Bbm5vdGF0aW9uGk8KCkFubm90YXRp", "b24SEAoEcGF0aBgBIAMoBUICEAESEwoLc291cmNlX2ZpbGUYAiABKAkSDQoF", - "YmVnaW4YAyABKAUSCwoDZW5kGAQgASgFQlgKE2NvbS5nb29nbGUucHJvdG9i", - "dWZCEERlc2NyaXB0b3JQcm90b3NIAVoKZGVzY3JpcHRvcqICA0dQQqoCGkdv", - "b2dsZS5Qcm90b2J1Zi5SZWZsZWN0aW9u")); + "YmVnaW4YAyABKAUSCwoDZW5kGAQgASgFQlsKE2NvbS5nb29nbGUucHJvdG9i", + "dWZCEERlc2NyaXB0b3JQcm90b3NIAVoKZGVzY3JpcHRvcqABAaICA0dQQqoC", + "Gkdvb2dsZS5Qcm90b2J1Zi5SZWZsZWN0aW9u")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc index c91faa08a4..ccccc9c12b 100644 --- a/src/google/protobuf/any.pb.cc +++ b/src/google/protobuf/any.pb.cc @@ -29,6 +29,7 @@ const ::google::protobuf::internal::GeneratedMessageReflection* } // namespace +void protobuf_AssignDesc_google_2fprotobuf_2fany_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AssignDesc_google_2fprotobuf_2fany_2eproto() { protobuf_AddDesc_google_2fprotobuf_2fany_2eproto(); const ::google::protobuf::FileDescriptor* file = @@ -61,6 +62,7 @@ inline void protobuf_AssignDescriptorsOnce() { &protobuf_AssignDesc_google_2fprotobuf_2fany_2eproto); } +void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( @@ -74,6 +76,7 @@ void protobuf_ShutdownFile_google_2fprotobuf_2fany_2eproto() { delete Any_reflection_; } +void protobuf_AddDesc_google_2fprotobuf_2fany_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AddDesc_google_2fprotobuf_2fany_2eproto() { static bool already_here = false; if (already_here) return; @@ -101,16 +104,6 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2fany_2eproto { } } static_descriptor_initializer_google_2fprotobuf_2fany_2eproto_; -namespace { - -static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD; -static void MergeFromFail(int line) { - GOOGLE_CHECK(false) << __FILE__ << ":" << line; -} - -} // namespace - - // =================================================================== void Any::PackFrom(const ::google::protobuf::Message& message) { @@ -334,7 +327,9 @@ int Any::ByteSize() const { void Any::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Any) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const Any* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -349,7 +344,9 @@ void Any::MergeFrom(const ::google::protobuf::Message& from) { void Any::MergeFrom(const Any& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Any) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from.type_url().size() > 0) { type_url_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.type_url_); diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc index d5dd89231f..cfb3078691 100644 --- a/src/google/protobuf/api.pb.cc +++ b/src/google/protobuf/api.pb.cc @@ -35,6 +35,7 @@ const ::google::protobuf::internal::GeneratedMessageReflection* } // namespace +void protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto() { protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto(); const ::google::protobuf::FileDescriptor* file = @@ -109,6 +110,7 @@ inline void protobuf_AssignDescriptorsOnce() { &protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto); } +void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( @@ -130,6 +132,7 @@ void protobuf_ShutdownFile_google_2fprotobuf_2fapi_2eproto() { delete Mixin_reflection_; } +void protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto() { static bool already_here = false; if (already_here) return; @@ -175,16 +178,6 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2fapi_2eproto { } } static_descriptor_initializer_google_2fprotobuf_2fapi_2eproto_; -namespace { - -static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD; -static void MergeFromFail(int line) { - GOOGLE_CHECK(false) << __FILE__ << ":" << line; -} - -} // namespace - - // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -601,7 +594,9 @@ int Api::ByteSize() const { void Api::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Api) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const Api* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -616,7 +611,9 @@ void Api::MergeFrom(const ::google::protobuf::Message& from) { void Api::MergeFrom(const Api& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Api) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } methods_.MergeFrom(from.methods_); options_.MergeFrom(from.options_); mixins_.MergeFrom(from.mixins_); @@ -1345,7 +1342,9 @@ int Method::ByteSize() const { void Method::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Method) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const Method* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -1360,7 +1359,9 @@ void Method::MergeFrom(const ::google::protobuf::Message& from) { void Method::MergeFrom(const Method& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Method) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } options_.MergeFrom(from.options_); if (from.name().size() > 0) { @@ -1858,7 +1859,9 @@ int Mixin::ByteSize() const { void Mixin::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Mixin) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const Mixin* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -1873,7 +1876,9 @@ void Mixin::MergeFrom(const ::google::protobuf::Message& from) { void Mixin::MergeFrom(const Mixin& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Mixin) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from.name().size() > 0) { name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index c4d48fc6a8..9064c38234 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -36,6 +36,7 @@ const ::google::protobuf::internal::GeneratedMessageReflection* } // namespace +void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto() { protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); const ::google::protobuf::FileDescriptor* file = @@ -102,6 +103,7 @@ inline void protobuf_AssignDescriptorsOnce() { &protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto); } +void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( @@ -123,6 +125,7 @@ void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto() { delete CodeGeneratorResponse_File_reflection_; } +void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto() { static bool already_here = false; if (already_here) return; @@ -161,16 +164,6 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2fcompiler_2fplugin_2eproto } } static_descriptor_initializer_google_2fprotobuf_2fcompiler_2fplugin_2eproto_; -namespace { - -static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD; -static void MergeFromFail(int line) { - GOOGLE_CHECK(false) << __FILE__ << ":" << line; -} - -} // namespace - - // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -451,7 +444,9 @@ int CodeGeneratorRequest::ByteSize() const { void CodeGeneratorRequest::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.compiler.CodeGeneratorRequest) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const CodeGeneratorRequest* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -466,7 +461,9 @@ void CodeGeneratorRequest::MergeFrom(const ::google::protobuf::Message& from) { void CodeGeneratorRequest::MergeFrom(const CodeGeneratorRequest& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorRequest) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } file_to_generate_.MergeFrom(from.file_to_generate_); proto_file_.MergeFrom(from.proto_file_); if (from._has_bits_[1 / 32] & (0xffu << (1 % 32))) { @@ -962,7 +959,9 @@ int CodeGeneratorResponse_File::ByteSize() const { void CodeGeneratorResponse_File::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.compiler.CodeGeneratorResponse.File) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const CodeGeneratorResponse_File* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -977,7 +976,9 @@ void CodeGeneratorResponse_File::MergeFrom(const ::google::protobuf::Message& fr void CodeGeneratorResponse_File::MergeFrom(const CodeGeneratorResponse_File& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorResponse.File) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_name()) { set_has_name(); @@ -1269,7 +1270,9 @@ int CodeGeneratorResponse::ByteSize() const { void CodeGeneratorResponse::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.compiler.CodeGeneratorResponse) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const CodeGeneratorResponse* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -1284,7 +1287,9 @@ void CodeGeneratorResponse::MergeFrom(const ::google::protobuf::Message& from) { void CodeGeneratorResponse::MergeFrom(const CodeGeneratorResponse& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorResponse) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } file_.MergeFrom(from.file_); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_error()) { diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index 4e2c9dcf33..0028c70862 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -106,6 +106,7 @@ const ::google::protobuf::internal::GeneratedMessageReflection* } // namespace +void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); const ::google::protobuf::FileDescriptor* file = @@ -588,6 +589,7 @@ inline void protobuf_AssignDescriptorsOnce() { &protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto); } +void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( @@ -697,6 +699,7 @@ void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto() { delete GeneratedCodeInfo_Annotation_reflection_; } +void protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto() { static bool already_here = false; if (already_here) return; @@ -834,9 +837,9 @@ void protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto() { ".protobuf.GeneratedCodeInfo.Annotation\032O" "\n\nAnnotation\022\020\n\004path\030\001 \003(\005B\002\020\001\022\023\n\013source" "_file\030\002 \001(\t\022\r\n\005begin\030\003 \001(\005\022\013\n\003end\030\004 \001(\005B" - "X\n\023com.google.protobufB\020DescriptorProtos" - "H\001Z\ndescriptor\242\002\003GPB\252\002\032Google.Protobuf.R" - "eflection", 5289); + "[\n\023com.google.protobufB\020DescriptorProtos" + "H\001Z\ndescriptor\240\001\001\242\002\003GPB\252\002\032Google.Protobu" + "f.Reflection", 5292); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/descriptor.proto", &protobuf_RegisterTypes); FileDescriptorSet::default_instance_ = new FileDescriptorSet(); @@ -899,16 +902,6 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2fdescriptor_2eproto { } } static_descriptor_initializer_google_2fprotobuf_2fdescriptor_2eproto_; -namespace { - -static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD; -static void MergeFromFail(int line) { - GOOGLE_CHECK(false) << __FILE__ << ":" << line; -} - -} // namespace - - // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -1088,7 +1081,9 @@ int FileDescriptorSet::ByteSize() const { void FileDescriptorSet::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.FileDescriptorSet) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const FileDescriptorSet* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -1103,7 +1098,9 @@ void FileDescriptorSet::MergeFrom(const ::google::protobuf::Message& from) { void FileDescriptorSet::MergeFrom(const FileDescriptorSet& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FileDescriptorSet) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } file_.MergeFrom(from.file_); if (from._internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->MergeFrom(from.unknown_fields()); @@ -1856,7 +1853,9 @@ int FileDescriptorProto::ByteSize() const { void FileDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.FileDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const FileDescriptorProto* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -1871,7 +1870,9 @@ void FileDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { void FileDescriptorProto::MergeFrom(const FileDescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FileDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } dependency_.MergeFrom(from.dependency_); public_dependency_.MergeFrom(from.public_dependency_); weak_dependency_.MergeFrom(from.weak_dependency_); @@ -2682,7 +2683,9 @@ int DescriptorProto_ExtensionRange::ByteSize() const { void DescriptorProto_ExtensionRange::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.DescriptorProto.ExtensionRange) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const DescriptorProto_ExtensionRange* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -2697,7 +2700,9 @@ void DescriptorProto_ExtensionRange::MergeFrom(const ::google::protobuf::Message void DescriptorProto_ExtensionRange::MergeFrom(const DescriptorProto_ExtensionRange& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DescriptorProto.ExtensionRange) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_start()) { set_start(from.start()); @@ -2981,7 +2986,9 @@ int DescriptorProto_ReservedRange::ByteSize() const { void DescriptorProto_ReservedRange::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.DescriptorProto.ReservedRange) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const DescriptorProto_ReservedRange* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -2996,7 +3003,9 @@ void DescriptorProto_ReservedRange::MergeFrom(const ::google::protobuf::Message& void DescriptorProto_ReservedRange::MergeFrom(const DescriptorProto_ReservedRange& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DescriptorProto.ReservedRange) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_start()) { set_start(from.start()); @@ -3608,7 +3617,9 @@ int DescriptorProto::ByteSize() const { void DescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.DescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const DescriptorProto* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -3623,7 +3634,9 @@ void DescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { void DescriptorProto::MergeFrom(const DescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } field_.MergeFrom(from.field_); extension_.MergeFrom(from.extension_); nested_type_.MergeFrom(from.nested_type_); @@ -4844,7 +4857,9 @@ int FieldDescriptorProto::ByteSize() const { void FieldDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.FieldDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const FieldDescriptorProto* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -4859,7 +4874,9 @@ void FieldDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { void FieldDescriptorProto::MergeFrom(const FieldDescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_name()) { set_has_name(); @@ -5606,7 +5623,9 @@ int OneofDescriptorProto::ByteSize() const { void OneofDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.OneofDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const OneofDescriptorProto* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -5621,7 +5640,9 @@ void OneofDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { void OneofDescriptorProto::MergeFrom(const OneofDescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.OneofDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_name()) { set_has_name(); @@ -6056,7 +6077,9 @@ int EnumDescriptorProto::ByteSize() const { void EnumDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.EnumDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const EnumDescriptorProto* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -6071,7 +6094,9 @@ void EnumDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { void EnumDescriptorProto::MergeFrom(const EnumDescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } value_.MergeFrom(from.value_); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_name()) { @@ -6534,7 +6559,9 @@ int EnumValueDescriptorProto::ByteSize() const { void EnumValueDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.EnumValueDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const EnumValueDescriptorProto* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -6549,7 +6576,9 @@ void EnumValueDescriptorProto::MergeFrom(const ::google::protobuf::Message& from void EnumValueDescriptorProto::MergeFrom(const EnumValueDescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumValueDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_name()) { set_has_name(); @@ -7012,7 +7041,9 @@ int ServiceDescriptorProto::ByteSize() const { void ServiceDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.ServiceDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const ServiceDescriptorProto* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -7027,7 +7058,9 @@ void ServiceDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) void ServiceDescriptorProto::MergeFrom(const ServiceDescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ServiceDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } method_.MergeFrom(from.method_); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_name()) { @@ -7642,7 +7675,9 @@ int MethodDescriptorProto::ByteSize() const { void MethodDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.MethodDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const MethodDescriptorProto* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -7657,7 +7692,9 @@ void MethodDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { void MethodDescriptorProto::MergeFrom(const MethodDescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.MethodDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_name()) { set_has_name(); @@ -8792,7 +8829,9 @@ int FileOptions::ByteSize() const { void FileOptions::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.FileOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const FileOptions* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -8807,7 +8846,9 @@ void FileOptions::MergeFrom(const ::google::protobuf::Message& from) { void FileOptions::MergeFrom(const FileOptions& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FileOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } uninterpreted_option_.MergeFrom(from.uninterpreted_option_); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_java_package()) { @@ -9789,7 +9830,9 @@ int MessageOptions::ByteSize() const { void MessageOptions::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.MessageOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const MessageOptions* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -9804,7 +9847,9 @@ void MessageOptions::MergeFrom(const ::google::protobuf::Message& from) { void MessageOptions::MergeFrom(const MessageOptions& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.MessageOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } uninterpreted_option_.MergeFrom(from.uninterpreted_option_); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_message_set_wire_format()) { @@ -10477,7 +10522,9 @@ int FieldOptions::ByteSize() const { void FieldOptions::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.FieldOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const FieldOptions* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -10492,7 +10539,9 @@ void FieldOptions::MergeFrom(const ::google::protobuf::Message& from) { void FieldOptions::MergeFrom(const FieldOptions& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } uninterpreted_option_.MergeFrom(from.uninterpreted_option_); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_ctype()) { @@ -10943,7 +10992,9 @@ int OneofOptions::ByteSize() const { void OneofOptions::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.OneofOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const OneofOptions* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -10958,7 +11009,9 @@ void OneofOptions::MergeFrom(const ::google::protobuf::Message& from) { void OneofOptions::MergeFrom(const OneofOptions& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.OneofOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } uninterpreted_option_.MergeFrom(from.uninterpreted_option_); _extensions_.MergeFrom(from._extensions_); if (from._internal_metadata_.have_unknown_fields()) { @@ -11324,7 +11377,9 @@ int EnumOptions::ByteSize() const { void EnumOptions::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.EnumOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const EnumOptions* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -11339,7 +11394,9 @@ void EnumOptions::MergeFrom(const ::google::protobuf::Message& from) { void EnumOptions::MergeFrom(const EnumOptions& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } uninterpreted_option_.MergeFrom(from.uninterpreted_option_); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_allow_alias()) { @@ -11709,7 +11766,9 @@ int EnumValueOptions::ByteSize() const { void EnumValueOptions::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.EnumValueOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const EnumValueOptions* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -11724,7 +11783,9 @@ void EnumValueOptions::MergeFrom(const ::google::protobuf::Message& from) { void EnumValueOptions::MergeFrom(const EnumValueOptions& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumValueOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } uninterpreted_option_.MergeFrom(from.uninterpreted_option_); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_deprecated()) { @@ -12066,7 +12127,9 @@ int ServiceOptions::ByteSize() const { void ServiceOptions::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.ServiceOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const ServiceOptions* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -12081,7 +12144,9 @@ void ServiceOptions::MergeFrom(const ::google::protobuf::Message& from) { void ServiceOptions::MergeFrom(const ServiceOptions& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ServiceOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } uninterpreted_option_.MergeFrom(from.uninterpreted_option_); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_deprecated()) { @@ -12423,7 +12488,9 @@ int MethodOptions::ByteSize() const { void MethodOptions::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.MethodOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const MethodOptions* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -12438,7 +12505,9 @@ void MethodOptions::MergeFrom(const ::google::protobuf::Message& from) { void MethodOptions::MergeFrom(const MethodOptions& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.MethodOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } uninterpreted_option_.MergeFrom(from.uninterpreted_option_); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_deprecated()) { @@ -12796,7 +12865,9 @@ int UninterpretedOption_NamePart::ByteSize() const { void UninterpretedOption_NamePart::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.UninterpretedOption.NamePart) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const UninterpretedOption_NamePart* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -12811,7 +12882,9 @@ void UninterpretedOption_NamePart::MergeFrom(const ::google::protobuf::Message& void UninterpretedOption_NamePart::MergeFrom(const UninterpretedOption_NamePart& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UninterpretedOption.NamePart) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_name_part()) { set_has_name_part(); @@ -13313,7 +13386,9 @@ int UninterpretedOption::ByteSize() const { void UninterpretedOption::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.UninterpretedOption) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const UninterpretedOption* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -13328,7 +13403,9 @@ void UninterpretedOption::MergeFrom(const ::google::protobuf::Message& from) { void UninterpretedOption::MergeFrom(const UninterpretedOption& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UninterpretedOption) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } name_.MergeFrom(from.name_); if (from._has_bits_[1 / 32] & (0xffu << (1 % 32))) { if (from.has_identifier_value()) { @@ -14170,7 +14247,9 @@ int SourceCodeInfo_Location::ByteSize() const { void SourceCodeInfo_Location::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.SourceCodeInfo.Location) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const SourceCodeInfo_Location* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -14185,7 +14264,9 @@ void SourceCodeInfo_Location::MergeFrom(const ::google::protobuf::Message& from) void SourceCodeInfo_Location::MergeFrom(const SourceCodeInfo_Location& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.SourceCodeInfo.Location) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } path_.MergeFrom(from.path_); span_.MergeFrom(from.span_); leading_detached_comments_.MergeFrom(from.leading_detached_comments_); @@ -14426,7 +14507,9 @@ int SourceCodeInfo::ByteSize() const { void SourceCodeInfo::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.SourceCodeInfo) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const SourceCodeInfo* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -14441,7 +14524,9 @@ void SourceCodeInfo::MergeFrom(const ::google::protobuf::Message& from) { void SourceCodeInfo::MergeFrom(const SourceCodeInfo& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.SourceCodeInfo) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } location_.MergeFrom(from.location_); if (from._internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->MergeFrom(from.unknown_fields()); @@ -15093,7 +15178,9 @@ int GeneratedCodeInfo_Annotation::ByteSize() const { void GeneratedCodeInfo_Annotation::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.GeneratedCodeInfo.Annotation) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const GeneratedCodeInfo_Annotation* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -15108,7 +15195,9 @@ void GeneratedCodeInfo_Annotation::MergeFrom(const ::google::protobuf::Message& void GeneratedCodeInfo_Annotation::MergeFrom(const GeneratedCodeInfo_Annotation& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.GeneratedCodeInfo.Annotation) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } path_.MergeFrom(from.path_); if (from._has_bits_[1 / 32] & (0xffu << (1 % 32))) { if (from.has_source_file()) { @@ -15348,7 +15437,9 @@ int GeneratedCodeInfo::ByteSize() const { void GeneratedCodeInfo::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.GeneratedCodeInfo) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const GeneratedCodeInfo* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -15363,7 +15454,9 @@ void GeneratedCodeInfo::MergeFrom(const ::google::protobuf::Message& from) { void GeneratedCodeInfo::MergeFrom(const GeneratedCodeInfo& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.GeneratedCodeInfo) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } annotation_.MergeFrom(from.annotation_); if (from._internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->MergeFrom(from.unknown_fields()); diff --git a/src/google/protobuf/duration.pb.cc b/src/google/protobuf/duration.pb.cc index b0c641bfcf..94ece18ea4 100644 --- a/src/google/protobuf/duration.pb.cc +++ b/src/google/protobuf/duration.pb.cc @@ -29,6 +29,7 @@ const ::google::protobuf::internal::GeneratedMessageReflection* } // namespace +void protobuf_AssignDesc_google_2fprotobuf_2fduration_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AssignDesc_google_2fprotobuf_2fduration_2eproto() { protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto(); const ::google::protobuf::FileDescriptor* file = @@ -61,6 +62,7 @@ inline void protobuf_AssignDescriptorsOnce() { &protobuf_AssignDesc_google_2fprotobuf_2fduration_2eproto); } +void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( @@ -74,6 +76,7 @@ void protobuf_ShutdownFile_google_2fprotobuf_2fduration_2eproto() { delete Duration_reflection_; } +void protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto() { static bool already_here = false; if (already_here) return; @@ -101,16 +104,6 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2fduration_2eproto { } } static_descriptor_initializer_google_2fprotobuf_2fduration_2eproto_; -namespace { - -static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD; -static void MergeFromFail(int line) { - GOOGLE_CHECK(false) << __FILE__ << ":" << line; -} - -} // namespace - - // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -322,7 +315,9 @@ int Duration::ByteSize() const { void Duration::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Duration) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const Duration* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -337,7 +332,9 @@ void Duration::MergeFrom(const ::google::protobuf::Message& from) { void Duration::MergeFrom(const Duration& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Duration) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from.seconds() != 0) { set_seconds(from.seconds()); } diff --git a/src/google/protobuf/empty.pb.cc b/src/google/protobuf/empty.pb.cc index 8b46120110..83775753ad 100644 --- a/src/google/protobuf/empty.pb.cc +++ b/src/google/protobuf/empty.pb.cc @@ -29,6 +29,7 @@ const ::google::protobuf::internal::GeneratedMessageReflection* } // namespace +void protobuf_AssignDesc_google_2fprotobuf_2fempty_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AssignDesc_google_2fprotobuf_2fempty_2eproto() { protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto(); const ::google::protobuf::FileDescriptor* file = @@ -59,6 +60,7 @@ inline void protobuf_AssignDescriptorsOnce() { &protobuf_AssignDesc_google_2fprotobuf_2fempty_2eproto); } +void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( @@ -72,6 +74,7 @@ void protobuf_ShutdownFile_google_2fprotobuf_2fempty_2eproto() { delete Empty_reflection_; } +void protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto() { static bool already_here = false; if (already_here) return; @@ -98,16 +101,6 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2fempty_2eproto { } } static_descriptor_initializer_google_2fprotobuf_2fempty_2eproto_; -namespace { - -static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD; -static void MergeFromFail(int line) { - GOOGLE_CHECK(false) << __FILE__ << ":" << line; -} - -} // namespace - - // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -240,7 +233,9 @@ int Empty::ByteSize() const { void Empty::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Empty) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const Empty* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -255,7 +250,9 @@ void Empty::MergeFrom(const ::google::protobuf::Message& from) { void Empty::MergeFrom(const Empty& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Empty) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } } void Empty::CopyFrom(const ::google::protobuf::Message& from) { diff --git a/src/google/protobuf/field_mask.pb.cc b/src/google/protobuf/field_mask.pb.cc index d197b4060a..ed05fe575b 100644 --- a/src/google/protobuf/field_mask.pb.cc +++ b/src/google/protobuf/field_mask.pb.cc @@ -29,6 +29,7 @@ const ::google::protobuf::internal::GeneratedMessageReflection* } // namespace +void protobuf_AssignDesc_google_2fprotobuf_2ffield_5fmask_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AssignDesc_google_2fprotobuf_2ffield_5fmask_2eproto() { protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto(); const ::google::protobuf::FileDescriptor* file = @@ -60,6 +61,7 @@ inline void protobuf_AssignDescriptorsOnce() { &protobuf_AssignDesc_google_2fprotobuf_2ffield_5fmask_2eproto); } +void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( @@ -73,6 +75,7 @@ void protobuf_ShutdownFile_google_2fprotobuf_2ffield_5fmask_2eproto() { delete FieldMask_reflection_; } +void protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto() { static bool already_here = false; if (already_here) return; @@ -99,16 +102,6 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2ffield_5fmask_2eproto { } } static_descriptor_initializer_google_2fprotobuf_2ffield_5fmask_2eproto_; -namespace { - -static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD; -static void MergeFromFail(int line) { - GOOGLE_CHECK(false) << __FILE__ << ":" << line; -} - -} // namespace - - // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -281,7 +274,9 @@ int FieldMask::ByteSize() const { void FieldMask::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.FieldMask) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const FieldMask* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -296,7 +291,9 @@ void FieldMask::MergeFrom(const ::google::protobuf::Message& from) { void FieldMask::MergeFrom(const FieldMask& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldMask) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } paths_.MergeFrom(from.paths_); } diff --git a/src/google/protobuf/source_context.pb.cc b/src/google/protobuf/source_context.pb.cc index 4d8e77ce38..5cc77bf34a 100644 --- a/src/google/protobuf/source_context.pb.cc +++ b/src/google/protobuf/source_context.pb.cc @@ -29,6 +29,7 @@ const ::google::protobuf::internal::GeneratedMessageReflection* } // namespace +void protobuf_AssignDesc_google_2fprotobuf_2fsource_5fcontext_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AssignDesc_google_2fprotobuf_2fsource_5fcontext_2eproto() { protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto(); const ::google::protobuf::FileDescriptor* file = @@ -60,6 +61,7 @@ inline void protobuf_AssignDescriptorsOnce() { &protobuf_AssignDesc_google_2fprotobuf_2fsource_5fcontext_2eproto); } +void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( @@ -73,6 +75,7 @@ void protobuf_ShutdownFile_google_2fprotobuf_2fsource_5fcontext_2eproto() { delete SourceContext_reflection_; } +void protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto() { static bool already_here = false; if (already_here) return; @@ -99,16 +102,6 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2fsource_5fcontext_2eproto } } static_descriptor_initializer_google_2fprotobuf_2fsource_5fcontext_2eproto_; -namespace { - -static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD; -static void MergeFromFail(int line) { - GOOGLE_CHECK(false) << __FILE__ << ":" << line; -} - -} // namespace - - // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -281,7 +274,9 @@ int SourceContext::ByteSize() const { void SourceContext::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.SourceContext) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const SourceContext* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -296,7 +291,9 @@ void SourceContext::MergeFrom(const ::google::protobuf::Message& from) { void SourceContext::MergeFrom(const SourceContext& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.SourceContext) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from.file_name().size() > 0) { file_name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.file_name_); diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc index dd6b78d198..a551384cfd 100644 --- a/src/google/protobuf/struct.pb.cc +++ b/src/google/protobuf/struct.pb.cc @@ -45,6 +45,7 @@ const ::google::protobuf::EnumDescriptor* NullValue_descriptor_ = NULL; } // namespace +void protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto() { protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto(); const ::google::protobuf::FileDescriptor* file = @@ -116,6 +117,7 @@ inline void protobuf_AssignDescriptorsOnce() { &protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto); } +void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( @@ -147,6 +149,7 @@ void protobuf_ShutdownFile_google_2fprotobuf_2fstruct_2eproto() { delete ListValue_reflection_; } +void protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto() { static bool already_here = false; if (already_here) return; @@ -203,16 +206,6 @@ bool NullValue_IsValid(int value) { } -namespace { - -static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD; -static void MergeFromFail(int line) { - GOOGLE_CHECK(false) << __FILE__ << ":" << line; -} - -} // namespace - - // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -348,18 +341,51 @@ void Struct::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // @@protoc_insertion_point(serialize_start:google.protobuf.Struct) // map fields = 1; - { - ::google::protobuf::scoped_ptr entry; - for (::google::protobuf::Map< ::std::string, ::google::protobuf::Value >::const_iterator - it = this->fields().begin(); - it != this->fields().end(); ++it) { - entry.reset(fields_.NewEntryWrapper(it->first, it->second)); - ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( - 1, *entry, output); - ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( - it->first.data(), it->first.length(), - ::google::protobuf::internal::WireFormatLite::SERIALIZE, - "google.protobuf.Struct.FieldsEntry.key"); + if (!this->fields().empty()) { + typedef ::google::protobuf::Map< ::std::string, ::google::protobuf::Value >::const_pointer + ConstPtr; + typedef ConstPtr SortItem; + typedef ::google::protobuf::internal::CompareByDerefFirst Less; + struct Utf8Check { + static void Check(ConstPtr p) { + ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + p->first.data(), p->first.length(), + ::google::protobuf::internal::WireFormatLite::SERIALIZE, + "google.protobuf.Struct.FieldsEntry.key"); + } + }; + + if (output->IsSerializationDeterminstic() && + this->fields().size() > 1) { + ::google::protobuf::scoped_array items( + new SortItem[this->fields().size()]); + typedef ::google::protobuf::Map< ::std::string, ::google::protobuf::Value >::size_type size_type; + size_type n = 0; + for (::google::protobuf::Map< ::std::string, ::google::protobuf::Value >::const_iterator + it = this->fields().begin(); + it != this->fields().end(); ++it, ++n) { + items[n] = SortItem(&*it); + } + ::std::sort(&items[0], &items[n], Less()); + ::google::protobuf::scoped_ptr entry; + for (size_type i = 0; i < n; i++) { + entry.reset(fields_.NewEntryWrapper( + items[i]->first, items[i]->second)); + ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( + 1, *entry, output); + Utf8Check::Check(items[i]); + } + } else { + ::google::protobuf::scoped_ptr entry; + for (::google::protobuf::Map< ::std::string, ::google::protobuf::Value >::const_iterator + it = this->fields().begin(); + it != this->fields().end(); ++it) { + entry.reset(fields_.NewEntryWrapper( + it->first, it->second)); + ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( + 1, *entry, output); + Utf8Check::Check(&*it); + } } } @@ -370,19 +396,55 @@ void Struct::SerializeWithCachedSizes( bool deterministic, ::google::protobuf::uint8* target) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Struct) // map fields = 1; - { - ::google::protobuf::scoped_ptr entry; - for (::google::protobuf::Map< ::std::string, ::google::protobuf::Value >::const_iterator - it = this->fields().begin(); - it != this->fields().end(); ++it) { - entry.reset(fields_.NewEntryWrapper(it->first, it->second)); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( - 1, *entry, false, target); - ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( - it->first.data(), it->first.length(), - ::google::protobuf::internal::WireFormatLite::SERIALIZE, - "google.protobuf.Struct.FieldsEntry.key"); + if (!this->fields().empty()) { + typedef ::google::protobuf::Map< ::std::string, ::google::protobuf::Value >::const_pointer + ConstPtr; + typedef ConstPtr SortItem; + typedef ::google::protobuf::internal::CompareByDerefFirst Less; + struct Utf8Check { + static void Check(ConstPtr p) { + ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + p->first.data(), p->first.length(), + ::google::protobuf::internal::WireFormatLite::SERIALIZE, + "google.protobuf.Struct.FieldsEntry.key"); + } + }; + + if (deterministic && + this->fields().size() > 1) { + ::google::protobuf::scoped_array items( + new SortItem[this->fields().size()]); + typedef ::google::protobuf::Map< ::std::string, ::google::protobuf::Value >::size_type size_type; + size_type n = 0; + for (::google::protobuf::Map< ::std::string, ::google::protobuf::Value >::const_iterator + it = this->fields().begin(); + it != this->fields().end(); ++it, ++n) { + items[n] = SortItem(&*it); + } + ::std::sort(&items[0], &items[n], Less()); + ::google::protobuf::scoped_ptr entry; + for (size_type i = 0; i < n; i++) { + entry.reset(fields_.NewEntryWrapper( + items[i]->first, items[i]->second)); + target = ::google::protobuf::internal::WireFormatLite:: + InternalWriteMessageNoVirtualToArray( + 1, *entry, deterministic, target); +; + Utf8Check::Check(items[i]); + } + } else { + ::google::protobuf::scoped_ptr entry; + for (::google::protobuf::Map< ::std::string, ::google::protobuf::Value >::const_iterator + it = this->fields().begin(); + it != this->fields().end(); ++it) { + entry.reset(fields_.NewEntryWrapper( + it->first, it->second)); + target = ::google::protobuf::internal::WireFormatLite:: + InternalWriteMessageNoVirtualToArray( + 1, *entry, deterministic, target); +; + Utf8Check::Check(&*it); + } } } @@ -415,7 +477,9 @@ int Struct::ByteSize() const { void Struct::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Struct) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const Struct* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -430,7 +494,9 @@ void Struct::MergeFrom(const ::google::protobuf::Message& from) { void Struct::MergeFrom(const Struct& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Struct) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } fields_.MergeFrom(from.fields_); } @@ -881,7 +947,9 @@ int Value::ByteSize() const { void Value::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Value) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const Value* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -896,7 +964,9 @@ void Value::MergeFrom(const ::google::protobuf::Message& from) { void Value::MergeFrom(const Value& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Value) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } switch (from.kind_case()) { case kNullValue: { set_null_value(from.null_value()); @@ -1406,7 +1476,9 @@ int ListValue::ByteSize() const { void ListValue::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.ListValue) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const ListValue* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -1421,7 +1493,9 @@ void ListValue::MergeFrom(const ::google::protobuf::Message& from) { void ListValue::MergeFrom(const ListValue& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ListValue) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } values_.MergeFrom(from.values_); } diff --git a/src/google/protobuf/timestamp.pb.cc b/src/google/protobuf/timestamp.pb.cc index 2ec4bc56f8..542e5ed7e4 100644 --- a/src/google/protobuf/timestamp.pb.cc +++ b/src/google/protobuf/timestamp.pb.cc @@ -29,6 +29,7 @@ const ::google::protobuf::internal::GeneratedMessageReflection* } // namespace +void protobuf_AssignDesc_google_2fprotobuf_2ftimestamp_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AssignDesc_google_2fprotobuf_2ftimestamp_2eproto() { protobuf_AddDesc_google_2fprotobuf_2ftimestamp_2eproto(); const ::google::protobuf::FileDescriptor* file = @@ -61,6 +62,7 @@ inline void protobuf_AssignDescriptorsOnce() { &protobuf_AssignDesc_google_2fprotobuf_2ftimestamp_2eproto); } +void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( @@ -74,6 +76,7 @@ void protobuf_ShutdownFile_google_2fprotobuf_2ftimestamp_2eproto() { delete Timestamp_reflection_; } +void protobuf_AddDesc_google_2fprotobuf_2ftimestamp_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AddDesc_google_2fprotobuf_2ftimestamp_2eproto() { static bool already_here = false; if (already_here) return; @@ -101,16 +104,6 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2ftimestamp_2eproto { } } static_descriptor_initializer_google_2fprotobuf_2ftimestamp_2eproto_; -namespace { - -static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD; -static void MergeFromFail(int line) { - GOOGLE_CHECK(false) << __FILE__ << ":" << line; -} - -} // namespace - - // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -336,7 +329,9 @@ int Timestamp::ByteSize() const { void Timestamp::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Timestamp) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const Timestamp* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -351,7 +346,9 @@ void Timestamp::MergeFrom(const ::google::protobuf::Message& from) { void Timestamp::MergeFrom(const Timestamp& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Timestamp) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from.seconds() != 0) { set_seconds(from.seconds()); } diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc index f9182a7577..7ba909ef1c 100644 --- a/src/google/protobuf/type.pb.cc +++ b/src/google/protobuf/type.pb.cc @@ -44,6 +44,7 @@ const ::google::protobuf::EnumDescriptor* Syntax_descriptor_ = NULL; } // namespace +void protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto() { protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto(); const ::google::protobuf::FileDescriptor* file = @@ -159,6 +160,7 @@ inline void protobuf_AssignDescriptorsOnce() { &protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto); } +void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( @@ -188,6 +190,7 @@ void protobuf_ShutdownFile_google_2fprotobuf_2ftype_2eproto() { delete Option_reflection_; } +void protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto() { static bool already_here = false; if (already_here) return; @@ -272,16 +275,6 @@ bool Syntax_IsValid(int value) { } -namespace { - -static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD; -static void MergeFromFail(int line) { - GOOGLE_CHECK(false) << __FILE__ << ":" << line; -} - -} // namespace - - // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -658,7 +651,9 @@ int Type::ByteSize() const { void Type::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Type) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const Type* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -673,7 +668,9 @@ void Type::MergeFrom(const ::google::protobuf::Message& from) { void Type::MergeFrom(const Type& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Type) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } fields_.MergeFrom(from.fields_); oneofs_.MergeFrom(from.oneofs_); options_.MergeFrom(from.options_); @@ -1581,7 +1578,9 @@ int Field::ByteSize() const { void Field::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Field) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const Field* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -1596,7 +1595,9 @@ void Field::MergeFrom(const ::google::protobuf::Message& from) { void Field::MergeFrom(const Field& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Field) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } options_.MergeFrom(from.options_); if (from.kind() != 0) { set_kind(from.kind()); @@ -2285,7 +2286,9 @@ int Enum::ByteSize() const { void Enum::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Enum) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const Enum* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -2300,7 +2303,9 @@ void Enum::MergeFrom(const ::google::protobuf::Message& from) { void Enum::MergeFrom(const Enum& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Enum) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } enumvalue_.MergeFrom(from.enumvalue_); options_.MergeFrom(from.options_); if (from.name().size() > 0) { @@ -2764,7 +2769,9 @@ int EnumValue::ByteSize() const { void EnumValue::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.EnumValue) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const EnumValue* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -2779,7 +2786,9 @@ void EnumValue::MergeFrom(const ::google::protobuf::Message& from) { void EnumValue::MergeFrom(const EnumValue& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumValue) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } options_.MergeFrom(from.options_); if (from.name().size() > 0) { @@ -3133,7 +3142,9 @@ int Option::ByteSize() const { void Option::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Option) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const Option* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -3148,7 +3159,9 @@ void Option::MergeFrom(const ::google::protobuf::Message& from) { void Option::MergeFrom(const Option& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Option) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from.name().size() > 0) { name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); diff --git a/src/google/protobuf/wrappers.pb.cc b/src/google/protobuf/wrappers.pb.cc index 08490f3f14..33a69d3b18 100644 --- a/src/google/protobuf/wrappers.pb.cc +++ b/src/google/protobuf/wrappers.pb.cc @@ -53,6 +53,7 @@ const ::google::protobuf::internal::GeneratedMessageReflection* } // namespace +void protobuf_AssignDesc_google_2fprotobuf_2fwrappers_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AssignDesc_google_2fprotobuf_2fwrappers_2eproto() { protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto(); const ::google::protobuf::FileDescriptor* file = @@ -204,6 +205,7 @@ inline void protobuf_AssignDescriptorsOnce() { &protobuf_AssignDesc_google_2fprotobuf_2fwrappers_2eproto); } +void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( @@ -249,6 +251,7 @@ void protobuf_ShutdownFile_google_2fprotobuf_2fwrappers_2eproto() { delete BytesValue_reflection_; } +void protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto() GOOGLE_ATTRIBUTE_COLD; void protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto() { static bool already_here = false; if (already_here) return; @@ -298,16 +301,6 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2fwrappers_2eproto { } } static_descriptor_initializer_google_2fprotobuf_2fwrappers_2eproto_; -namespace { - -static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD; -static void MergeFromFail(int line) { - GOOGLE_CHECK(false) << __FILE__ << ":" << line; -} - -} // namespace - - // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -477,7 +470,9 @@ int DoubleValue::ByteSize() const { void DoubleValue::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.DoubleValue) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const DoubleValue* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -492,7 +487,9 @@ void DoubleValue::MergeFrom(const ::google::protobuf::Message& from) { void DoubleValue::MergeFrom(const DoubleValue& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DoubleValue) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from.value() != 0) { set_value(from.value()); } @@ -735,7 +732,9 @@ int FloatValue::ByteSize() const { void FloatValue::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.FloatValue) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const FloatValue* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -750,7 +749,9 @@ void FloatValue::MergeFrom(const ::google::protobuf::Message& from) { void FloatValue::MergeFrom(const FloatValue& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FloatValue) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from.value() != 0) { set_value(from.value()); } @@ -995,7 +996,9 @@ int Int64Value::ByteSize() const { void Int64Value::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Int64Value) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const Int64Value* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -1010,7 +1013,9 @@ void Int64Value::MergeFrom(const ::google::protobuf::Message& from) { void Int64Value::MergeFrom(const Int64Value& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Int64Value) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from.value() != 0) { set_value(from.value()); } @@ -1255,7 +1260,9 @@ int UInt64Value::ByteSize() const { void UInt64Value::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.UInt64Value) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const UInt64Value* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -1270,7 +1277,9 @@ void UInt64Value::MergeFrom(const ::google::protobuf::Message& from) { void UInt64Value::MergeFrom(const UInt64Value& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UInt64Value) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from.value() != 0) { set_value(from.value()); } @@ -1515,7 +1524,9 @@ int Int32Value::ByteSize() const { void Int32Value::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Int32Value) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const Int32Value* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -1530,7 +1541,9 @@ void Int32Value::MergeFrom(const ::google::protobuf::Message& from) { void Int32Value::MergeFrom(const Int32Value& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Int32Value) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from.value() != 0) { set_value(from.value()); } @@ -1775,7 +1788,9 @@ int UInt32Value::ByteSize() const { void UInt32Value::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.UInt32Value) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const UInt32Value* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -1790,7 +1805,9 @@ void UInt32Value::MergeFrom(const ::google::protobuf::Message& from) { void UInt32Value::MergeFrom(const UInt32Value& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UInt32Value) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from.value() != 0) { set_value(from.value()); } @@ -2033,7 +2050,9 @@ int BoolValue::ByteSize() const { void BoolValue::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.BoolValue) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const BoolValue* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -2048,7 +2067,9 @@ void BoolValue::MergeFrom(const ::google::protobuf::Message& from) { void BoolValue::MergeFrom(const BoolValue& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.BoolValue) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from.value() != 0) { set_value(from.value()); } @@ -2308,7 +2329,9 @@ int StringValue::ByteSize() const { void StringValue::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.StringValue) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const StringValue* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -2323,7 +2346,9 @@ void StringValue::MergeFrom(const ::google::protobuf::Message& from) { void StringValue::MergeFrom(const StringValue& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.StringValue) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from.value().size() > 0) { set_value(from.value()); } @@ -2623,7 +2648,9 @@ int BytesValue::ByteSize() const { void BytesValue::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.BytesValue) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } const BytesValue* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); @@ -2638,7 +2665,9 @@ void BytesValue::MergeFrom(const ::google::protobuf::Message& from) { void BytesValue::MergeFrom(const BytesValue& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.BytesValue) - if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + if (GOOGLE_PREDICT_FALSE(&from == this)) { + ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + } if (from.value().size() > 0) { set_value(from.value()); } From 7a7913e442f91a84518bcc916dc3e5f928014f1e Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Wed, 13 Jul 2016 15:45:08 -0700 Subject: [PATCH 03/18] Add missing LIBPROTOBUF_EXPORT. --- src/google/protobuf/generated_message_util.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/google/protobuf/generated_message_util.h b/src/google/protobuf/generated_message_util.h index dc81518914..8967726e77 100644 --- a/src/google/protobuf/generated_message_util.h +++ b/src/google/protobuf/generated_message_util.h @@ -112,12 +112,13 @@ class ArenaString; // pointer to a copy of the string that resides in *arena. Requires both // args to be non-NULL. If something goes wrong while reading the data // then NULL is returned (e.g., input does not start with a valid varint). -ArenaString* ReadArenaString(::google::protobuf::io::CodedInputStream* input, - ::google::protobuf::Arena* arena); +LIBPROTOBUF_EXPORT ArenaString* ReadArenaString( + ::google::protobuf::io::CodedInputStream* input, + ::google::protobuf::Arena* arena); // Helper function to crash on merge failure. // Moved out of generated code to reduce binary size. -void MergeFromFail(const char* file, int line) GOOGLE_ATTRIBUTE_NORETURN; +LIBPROTOBUF_EXPORT void MergeFromFail(const char* file, int line) GOOGLE_ATTRIBUTE_NORETURN; } // namespace internal } // namespace protobuf From 06a02488ce326e4e4dc0c1bd3d66853c5de88d73 Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Wed, 13 Jul 2016 16:05:50 -0700 Subject: [PATCH 04/18] Add missing LIBPROTOBUF_EXPORT --- src/google/protobuf/util/json_util.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/google/protobuf/util/json_util.h b/src/google/protobuf/util/json_util.h index 170ae91b7c..6d3cee5281 100644 --- a/src/google/protobuf/util/json_util.h +++ b/src/google/protobuf/util/json_util.h @@ -73,7 +73,7 @@ typedef JsonPrintOptions JsonOptions; // Converts from protobuf message to JSON. This is a simple wrapper of // BinaryToJsonString(). It will use the DescriptorPool of the passed-in // message to resolve Any types. -util::Status MessageToJsonString(const Message& message, +LIBPROTOBUF_EXPORT util::Status MessageToJsonString(const Message& message, string* output, const JsonOptions& options); @@ -85,7 +85,7 @@ inline util::Status MessageToJsonString(const Message& message, // Converts from JSON to protobuf message. This is a simple wrapper of // JsonStringToBinary(). It will use the DescriptorPool of the passed-in // message to resolve Any types. -util::Status JsonStringToMessage(const string& input, +LIBPROTOBUF_EXPORT util::Status JsonStringToMessage(const string& input, Message* message, const JsonParseOptions& options); @@ -100,7 +100,7 @@ inline util::Status JsonStringToMessage(const string& input, // 2. input is not valid protobuf wire format, or conflicts with the type // information returned by TypeResolver. // Note that unknown fields will be discarded silently. -util::Status BinaryToJsonStream( +LIBPROTOBUF_EXPORT util::Status BinaryToJsonStream( TypeResolver* resolver, const string& type_url, io::ZeroCopyInputStream* binary_input, @@ -135,7 +135,7 @@ inline util::Status BinaryToJsonString(TypeResolver* resolver, // 1. TypeResolver fails to resolve a type. // 2. input is not valid JSON format, or conflicts with the type // information returned by TypeResolver. -util::Status JsonToBinaryStream( +LIBPROTOBUF_EXPORT util::Status JsonToBinaryStream( TypeResolver* resolver, const string& type_url, io::ZeroCopyInputStream* json_input, From 932f94e16e946382f49db2027e71d02c3617afcb Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Wed, 13 Jul 2016 15:56:53 -0700 Subject: [PATCH 05/18] Update version number to 3.0.0-beta-4 --- Protobuf.podspec | 2 +- configure.ac | 2 +- csharp/Google.Protobuf.Tools.nuspec | 2 +- csharp/src/Google.Protobuf/Google.Protobuf.nuspec | 4 ++-- java/core/pom.xml | 2 +- java/lite/pom.xml | 2 +- java/pom.xml | 2 +- java/util/pom.xml | 2 +- javanano/pom.xml | 4 ++-- js/package.json | 2 +- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/google-protobuf.gemspec | 2 +- ruby/pom.xml | 2 +- 14 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Protobuf.podspec b/Protobuf.podspec index 2523076a4a..ac27f03e55 100644 --- a/Protobuf.podspec +++ b/Protobuf.podspec @@ -5,7 +5,7 @@ # dependent projects use the :git notation to refer to the library. Pod::Spec.new do |s| s.name = 'Protobuf' - s.version = '3.0.0-beta-3' + s.version = '3.0.0-beta-4' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/google/protobuf' s.license = 'New BSD' diff --git a/configure.ac b/configure.ac index d858e1779d..7ae4a88b37 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AC_PREREQ(2.59) # In the SVN trunk, the version should always be the next anticipated release # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed # the size of one file name in the dist tarfile over the 99-char limit.) -AC_INIT([Protocol Buffers],[3.0.0-beta-3],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.0.0-beta-4],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index e4240dae87..659b2e7787 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers tools Tools for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.0.0-beta3 + 3.0.0-beta4 Google Inc. protobuf-packages https://github.com/google/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.nuspec b/csharp/src/Google.Protobuf/Google.Protobuf.nuspec index 2aabf364ae..e7b47ffbb1 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.nuspec +++ b/csharp/src/Google.Protobuf/Google.Protobuf.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers C# C# runtime library for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.0.0-beta3 + 3.0.0-beta4 Google Inc. protobuf-packages https://github.com/google/protobuf/blob/master/LICENSE @@ -51,4 +51,4 @@ - \ No newline at end of file + diff --git a/java/core/pom.xml b/java/core/pom.xml index 0d4c5c75d0..422bde82b8 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -6,7 +6,7 @@ com.google.protobuf protobuf-parent - 3.0.0-beta-3 + 3.0.0-beta-4 protobuf-java diff --git a/java/lite/pom.xml b/java/lite/pom.xml index c403dc093d..87a5c44de7 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -6,7 +6,7 @@ com.google.protobuf protobuf-parent - 3.0.0-beta-3 + 3.0.0-beta-4 protobuf-lite diff --git a/java/pom.xml b/java/pom.xml index 7a1a91f873..359db6c1de 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -11,7 +11,7 @@ com.google.protobuf protobuf-parent - 3.0.0-beta-3 + 3.0.0-beta-4 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index 9236f90759..d8f64eb18b 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -6,7 +6,7 @@ com.google.protobuf protobuf-parent - 3.0.0-beta-3 + 3.0.0-beta-4 protobuf-java-util diff --git a/javanano/pom.xml b/javanano/pom.xml index a2eca09d1c..e6a03d1574 100644 --- a/javanano/pom.xml +++ b/javanano/pom.xml @@ -10,7 +10,7 @@ com.google.protobuf.nano protobuf-javanano - 3.0.0-alpha-6 + 3.0.0-alpha-7 bundle Protocol Buffer JavaNano API @@ -165,7 +165,7 @@ https://developers.google.com/protocol-buffers/ com.google.protobuf - com.google.protobuf;version=3.0.0-alpha-5 + com.google.protobuf;version=3.0.0-alpha-7 diff --git a/js/package.json b/js/package.json index 657b08bddf..76ce0c1db3 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.0.0-alpha.6.2", + "version": "3.0.0-alpha.7", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index 5086604156..8fad896a06 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -10,7 +10,7 @@ com.google.protobuf protoc - 3.0.0-beta-3 + 3.0.0-beta-4 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index 2a3c6771a0..7213496eae 100755 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,7 +30,7 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '3.0.0b3' +__version__ = '3.0.0b4' if __name__ != '__main__': try: diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index c542abf6ab..8cf40e3f7a 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.0.0.alpha.6.0.0" + s.version = "3.0.0.alpha.7.0.0" s.licenses = ["BSD"] s.summary = "Protocol Buffers" s.description = "Protocol Buffers are Google's data interchange format." diff --git a/ruby/pom.xml b/ruby/pom.xml index 4cbd6d30c1..62845815b2 100644 --- a/ruby/pom.xml +++ b/ruby/pom.xml @@ -86,7 +86,7 @@ com.google.protobuf protobuf-java - 3.0.0-alpha-3 + 3.0.0-beta-3 From dd37b992bef77ce9648c5a29a9bce53a17fb5f1f Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Wed, 13 Jul 2016 16:44:27 -0700 Subject: [PATCH 06/18] Comment out lite conformance test. The 'lite' generator flag is no longer supported. --- conformance/Makefile.am | 88 ++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/conformance/Makefile.am b/conformance/Makefile.am index 5538cc75d8..64adb7c5bf 100644 --- a/conformance/Makefile.am +++ b/conformance/Makefile.am @@ -84,47 +84,47 @@ other_language_protoc_outputs = \ google/protobuf/wrappers.pb.cc \ google/protobuf/wrappers.pb.h \ google/protobuf/wrappers.rb \ - google/protobuf/wrappers_pb2.py \ - lite/com/google/protobuf/Any.java \ - lite/com/google/protobuf/AnyOrBuilder.java \ - lite/com/google/protobuf/AnyProto.java \ - lite/com/google/protobuf/BoolValue.java \ - lite/com/google/protobuf/BoolValueOrBuilder.java \ - lite/com/google/protobuf/BytesValue.java \ - lite/com/google/protobuf/BytesValueOrBuilder.java \ - lite/com/google/protobuf/conformance/Conformance.java \ - lite/com/google/protobuf/DoubleValue.java \ - lite/com/google/protobuf/DoubleValueOrBuilder.java \ - lite/com/google/protobuf/Duration.java \ - lite/com/google/protobuf/DurationOrBuilder.java \ - lite/com/google/protobuf/DurationProto.java \ - lite/com/google/protobuf/FieldMask.java \ - lite/com/google/protobuf/FieldMaskOrBuilder.java \ - lite/com/google/protobuf/FieldMaskProto.java \ - lite/com/google/protobuf/FloatValue.java \ - lite/com/google/protobuf/FloatValueOrBuilder.java \ - lite/com/google/protobuf/Int32Value.java \ - lite/com/google/protobuf/Int32ValueOrBuilder.java \ - lite/com/google/protobuf/Int64Value.java \ - lite/com/google/protobuf/Int64ValueOrBuilder.java \ - lite/com/google/protobuf/ListValue.java \ - lite/com/google/protobuf/ListValueOrBuilder.java \ - lite/com/google/protobuf/NullValue.java \ - lite/com/google/protobuf/StringValue.java \ - lite/com/google/protobuf/StringValueOrBuilder.java \ - lite/com/google/protobuf/Struct.java \ - lite/com/google/protobuf/StructOrBuilder.java \ - lite/com/google/protobuf/StructProto.java \ - lite/com/google/protobuf/Timestamp.java \ - lite/com/google/protobuf/TimestampOrBuilder.java \ - lite/com/google/protobuf/TimestampProto.java \ - lite/com/google/protobuf/UInt32Value.java \ - lite/com/google/protobuf/UInt32ValueOrBuilder.java \ - lite/com/google/protobuf/UInt64Value.java \ - lite/com/google/protobuf/UInt64ValueOrBuilder.java \ - lite/com/google/protobuf/Value.java \ - lite/com/google/protobuf/ValueOrBuilder.java \ - lite/com/google/protobuf/WrappersProto.java + google/protobuf/wrappers_pb2.py + # lite/com/google/protobuf/Any.java \ + # lite/com/google/protobuf/AnyOrBuilder.java \ + # lite/com/google/protobuf/AnyProto.java \ + # lite/com/google/protobuf/BoolValue.java \ + # lite/com/google/protobuf/BoolValueOrBuilder.java \ + # lite/com/google/protobuf/BytesValue.java \ + # lite/com/google/protobuf/BytesValueOrBuilder.java \ + # lite/com/google/protobuf/conformance/Conformance.java \ + # lite/com/google/protobuf/DoubleValue.java \ + # lite/com/google/protobuf/DoubleValueOrBuilder.java \ + # lite/com/google/protobuf/Duration.java \ + # lite/com/google/protobuf/DurationOrBuilder.java \ + # lite/com/google/protobuf/DurationProto.java \ + # lite/com/google/protobuf/FieldMask.java \ + # lite/com/google/protobuf/FieldMaskOrBuilder.java \ + # lite/com/google/protobuf/FieldMaskProto.java \ + # lite/com/google/protobuf/FloatValue.java \ + # lite/com/google/protobuf/FloatValueOrBuilder.java \ + # lite/com/google/protobuf/Int32Value.java \ + # lite/com/google/protobuf/Int32ValueOrBuilder.java \ + # lite/com/google/protobuf/Int64Value.java \ + # lite/com/google/protobuf/Int64ValueOrBuilder.java \ + # lite/com/google/protobuf/ListValue.java \ + # lite/com/google/protobuf/ListValueOrBuilder.java \ + # lite/com/google/protobuf/NullValue.java \ + # lite/com/google/protobuf/StringValue.java \ + # lite/com/google/protobuf/StringValueOrBuilder.java \ + # lite/com/google/protobuf/Struct.java \ + # lite/com/google/protobuf/StructOrBuilder.java \ + # lite/com/google/protobuf/StructProto.java \ + # lite/com/google/protobuf/Timestamp.java \ + # lite/com/google/protobuf/TimestampOrBuilder.java \ + # lite/com/google/protobuf/TimestampProto.java \ + # lite/com/google/protobuf/UInt32Value.java \ + # lite/com/google/protobuf/UInt32ValueOrBuilder.java \ + # lite/com/google/protobuf/UInt64Value.java \ + # lite/com/google/protobuf/UInt64ValueOrBuilder.java \ + # lite/com/google/protobuf/Value.java \ + # lite/com/google/protobuf/ValueOrBuilder.java \ + # lite/com/google/protobuf/WrappersProto.java bin_PROGRAMS = conformance-test-runner conformance-cpp @@ -192,7 +192,7 @@ if USE_EXTERNAL_PROTOC protoc_middleman: $(conformance_protoc_inputs) $(well_known_type_protoc_inputs) $(PROTOC) -I$(srcdir) -I$(top_srcdir) --cpp_out=. --java_out=. --ruby_out=. --objc_out=. --python_out=. $(conformance_protoc_inputs) $(PROTOC) -I$(srcdir) -I$(top_srcdir) --cpp_out=. --java_out=. --ruby_out=. --python_out=. $(well_known_type_protoc_inputs) - $(PROTOC) -I$(srcdir) -I$(top_srcdir) --java_out=lite:lite $(conformance_protoc_inputs) $(well_known_type_protoc_inputs) + ## $(PROTOC) -I$(srcdir) -I$(top_srcdir) --java_out=lite:lite $(conformance_protoc_inputs) $(well_known_type_protoc_inputs) touch protoc_middleman else @@ -203,8 +203,8 @@ else protoc_middleman: $(top_srcdir)/src/protoc$(EXEEXT) $(conformance_protoc_inputs) $(well_known_type_protoc_inputs) oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --cpp_out=$$oldpwd --java_out=$$oldpwd --ruby_out=$$oldpwd --objc_out=$$oldpwd --python_out=$$oldpwd $(conformance_protoc_inputs) ) oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --cpp_out=$$oldpwd --java_out=$$oldpwd --ruby_out=$$oldpwd --python_out=$$oldpwd $(well_known_type_protoc_inputs) ) - @mkdir -p lite - oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --java_out=lite:$$oldpwd/lite $(conformance_protoc_inputs) $(well_known_type_protoc_inputs) ) + ## @mkdir -p lite + ## oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --java_out=lite:$$oldpwd/lite $(conformance_protoc_inputs) $(well_known_type_protoc_inputs) ) touch protoc_middleman endif From 047a3b4852c38c46b2c28109a57c629d00def43c Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Wed, 13 Jul 2016 18:09:10 -0700 Subject: [PATCH 07/18] Exclude Java lite module from parent pom.xml --- java/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/pom.xml b/java/pom.xml index 7a1a91f873..870325be75 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -182,7 +182,7 @@ core - lite + util From c2ebdec35598deed99d17fc1320a2e213c7d021e Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Thu, 14 Jul 2016 10:46:24 -0700 Subject: [PATCH 08/18] Update version number in AssemblyInfo.cs. --- csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs b/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs index 0516f18e25..1673edfb03 100644 --- a/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs +++ b/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs @@ -64,4 +64,4 @@ using System.Security; [assembly: AssemblyVersion("3.0.0.0")] [assembly: AssemblyFileVersion("3.0.0.0")] -[assembly: AssemblyInformationalVersion("3.0.0-beta3")] +[assembly: AssemblyInformationalVersion("3.0.0-beta4")] From d9334ea8d948ba591fba8b2d2f458b2629f37d93 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Fri, 1 Jul 2016 09:37:12 +0100 Subject: [PATCH 09/18] Improve exception throwing implementation in collections --- .../Google.Protobuf/Collections/MapField.cs | 31 +++++++-------- .../Collections/RepeatedField.cs | 39 +++++-------------- 2 files changed, 25 insertions(+), 45 deletions(-) diff --git a/csharp/src/Google.Protobuf/Collections/MapField.cs b/csharp/src/Google.Protobuf/Collections/MapField.cs index 053f755850..537ce261a4 100644 --- a/csharp/src/Google.Protobuf/Collections/MapField.cs +++ b/csharp/src/Google.Protobuf/Collections/MapField.cs @@ -30,14 +30,13 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion +using Google.Protobuf.Compatibility; using Google.Protobuf.Reflection; using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; -using Google.Protobuf.Compatibility; namespace Google.Protobuf.Collections { @@ -113,7 +112,7 @@ namespace Google.Protobuf.Collections // Validation of arguments happens in ContainsKey and the indexer if (ContainsKey(key)) { - throw new ArgumentException("Key already exists in map", "key"); + throw new ArgumentException("Key already exists in map", nameof(key)); } this[key] = value; } @@ -125,7 +124,7 @@ namespace Google.Protobuf.Collections /// true if the map contains the given key; false otherwise. public bool ContainsKey(TKey key) { - ProtoPreconditions.CheckNotNullUnconstrained(key, "key"); + ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key)); return map.ContainsKey(key); } @@ -142,7 +141,7 @@ namespace Google.Protobuf.Collections /// true if the map contained the given key before the entry was removed; false otherwise. public bool Remove(TKey key) { - ProtoPreconditions.CheckNotNullUnconstrained(key, "key"); + ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key)); LinkedListNode> node; if (map.TryGetValue(key, out node)) { @@ -190,7 +189,7 @@ namespace Google.Protobuf.Collections { get { - ProtoPreconditions.CheckNotNullUnconstrained(key, "key"); + ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key)); TValue value; if (TryGetValue(key, out value)) { @@ -200,11 +199,11 @@ namespace Google.Protobuf.Collections } set { - ProtoPreconditions.CheckNotNullUnconstrained(key, "key"); + ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key)); // value == null check here is redundant, but avoids boxing. if (value == null) { - ProtoPreconditions.CheckNotNullUnconstrained(value, "value"); + ProtoPreconditions.CheckNotNullUnconstrained(value, nameof(value)); } LinkedListNode> node; var pair = new KeyValuePair(key, value); @@ -236,7 +235,7 @@ namespace Google.Protobuf.Collections /// The entries to add to the map. public void Add(IDictionary entries) { - ProtoPreconditions.CheckNotNull(entries, "entries"); + ProtoPreconditions.CheckNotNull(entries, nameof(entries)); foreach (var pair in entries) { Add(pair.Key, pair.Value); @@ -315,7 +314,7 @@ namespace Google.Protobuf.Collections { if (item.Key == null) { - throw new ArgumentException("Key is null", "item"); + throw new ArgumentException("Key is null", nameof(item)); } LinkedListNode> node; if (map.TryGetValue(item.Key, out node) && @@ -503,7 +502,7 @@ namespace Google.Protobuf.Collections void IDictionary.Remove(object key) { - ProtoPreconditions.CheckNotNull(key, "key"); + ProtoPreconditions.CheckNotNull(key, nameof(key)); if (!(key is TKey)) { return; @@ -532,7 +531,7 @@ namespace Google.Protobuf.Collections { get { - ProtoPreconditions.CheckNotNull(key, "key"); + ProtoPreconditions.CheckNotNull(key, nameof(key)); if (!(key is TKey)) { return null; @@ -714,11 +713,11 @@ namespace Google.Protobuf.Collections { if (arrayIndex < 0) { - throw new ArgumentOutOfRangeException("arrayIndex"); + throw new ArgumentOutOfRangeException(nameof(arrayIndex)); } if (arrayIndex + Count >= array.Length) { - throw new ArgumentException("Not enough space in the array", "array"); + throw new ArgumentException("Not enough space in the array", nameof(array)); } foreach (var item in this) { @@ -745,11 +744,11 @@ namespace Google.Protobuf.Collections { if (index < 0) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } if (index + Count >= array.Length) { - throw new ArgumentException("Not enough space in the array", "array"); + throw new ArgumentException("Not enough space in the array", nameof(array)); } foreach (var item in this) { diff --git a/csharp/src/Google.Protobuf/Collections/RepeatedField.cs b/csharp/src/Google.Protobuf/Collections/RepeatedField.cs index d1db856c9c..482ca9b665 100644 --- a/csharp/src/Google.Protobuf/Collections/RepeatedField.cs +++ b/csharp/src/Google.Protobuf/Collections/RepeatedField.cs @@ -34,7 +34,6 @@ using System; using System.Collections; using System.Collections.Generic; using System.IO; -using System.Text; namespace Google.Protobuf.Collections { @@ -227,10 +226,7 @@ namespace Google.Protobuf.Collections /// The item to add. public void Add(T item) { - if (item == null) - { - throw new ArgumentNullException("item"); - } + ProtoPreconditions.CheckNotNullUnconstrained(item, nameof(item)); EnsureSize(count + 1); array[count++] = item; } @@ -300,10 +296,7 @@ namespace Google.Protobuf.Collections /// The values to add to this collection. public void Add(RepeatedField values) { - if (values == null) - { - throw new ArgumentNullException("values"); - } + ProtoPreconditions.CheckNotNull(values, nameof(values)); EnsureSize(count + values.count); // We know that all the values will be valid, because it's a RepeatedField. Array.Copy(values.array, 0, array, count, values.count); @@ -316,10 +309,7 @@ namespace Google.Protobuf.Collections /// The values to add to this collection. public void Add(IEnumerable values) { - if (values == null) - { - throw new ArgumentNullException("values"); - } + ProtoPreconditions.CheckNotNull(values, nameof(values)); // TODO: Check for ICollection and get the Count, to optimize? foreach (T item in values) { @@ -418,10 +408,7 @@ namespace Google.Protobuf.Collections /// The zero-based index of the item, or -1 if it is not found. public int IndexOf(T item) { - if (item == null) - { - throw new ArgumentNullException("item"); - } + ProtoPreconditions.CheckNotNullUnconstrained(item, nameof(item)); EqualityComparer comparer = EqualityComparer.Default; for (int i = 0; i < count; i++) { @@ -440,13 +427,10 @@ namespace Google.Protobuf.Collections /// The item to insert. public void Insert(int index, T item) { - if (item == null) - { - throw new ArgumentNullException("item"); - } + ProtoPreconditions.CheckNotNullUnconstrained(item, nameof(item)); if (index < 0 || index > count) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } EnsureSize(count + 1); Array.Copy(array, index, array, index + 1, count - index); @@ -462,7 +446,7 @@ namespace Google.Protobuf.Collections { if (index < 0 || index >= count) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } Array.Copy(array, index + 1, array, index, count - index - 1); count--; @@ -494,7 +478,7 @@ namespace Google.Protobuf.Collections { if (index < 0 || index >= count) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } return array[index]; } @@ -502,12 +486,9 @@ namespace Google.Protobuf.Collections { if (index < 0 || index >= count) { - throw new ArgumentOutOfRangeException("index"); - } - if (value == null) - { - throw new ArgumentNullException("value"); + throw new ArgumentOutOfRangeException(nameof(index)); } + ProtoPreconditions.CheckNotNullUnconstrained(value, nameof(value)); array[index] = value; } } From b053b9211b03bc334b6b0f9cc5ef22f7c500e6cc Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Fri, 1 Jul 2016 09:46:45 +0100 Subject: [PATCH 10/18] Implement RepeatedField.AddRange. This fixes issue #1730. --- .../Collections/RepeatedFieldTest.cs | 10 ++++++++++ .../Google.Protobuf/Collections/RepeatedField.cs | 14 +++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs b/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs index 8ed54cfb48..5d23d834ad 100644 --- a/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs +++ b/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs @@ -74,6 +74,16 @@ namespace Google.Protobuf.Collections Assert.AreEqual("bar", list[1]); } + [Test] + public void AddRange() + { + var list = new RepeatedField(); + list.AddRange(new[] { "foo", "bar" }); + Assert.AreEqual(2, list.Count); + Assert.AreEqual("foo", list[0]); + Assert.AreEqual("bar", list[1]); + } + [Test] public void Add_RepeatedField() { diff --git a/csharp/src/Google.Protobuf/Collections/RepeatedField.cs b/csharp/src/Google.Protobuf/Collections/RepeatedField.cs index 482ca9b665..a13cebdf91 100644 --- a/csharp/src/Google.Protobuf/Collections/RepeatedField.cs +++ b/csharp/src/Google.Protobuf/Collections/RepeatedField.cs @@ -307,7 +307,7 @@ namespace Google.Protobuf.Collections /// Adds all of the specified values into this collection. /// /// The values to add to this collection. - public void Add(IEnumerable values) + public void AddRange(IEnumerable values) { ProtoPreconditions.CheckNotNull(values, nameof(values)); // TODO: Check for ICollection and get the Count, to optimize? @@ -317,6 +317,18 @@ namespace Google.Protobuf.Collections } } + /// + /// Adds all of the specified values into this collection. This method is present to + /// allow repeated fields to be constructed from queries within collection initializers. + /// Within non-collection-initializer code, consider using the equivalent + /// method instead for clarity. + /// + /// The values to add to this collection. + public void Add(IEnumerable values) + { + AddRange(values); + } + /// /// Returns an enumerator that iterates through the collection. /// From 2ee1e52380bcda8fccf228447decfc20529172cd Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Fri, 8 Jul 2016 18:04:39 +0100 Subject: [PATCH 11/18] Optimize AddRange for sequences implementing ICollection (Also fix a few more C# 6-isms.) --- .../Collections/RepeatedFieldTest.cs | 72 ++++++++++++++++++- .../Collections/RepeatedField.cs | 46 ++++++++++-- 2 files changed, 110 insertions(+), 8 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs b/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs index 5d23d834ad..f8e3b1770b 100644 --- a/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs +++ b/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs @@ -75,15 +75,83 @@ namespace Google.Protobuf.Collections } [Test] - public void AddRange() + public void AddRange_SlowPath() { var list = new RepeatedField(); - list.AddRange(new[] { "foo", "bar" }); + list.AddRange(new[] { "foo", "bar" }.Select(x => x)); Assert.AreEqual(2, list.Count); Assert.AreEqual("foo", list[0]); Assert.AreEqual("bar", list[1]); } + [Test] + public void AddRange_SlowPath_NullsProhibited_ReferenceType() + { + var list = new RepeatedField(); + // It's okay for this to throw ArgumentNullException if necessary. + // It's not ideal, but not awful. + Assert.Catch(() => list.AddRange(new[] { "foo", null }.Select(x => x))); + } + + [Test] + public void AddRange_SlowPath_NullsProhibited_NullableValueType() + { + var list = new RepeatedField(); + // It's okay for this to throw ArgumentNullException if necessary. + // It's not ideal, but not awful. + Assert.Catch(() => list.AddRange(new[] { 20, (int?)null }.Select(x => x))); + } + + [Test] + public void AddRange_Optimized_NonNullableValueType() + { + var list = new RepeatedField(); + list.AddRange(new List { 20, 30 }); + Assert.AreEqual(2, list.Count); + Assert.AreEqual(20, list[0]); + Assert.AreEqual(30, list[1]); + } + + [Test] + public void AddRange_Optimized_ReferenceType() + { + var list = new RepeatedField(); + list.AddRange(new List { "foo", "bar" }); + Assert.AreEqual(2, list.Count); + Assert.AreEqual("foo", list[0]); + Assert.AreEqual("bar", list[1]); + } + + [Test] + public void AddRange_Optimized_NullableValueType() + { + var list = new RepeatedField(); + list.AddRange(new List { 20, 30 }); + Assert.AreEqual(2, list.Count); + Assert.AreEqual((int?) 20, list[0]); + Assert.AreEqual((int?) 30, list[1]); + } + + [Test] + public void AddRange_Optimized_NullsProhibited_ReferenceType() + { + // We don't just trust that a collection with a nullable element type doesn't contain nulls + var list = new RepeatedField(); + // It's okay for this to throw ArgumentNullException if necessary. + // It's not ideal, but not awful. + Assert.Catch(() => list.AddRange(new List { "foo", null })); + } + + [Test] + public void AddRange_Optimized_NullsProhibited_NullableValueType() + { + // We don't just trust that a collection with a nullable element type doesn't contain nulls + var list = new RepeatedField(); + // It's okay for this to throw ArgumentNullException if necessary. + // It's not ideal, but not awful. + Assert.Catch(() => list.AddRange(new List { 20, null })); + } + [Test] public void Add_RepeatedField() { diff --git a/csharp/src/Google.Protobuf/Collections/RepeatedField.cs b/csharp/src/Google.Protobuf/Collections/RepeatedField.cs index a13cebdf91..dcc6e9bf9f 100644 --- a/csharp/src/Google.Protobuf/Collections/RepeatedField.cs +++ b/csharp/src/Google.Protobuf/Collections/RepeatedField.cs @@ -281,12 +281,12 @@ namespace Google.Protobuf.Collections /// /// Gets the number of elements contained in the collection. /// - public int Count { get { return count; } } + public int Count => count; /// /// Gets a value indicating whether the collection is read-only. /// - public bool IsReadOnly { get { return false; } } + public bool IsReadOnly => false; // TODO: Remove this overload and just handle it in the one below, at execution time? @@ -310,7 +310,41 @@ namespace Google.Protobuf.Collections public void AddRange(IEnumerable values) { ProtoPreconditions.CheckNotNull(values, nameof(values)); - // TODO: Check for ICollection and get the Count, to optimize? + + // Optimize the case where we know the size and can ask the collection to + // copy itself. + var collection = values as ICollection; + if (collection != null) + { + var extraCount = collection.Count; + // For reference types and nullable value types, we need to check that there are no nulls + // present. (This isn't a thread-safe approach, but we don't advertise this is thread-safe.) + // We expect the JITter to optimize this test to true/false, so it's effectively conditional + // specialization. + if (default(T) == null) + { + // TODO: Measure whether iterating once to check and then letting the collection copy + // itself is faster or slower than iterating and adding as we go. For large + // collections this will not be great in terms of cache usage... but the optimized + // copy may be significantly faster than doing it one at a time. + foreach (var item in collection) + { + if (item == null) + { + throw new ArgumentException("Sequence contained null element", nameof(values)); + } + } + } + EnsureSize(count + extraCount); + collection.CopyTo(array, count); + count += extraCount; + return; + } + + // We *could* check for ICollection as well, but very very few collections implement + // ICollection but not ICollection. (HashSet does, for one...) + + // Fall back to a slower path of adding items one at a time. foreach (T item in values) { Add(item); @@ -506,16 +540,16 @@ namespace Google.Protobuf.Collections } #region Explicit interface implementation for IList and ICollection. - bool IList.IsFixedSize { get { return false; } } + bool IList.IsFixedSize => false; void ICollection.CopyTo(Array array, int index) { Array.Copy(this.array, 0, array, index, count); } - bool ICollection.IsSynchronized { get { return false; } } + bool ICollection.IsSynchronized => false; - object ICollection.SyncRoot { get { return this; } } + object ICollection.SyncRoot => this; object IList.this[int index] { From 5e0de1ebee532dc2ff4ce88ec2d7bee90817825c Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Sat, 9 Jul 2016 08:02:14 +0100 Subject: [PATCH 12/18] Remove the overload for Add(RepeatedField) We now just perform the optimization within AddRange itself. This is a breaking change in terms of "drop in the DLL", but is source compatible, which should be fine. --- .../Collections/RepeatedFieldTest.cs | 12 ++++++-- .../Collections/RepeatedField.cs | 30 ++++++++----------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs b/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs index f8e3b1770b..6852f75f8e 100644 --- a/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs +++ b/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs @@ -153,10 +153,18 @@ namespace Google.Protobuf.Collections } [Test] - public void Add_RepeatedField() + public void AddRange_AlreadyNotEmpty() + { + var list = new RepeatedField { 1, 2, 3 }; + list.AddRange(new List { 4, 5, 6 }); + CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 5, 6 }, list); + } + + [Test] + public void AddRange_RepeatedField() { var list = new RepeatedField { "original" }; - list.Add(new RepeatedField { "foo", "bar" }); + list.AddRange(new RepeatedField { "foo", "bar" }); Assert.AreEqual(3, list.Count); Assert.AreEqual("original", list[0]); Assert.AreEqual("foo", list[1]); diff --git a/csharp/src/Google.Protobuf/Collections/RepeatedField.cs b/csharp/src/Google.Protobuf/Collections/RepeatedField.cs index dcc6e9bf9f..7bb5644801 100644 --- a/csharp/src/Google.Protobuf/Collections/RepeatedField.cs +++ b/csharp/src/Google.Protobuf/Collections/RepeatedField.cs @@ -288,21 +288,6 @@ namespace Google.Protobuf.Collections /// public bool IsReadOnly => false; - // TODO: Remove this overload and just handle it in the one below, at execution time? - - /// - /// Adds all of the specified values into this collection. - /// - /// The values to add to this collection. - public void Add(RepeatedField values) - { - ProtoPreconditions.CheckNotNull(values, nameof(values)); - EnsureSize(count + values.count); - // We know that all the values will be valid, because it's a RepeatedField. - Array.Copy(values.array, 0, array, count, values.count); - count += values.count; - } - /// /// Adds all of the specified values into this collection. /// @@ -311,8 +296,19 @@ namespace Google.Protobuf.Collections { ProtoPreconditions.CheckNotNull(values, nameof(values)); - // Optimize the case where we know the size and can ask the collection to - // copy itself. + // Optimization 1: If the collection we're adding is already a RepeatedField, + // we know the values are valid. + var otherRepeatedField = values as RepeatedField; + if (otherRepeatedField != null) + { + EnsureSize(count + otherRepeatedField.count); + Array.Copy(otherRepeatedField.array, 0, array, count, otherRepeatedField.count); + count += otherRepeatedField.count; + return; + } + + // Optimization 2: The collection is an ICollection, so we can expand + // just once and ask the collection to copy itself into the array. var collection = values as ICollection; if (collection != null) { From b5ce5251fd9450162f12fae93b35f31c5319a793 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Thu, 14 Jul 2016 22:01:47 +0100 Subject: [PATCH 13/18] Move to dotnet cli for building, and .NET Core (netstandard1.0) as target platform (#1727) This also updates the version number to 3.0.0-beta4 --- .travis.yml | 12 +- Makefile.am | 26 ++- appveyor.bat | 9 +- appveyor.yml | 6 + conformance/Makefile.am | 2 +- csharp/.gitignore | 21 +-- csharp/build_packages.bat | 7 +- csharp/buildall.sh | 15 +- csharp/src/AddressBook/AddressBook.csproj | 75 -------- csharp/src/AddressBook/AddressBook.xproj | 19 ++ .../AddressBook/Properties/AssemblyInfo.cs | 18 -- csharp/src/AddressBook/SampleUsage.cs | 2 +- csharp/src/AddressBook/app.config | 3 - csharp/src/AddressBook/project.json | 20 +++ .../Google.Protobuf.Conformance/App.config | 6 - .../Google.Protobuf.Conformance.csproj | 61 ------- .../Google.Protobuf.Conformance.xproj | 19 ++ .../Properties/AssemblyInfo.cs | 48 ----- .../Google.Protobuf.Conformance/project.json | 19 ++ .../Google.Protobuf.JsonDump.csproj | 68 ------- .../Google.Protobuf.JsonDump.xproj | 19 ++ .../src/Google.Protobuf.JsonDump/Program.cs | 3 +- .../Properties/AssemblyInfo.cs | 19 -- .../src/Google.Protobuf.JsonDump/app.config | 3 - .../src/Google.Protobuf.JsonDump/project.json | 19 ++ .../Google.Protobuf.Test/FieldCodecTest.cs | 3 +- .../Google.Protobuf.Test.csproj | 143 --------------- .../Google.Protobuf.Test.xproj | 19 ++ .../Properties/AppManifest.xml | 6 - .../Properties/AssemblyInfo.cs | 20 --- .../WellKnownTypes/AnyTest.cs | 2 +- .../WellKnownTypes/FieldMaskTest.cs | 4 +- .../src/Google.Protobuf.Test/packages.config | 5 - csharp/src/Google.Protobuf.Test/project.json | 44 +++++ csharp/src/Google.Protobuf.sln | 65 +++---- .../Google.Protobuf/Google.Protobuf.csproj | 168 ------------------ .../Google.Protobuf/Google.Protobuf.nuspec | 54 ------ .../src/Google.Protobuf/Google.Protobuf.xproj | 19 ++ .../Properties/AssemblyInfo.cs | 18 -- csharp/src/Google.Protobuf/packages.config | 4 - csharp/src/Google.Protobuf/project.json | 65 +++++++ jenkins/docker/Dockerfile | 7 + tests.sh | 20 ++- 43 files changed, 367 insertions(+), 818 deletions(-) delete mode 100644 csharp/src/AddressBook/AddressBook.csproj create mode 100644 csharp/src/AddressBook/AddressBook.xproj delete mode 100644 csharp/src/AddressBook/Properties/AssemblyInfo.cs delete mode 100644 csharp/src/AddressBook/app.config create mode 100644 csharp/src/AddressBook/project.json delete mode 100644 csharp/src/Google.Protobuf.Conformance/App.config delete mode 100644 csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.csproj create mode 100644 csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.xproj delete mode 100644 csharp/src/Google.Protobuf.Conformance/Properties/AssemblyInfo.cs create mode 100644 csharp/src/Google.Protobuf.Conformance/project.json delete mode 100644 csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj create mode 100644 csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.xproj delete mode 100644 csharp/src/Google.Protobuf.JsonDump/Properties/AssemblyInfo.cs delete mode 100644 csharp/src/Google.Protobuf.JsonDump/app.config create mode 100644 csharp/src/Google.Protobuf.JsonDump/project.json delete mode 100644 csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj create mode 100644 csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.xproj delete mode 100644 csharp/src/Google.Protobuf.Test/Properties/AppManifest.xml delete mode 100644 csharp/src/Google.Protobuf.Test/Properties/AssemblyInfo.cs delete mode 100644 csharp/src/Google.Protobuf.Test/packages.config create mode 100644 csharp/src/Google.Protobuf.Test/project.json delete mode 100644 csharp/src/Google.Protobuf/Google.Protobuf.csproj delete mode 100644 csharp/src/Google.Protobuf/Google.Protobuf.nuspec create mode 100644 csharp/src/Google.Protobuf/Google.Protobuf.xproj delete mode 100644 csharp/src/Google.Protobuf/packages.config create mode 100644 csharp/src/Google.Protobuf/project.json diff --git a/.travis.yml b/.travis.yml index 46abbb9e3b..7cfe0dfbab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,6 @@ script: env: - CONFIG=cpp - CONFIG=cpp_distcheck - - CONFIG=csharp - CONFIG=golang - CONFIG=java_jdk6 - CONFIG=java_jdk7 @@ -52,10 +51,6 @@ matrix: env: CONFIG=javanano_jdk7 - os: osx env: CONFIG=javanano_oracle7 - # Requires installing mono, currently travis.sh is doing that with apt-get - # which doesn't work on OS X. - - os: osx - env: CONFIG=csharp # Requires installing golang, currently travis.sh is doing that with apt-get # which doesn't work on OS X. - os: osx @@ -70,6 +65,13 @@ matrix: env: CONFIG=objectivec_osx - os: linux env: CONFIG=objectivec_cocoapods_integration + # The dotnet environment requires Ubuntu 14.04 or 16.04. This + # configuration is effectively an "extra" one, outside the + # autogenerated matrix. + include: + - os: linux + env: CONFIG=csharp + dist: trusty allow_failures: # These currently do not work on OS X but are being worked on by @haberman. - os: osx diff --git a/Makefile.am b/Makefile.am index 72cc91490e..80df33585d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -59,22 +59,19 @@ csharp_EXTRA_DIST= \ csharp/keys/README.md \ csharp/protos/unittest_issues.proto \ csharp/src/AddressBook/AddPerson.cs \ - csharp/src/AddressBook/AddressBook.csproj \ csharp/src/AddressBook/Addressbook.cs \ + csharp/src/AddressBook/AddressBook.xproj \ csharp/src/AddressBook/ListPeople.cs \ csharp/src/AddressBook/Program.cs \ - csharp/src/AddressBook/Properties/AssemblyInfo.cs \ csharp/src/AddressBook/SampleUsage.cs \ - csharp/src/AddressBook/app.config \ - csharp/src/Google.Protobuf.Conformance/App.config \ + csharp/src/AddressBook/project.json \ csharp/src/Google.Protobuf.Conformance/Conformance.cs \ - csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.csproj \ + csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.xproj \ csharp/src/Google.Protobuf.Conformance/Program.cs \ - csharp/src/Google.Protobuf.Conformance/Properties/AssemblyInfo.cs \ - csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj \ + csharp/src/Google.Protobuf.Conformance/project.json \ + csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.xproj \ csharp/src/Google.Protobuf.JsonDump/Program.cs \ - csharp/src/Google.Protobuf.JsonDump/Properties/AssemblyInfo.cs \ - csharp/src/Google.Protobuf.JsonDump/app.config \ + csharp/src/Google.Protobuf.JsonDump/project.json \ csharp/src/Google.Protobuf.Test/ByteStringTest.cs \ csharp/src/Google.Protobuf.Test/CodedInputStreamExtensions.cs \ csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs \ @@ -87,13 +84,11 @@ csharp_EXTRA_DIST= \ csharp/src/Google.Protobuf.Test/EqualityTester.cs \ csharp/src/Google.Protobuf.Test/FieldCodecTest.cs \ csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs \ - csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj \ + csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.xproj \ csharp/src/Google.Protobuf.Test/IssuesTest.cs \ csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs \ csharp/src/Google.Protobuf.Test/JsonParserTest.cs \ csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs \ - csharp/src/Google.Protobuf.Test/Properties/AppManifest.xml \ - csharp/src/Google.Protobuf.Test/Properties/AssemblyInfo.cs \ csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs \ csharp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs \ csharp/src/Google.Protobuf.Test/Reflection/TypeRegistryTest.cs \ @@ -110,7 +105,7 @@ csharp_EXTRA_DIST= \ csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs \ csharp/src/Google.Protobuf.Test/WellKnownTypes/TimestampTest.cs \ csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs \ - csharp/src/Google.Protobuf.Test/packages.config \ + csharp/src/Google.Protobuf.Test/project.json \ csharp/src/Google.Protobuf.sln \ csharp/src/Google.Protobuf/ByteArray.cs \ csharp/src/Google.Protobuf/ByteString.cs \ @@ -124,8 +119,7 @@ csharp_EXTRA_DIST= \ csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs \ csharp/src/Google.Protobuf/FieldCodec.cs \ csharp/src/Google.Protobuf/FrameworkPortability.cs \ - csharp/src/Google.Protobuf/Google.Protobuf.csproj \ - csharp/src/Google.Protobuf/Google.Protobuf.nuspec \ + csharp/src/Google.Protobuf/Google.Protobuf.xproj \ csharp/src/Google.Protobuf/IDeepCloneable.cs \ csharp/src/Google.Protobuf/IMessage.cs \ csharp/src/Google.Protobuf/InvalidJsonException.cs \ @@ -183,7 +177,7 @@ csharp_EXTRA_DIST= \ csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs \ csharp/src/Google.Protobuf/WellKnownTypes/WrappersPartial.cs \ csharp/src/Google.Protobuf/WireFormat.cs \ - csharp/src/Google.Protobuf/packages.config \ + csharp/src/Google.Protobuf/project.json \ csharp/src/packages/repositories.config java_EXTRA_DIST= \ diff --git a/appveyor.bat b/appveyor.bat index 9a46b92892..0e6dd52068 100644 --- a/appveyor.bat +++ b/appveyor.bat @@ -19,9 +19,12 @@ goto :EOF :build_csharp echo Building C# cd csharp\src -nuget restore -msbuild Google.Protobuf.sln /p:Platform="Any CPU" /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" || goto error -nunit-console Google.Protobuf.Test\bin\%configuration%\Google.Protobuf.Test.dll || goto error +dotnet restore +dotnet build -c %configuration% Google.Protobuf Google.Protobuf.Test Google.Protobuf.Conformance || goto error + +echo Testing C# +dotnet test -c %configuration% Google.Protobuf.Test || goto error + goto :EOF :error diff --git a/appveyor.yml b/appveyor.yml index c84ecae2f3..ce797c69a8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,10 +14,16 @@ environment: - language: csharp +# Our build scripts run tests automatically; we don't want AppVeyor +# to try to detect them itself. +test: off + install: - ps: Start-FileDownload https://googlemock.googlecode.com/files/gmock-1.7.0.zip - 7z x gmock-1.7.0.zip - rename gmock-1.7.0 gmock + - ps: Start-FileDownload https://go.microsoft.com/fwlink/?LinkID=809122 -FileName dotnetsdk.exe + - dotnetsdk.exe /install /quiet /norestart before_build: - if %platform%==Win32 set generator=Visual Studio 12 diff --git a/conformance/Makefile.am b/conformance/Makefile.am index 64adb7c5bf..b76407eead 100644 --- a/conformance/Makefile.am +++ b/conformance/Makefile.am @@ -246,7 +246,7 @@ conformance-java-lite: javac_middleman_lite conformance-csharp: $(other_language_protoc_outputs) @echo "Writing shortcut script conformance-csharp..." @echo '#! /bin/sh' > conformance-csharp - @echo 'mono ../csharp/src/Google.Protobuf.Conformance/bin/Release/Google.Protobuf.Conformance.exe "$$@"' >> conformance-csharp + @echo 'dotnet ../csharp/src/Google.Protobuf.Conformance/bin/Release/netcoreapp1.0/Google.Protobuf.Conformance.dll "$$@"' >> conformance-csharp @chmod +x conformance-csharp # Targets for actually running tests. diff --git a/csharp/.gitignore b/csharp/.gitignore index c88f741e37..8ba8849985 100644 --- a/csharp/.gitignore +++ b/csharp/.gitignore @@ -1,16 +1,10 @@ -# -# Untracked directories -# -src/AddressBook/bin -src/AddressBook/obj -src/Google.Protobuf/bin/ -src/Google.Protobuf/obj/ -src/Google.Protobuf.Conformance/bin/ -src/Google.Protobuf.Conformance/obj/ -src/Google.Protobuf.Test/bin/ -src/Google.Protobuf.Test/obj/ -src/Google.Protobuf.JsonDump/bin/ -src/Google.Protobuf.JsonDump/obj/ +# Output +bin +obj +project.lock.json +TestResult.xml + +# Possibly legacy now? mono/bin mono/tmp mono/protoc @@ -23,6 +17,7 @@ lib/NUnit # # Untracked files # +.vs *.user *.suo *.nupkg diff --git a/csharp/build_packages.bat b/csharp/build_packages.bat index 1502f0634b..37732e7c66 100644 --- a/csharp/build_packages.bat +++ b/csharp/build_packages.bat @@ -1,10 +1,7 @@ @rem Builds Google.Protobuf NuGet packages -@rem Adjust the location of nuget.exe -set NUGET=C:\nuget\nuget.exe - -@rem Build src/Google.Protobuf.sln solution in Release configuration first. -%NUGET% pack src\Google.Protobuf\Google.Protobuf.nuspec -Symbols || goto :error +dotnet restore src +dotnet pack -c Release src\Google.Protobuf || goto :error goto :EOF diff --git a/csharp/buildall.sh b/csharp/buildall.sh index 45af705f38..cab3222992 100755 --- a/csharp/buildall.sh +++ b/csharp/buildall.sh @@ -1,17 +1,16 @@ #!/bin/bash -# Use mono to build solution and run all tests. -# Adjust these to reflect the location of nunit-console in your system. -NUNIT_CONSOLE=nunit-console - -# The rest you can leave intact CONFIG=Release SRC=$(dirname $0)/src set -ex -echo Building the solution. -xbuild /p:Configuration=$CONFIG $SRC/Google.Protobuf.sln +echo Building relevant projects. +dotnet build -c $CONFIG $SRC/Google.Protobuf $SRC/Google.Protobuf.Test $SRC/Google.Protobuf.Conformance echo Running tests. -$NUNIT_CONSOLE $SRC/Google.Protobuf.Test/bin/$CONFIG/Google.Protobuf.Test.dll +# Only test netcoreapp1.0, which uses the .NET Core runtime. +# If we want to test the .NET 4.5 version separately, we could +# run Mono explicitly. However, we don't have any differences between +# the .NET 4.5 and netstandard1.0 assemblies. +dotnet test -c $CONFIG -f netcoreapp1.0 $SRC/Google.Protobuf.Test diff --git a/csharp/src/AddressBook/AddressBook.csproj b/csharp/src/AddressBook/AddressBook.csproj deleted file mode 100644 index 8f8ca7e23a..0000000000 --- a/csharp/src/AddressBook/AddressBook.csproj +++ /dev/null @@ -1,75 +0,0 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {A31F5FB2-4FF3-432A-B35B-5CD203606311} - Exe - Properties - Google.Protobuf.Examples.AddressBook - AddressBook - v4.5 - 512 - Google.Protobuf.Examples.AddressBook.Program - - - - - true - full - false - bin\Debug - obj\Debug\ - DEBUG;TRACE - prompt - 4 - true - Off - false - - - pdbonly - true - bin\Release - obj\Release\ - TRACE - prompt - 4 - true - Off - false - - - - - - - - - - - - - - - - - - {6908BDCE-D925-43F3-94AC-A531E6DF2591} - Google.Protobuf - - - - - - - - \ No newline at end of file diff --git a/csharp/src/AddressBook/AddressBook.xproj b/csharp/src/AddressBook/AddressBook.xproj new file mode 100644 index 0000000000..4c9925e83d --- /dev/null +++ b/csharp/src/AddressBook/AddressBook.xproj @@ -0,0 +1,19 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + afb63919-1e05-43b4-802a-8fb8c9b2f463 + AddressBook + .\obj + .\bin\ + + + + 2.0 + + + \ No newline at end of file diff --git a/csharp/src/AddressBook/Properties/AssemblyInfo.cs b/csharp/src/AddressBook/Properties/AssemblyInfo.cs deleted file mode 100644 index 9cb014c0d7..0000000000 --- a/csharp/src/AddressBook/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. - -[assembly: AssemblyTitle("AddressBook")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("AddressBook")] -[assembly: AssemblyCopyright("Copyright © 2015")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -[assembly: AssemblyVersion("3.0.0.0")] -[assembly: AssemblyFileVersion("3.0.0.0")] diff --git a/csharp/src/AddressBook/SampleUsage.cs b/csharp/src/AddressBook/SampleUsage.cs index aaaedda4d6..941d865aa4 100644 --- a/csharp/src/AddressBook/SampleUsage.cs +++ b/csharp/src/AddressBook/SampleUsage.cs @@ -66,7 +66,7 @@ namespace Google.Protobuf.Examples.AddressBook // The message performs a deep-comparison on equality: if (restored.People.Count != 1 || !person.Equals(restored.People[0])) { - throw new ApplicationException("There is a bad person in here!"); + throw new Exception("There is a bad person in here!"); } } } diff --git a/csharp/src/AddressBook/app.config b/csharp/src/AddressBook/app.config deleted file mode 100644 index a80813afe3..0000000000 --- a/csharp/src/AddressBook/app.config +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/csharp/src/AddressBook/project.json b/csharp/src/AddressBook/project.json new file mode 100644 index 0000000000..c500bdc296 --- /dev/null +++ b/csharp/src/AddressBook/project.json @@ -0,0 +1,20 @@ +{ + "buildOptions": { + "debugType": "portable", + "emitEntryPoint": true, + "additionalArguments": [ "/main:Google.Protobuf.Examples.AddressBook.Program" ] + }, + "dependencies": { + "Google.Protobuf": { "target": "project" } + }, + "frameworks": { + "netcoreapp1.0": { + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0" + } + } + } + } +} diff --git a/csharp/src/Google.Protobuf.Conformance/App.config b/csharp/src/Google.Protobuf.Conformance/App.config deleted file mode 100644 index 8e15646352..0000000000 --- a/csharp/src/Google.Protobuf.Conformance/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.csproj b/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.csproj deleted file mode 100644 index 82f728d192..0000000000 --- a/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.csproj +++ /dev/null @@ -1,61 +0,0 @@ - - - - - Debug - AnyCPU - {0607D1B8-80D6-4B35-9857-1263C1B32B94} - Exe - Properties - Google.Protobuf.Conformance - Google.Protobuf.Conformance - v4.5 - 512 - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - {6908bdce-d925-43f3-94ac-a531e6df2591} - Google.Protobuf - - - - - \ No newline at end of file diff --git a/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.xproj b/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.xproj new file mode 100644 index 0000000000..99ff146538 --- /dev/null +++ b/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.xproj @@ -0,0 +1,19 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + dddc055b-e185-4181-bab0-072f0f984569 + Google.Protobuf.Conformance + .\obj + .\bin\ + + + + 2.0 + + + \ No newline at end of file diff --git a/csharp/src/Google.Protobuf.Conformance/Properties/AssemblyInfo.cs b/csharp/src/Google.Protobuf.Conformance/Properties/AssemblyInfo.cs deleted file mode 100644 index d22e90fd8f..0000000000 --- a/csharp/src/Google.Protobuf.Conformance/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,48 +0,0 @@ -#region Copyright notice and license -// Protocol Buffers - Google's data interchange format -// Copyright 2015 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. -#endregion - -using System.Reflection; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Google.Protobuf.Conformance")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Google.Protobuf.Conformance")] -[assembly: AssemblyCopyright("Copyright © 2015")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -[assembly: AssemblyVersion("3.0.0.0")] -[assembly: AssemblyFileVersion("3.0.0.0")] diff --git a/csharp/src/Google.Protobuf.Conformance/project.json b/csharp/src/Google.Protobuf.Conformance/project.json new file mode 100644 index 0000000000..84b23c456d --- /dev/null +++ b/csharp/src/Google.Protobuf.Conformance/project.json @@ -0,0 +1,19 @@ +{ + "buildOptions": { + "debugType": "portable", + "emitEntryPoint": true + }, + "dependencies": { + "Google.Protobuf": { "target": "project" } + }, + "frameworks": { + "netcoreapp1.0": { + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0" + } + } + } + } +} diff --git a/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj b/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj deleted file mode 100644 index ede1f7781c..0000000000 --- a/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj +++ /dev/null @@ -1,68 +0,0 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {D7282E99-2DC3-405B-946F-177DB2FD2AE2} - Exe - Properties - Google.Protobuf.JsonDump - Google.Protobuf.JsonDump - v4.5 - 512 - - - - - true - full - false - bin\Debug - obj\Debug\ - DEBUG;TRACE - prompt - 4 - true - Off - false - - - pdbonly - true - bin\Release - obj\Release\ - TRACE - prompt - 4 - true - Off - false - - - - - - - - - - - - {6908BDCE-D925-43F3-94AC-A531E6DF2591} - Google.Protobuf - - - - - - - - \ No newline at end of file diff --git a/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.xproj b/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.xproj new file mode 100644 index 0000000000..27095be5b3 --- /dev/null +++ b/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.xproj @@ -0,0 +1,19 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 9695e08f-9829-497d-b95c-b38f28d48690 + Google.Protobuf.JsonDump + .\obj + .\bin\ + + + + 2.0 + + + \ No newline at end of file diff --git a/csharp/src/Google.Protobuf.JsonDump/Program.cs b/csharp/src/Google.Protobuf.JsonDump/Program.cs index 99e60e901a..296b2f3f1e 100644 --- a/csharp/src/Google.Protobuf.JsonDump/Program.cs +++ b/csharp/src/Google.Protobuf.JsonDump/Program.cs @@ -32,6 +32,7 @@ using System; using System.IO; +using System.Reflection; namespace Google.Protobuf.ProtoDump { @@ -55,7 +56,7 @@ namespace Google.Protobuf.ProtoDump Console.Error.WriteLine("Unable to load type {0}.", args[0]); return 1; } - if (!typeof(IMessage).IsAssignableFrom(type)) + if (!typeof(IMessage).GetTypeInfo().IsAssignableFrom(type)) { Console.Error.WriteLine("Type {0} doesn't implement IMessage.", args[0]); return 1; diff --git a/csharp/src/Google.Protobuf.JsonDump/Properties/AssemblyInfo.cs b/csharp/src/Google.Protobuf.JsonDump/Properties/AssemblyInfo.cs deleted file mode 100644 index d980b01393..0000000000 --- a/csharp/src/Google.Protobuf.JsonDump/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. - -[assembly: AssemblyTitle("ProtoDump")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("ProtoDump")] -[assembly: AssemblyCopyright("Copyright © 2015")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -[assembly: AssemblyVersion("3.0.0.0")] -[assembly: AssemblyFileVersion("3.0.0.0")] diff --git a/csharp/src/Google.Protobuf.JsonDump/app.config b/csharp/src/Google.Protobuf.JsonDump/app.config deleted file mode 100644 index 51278a4563..0000000000 --- a/csharp/src/Google.Protobuf.JsonDump/app.config +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/csharp/src/Google.Protobuf.JsonDump/project.json b/csharp/src/Google.Protobuf.JsonDump/project.json new file mode 100644 index 0000000000..84b23c456d --- /dev/null +++ b/csharp/src/Google.Protobuf.JsonDump/project.json @@ -0,0 +1,19 @@ +{ + "buildOptions": { + "debugType": "portable", + "emitEntryPoint": true + }, + "dependencies": { + "Google.Protobuf": { "target": "project" } + }, + "frameworks": { + "netcoreapp1.0": { + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0" + } + } + } + } +} diff --git a/csharp/src/Google.Protobuf.Test/FieldCodecTest.cs b/csharp/src/Google.Protobuf.Test/FieldCodecTest.cs index c616470e81..0e2bad59e5 100644 --- a/csharp/src/Google.Protobuf.Test/FieldCodecTest.cs +++ b/csharp/src/Google.Protobuf.Test/FieldCodecTest.cs @@ -32,6 +32,7 @@ using System.Collections.Generic; using System.IO; +using System.Reflection; using Google.Protobuf.TestProtos; using NUnit.Framework; @@ -162,7 +163,7 @@ namespace Google.Protobuf codedOutput.Flush(); Assert.AreEqual(0, stream.Position); Assert.AreEqual(0, codec.CalculateSizeWithTag(codec.DefaultValue)); - if (typeof(T).IsValueType) + if (typeof(T).GetTypeInfo().IsValueType) { Assert.AreEqual(default(T), codec.DefaultValue); } diff --git a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj deleted file mode 100644 index 4f37c5e253..0000000000 --- a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj +++ /dev/null @@ -1,143 +0,0 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {DD01ED24-3750-4567-9A23-1DB676A15610} - Library - Properties - Google.Protobuf - Google.Protobuf.Test - v4.5 - 512 - 3.5 - - - - - - - true - full - false - bin\Debug - obj\Debug\ - DEBUG;TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate) - prompt - 4 - true - Off - false - - - pdbonly - true - bin\Release - obj\Release\ - TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate) - prompt - 4 - true - Off - false - - - pdbonly - true - bin\ReleaseSigned - obj\ReleaseSigned\ - TRACE;$(EnvironmentFlavor);$(EnvironmentTemplate) - prompt - 4 - true - Off - false - True - ..\..\keys\Google.Protobuf.snk - - - - - ..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.dll - True - - - ..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.interfaces.dll - True - - - ..\packages\NUnit.2.6.4\lib\nunit.framework.dll - True - - - ..\packages\NUnitTestAdapter.2.0.0\lib\nunit.util.dll - True - - - ..\packages\NUnitTestAdapter.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll - True - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {6908BDCE-D925-43F3-94AC-A531E6DF2591} - Google.Protobuf - - - - - - - - - - - - \ No newline at end of file diff --git a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.xproj b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.xproj new file mode 100644 index 0000000000..a9a1cc0495 --- /dev/null +++ b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.xproj @@ -0,0 +1,19 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 580eb013-d3c7-4578-b845-015f4a3b0591 + Google.Protobuf.Test + .\obj + .\bin\ + + + + 2.0 + + + \ No newline at end of file diff --git a/csharp/src/Google.Protobuf.Test/Properties/AppManifest.xml b/csharp/src/Google.Protobuf.Test/Properties/AppManifest.xml deleted file mode 100644 index a955232752..0000000000 --- a/csharp/src/Google.Protobuf.Test/Properties/AppManifest.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - diff --git a/csharp/src/Google.Protobuf.Test/Properties/AssemblyInfo.cs b/csharp/src/Google.Protobuf.Test/Properties/AssemblyInfo.cs deleted file mode 100644 index d00acf8554..0000000000 --- a/csharp/src/Google.Protobuf.Test/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. - -[assembly: AssemblyTitle("Google.Protobuf.Test")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Google.Protobuf.Test")] -[assembly: AssemblyCopyright("Copyright © 2015")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -[assembly: AssemblyVersion("3.0.0.0")] -[assembly: AssemblyFileVersion("3.0.0.0")] diff --git a/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs b/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs index f21be7d9b9..4aecc998de 100644 --- a/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs +++ b/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs @@ -96,7 +96,7 @@ namespace Google.Protobuf.WellKnownTypes var message = SampleMessages.CreateFullTestAllTypes(); var any = Any.Pack(message); var text = any.ToString(); - Assert.That(text, Is.StringContaining("\"@value\": \"" + message.ToByteString().ToBase64() + "\"")); + Assert.That(text, Does.Contain("\"@value\": \"" + message.ToByteString().ToBase64() + "\"")); } [Test] diff --git a/csharp/src/Google.Protobuf.Test/WellKnownTypes/FieldMaskTest.cs b/csharp/src/Google.Protobuf.Test/WellKnownTypes/FieldMaskTest.cs index 89bc82759c..1d9908b4d3 100644 --- a/csharp/src/Google.Protobuf.Test/WellKnownTypes/FieldMaskTest.cs +++ b/csharp/src/Google.Protobuf.Test/WellKnownTypes/FieldMaskTest.cs @@ -46,8 +46,8 @@ namespace Google.Protobuf.WellKnownTypes var mask = new FieldMask { Paths = { input } }; var text = mask.ToString(); // More specific test below - Assert.That(text, Is.StringContaining("@warning")); - Assert.That(text, Is.StringContaining(input)); + Assert.That(text, Does.Contain("@warning")); + Assert.That(text, Does.Contain(input)); } [Test] diff --git a/csharp/src/Google.Protobuf.Test/packages.config b/csharp/src/Google.Protobuf.Test/packages.config deleted file mode 100644 index c76539928c..0000000000 --- a/csharp/src/Google.Protobuf.Test/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/csharp/src/Google.Protobuf.Test/project.json b/csharp/src/Google.Protobuf.Test/project.json new file mode 100644 index 0000000000..87b732c9b5 --- /dev/null +++ b/csharp/src/Google.Protobuf.Test/project.json @@ -0,0 +1,44 @@ +{ + "buildOptions": { + "debugType": "portable", + "keyFile": "../../keys/Google.Protobuf.snk" + }, + + "configurations": { + "Debug": { + "buildOptions": { + "define": [ "DEBUG", "TRACE" ] + } + }, + "Release": { + "buildOptions": { + "define": [ "RELEASE", "TRACE" ], + "optimize": true + } + } + }, + + "dependencies": { + "Google.Protobuf": { "target": "project" }, + "NUnit": "3.4.0", + "dotnet-test-nunit": "3.4.0-alpha-2", + }, + + "testRunner": "nunit", + + "frameworks": { + "netcoreapp1.0": { + "imports" : [ "dnxcore50", "netcoreapp1.0", "portable-net45+win8" ], + "buildOptions": { + "define": [ "PCL" ] + }, + "dependencies": { + "Microsoft.NETCore.App": { + "version": "1.0.0", + "type": "platform" + }, + "System.Console": "4.0.0" + } + } + } +} \ No newline at end of file diff --git a/csharp/src/Google.Protobuf.sln b/csharp/src/Google.Protobuf.sln index 72d87f766f..3c62bba334 100644 --- a/csharp/src/Google.Protobuf.sln +++ b/csharp/src/Google.Protobuf.sln @@ -1,54 +1,43 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2015 -VisualStudioVersion = 14.0.24720.0 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 14.0.24720.0 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.Protobuf", "Google.Protobuf\Google.Protobuf.csproj", "{6908BDCE-D925-43F3-94AC-A531E6DF2591}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "AddressBook", "AddressBook\AddressBook.xproj", "{AFB63919-1E05-43B4-802A-8FB8C9B2F463}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.Protobuf.Test", "Google.Protobuf.Test\Google.Protobuf.Test.csproj", "{DD01ED24-3750-4567-9A23-1DB676A15610}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Google.Protobuf", "Google.Protobuf\Google.Protobuf.xproj", "{9B576380-726D-4142-8238-60A43AB0E35A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddressBook", "AddressBook\AddressBook.csproj", "{A31F5FB2-4FF3-432A-B35B-5CD203606311}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Google.Protobuf.Test", "Google.Protobuf.Test\Google.Protobuf.Test.xproj", "{580EB013-D3C7-4578-B845-015F4A3B0591}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.Protobuf.JsonDump", "Google.Protobuf.JsonDump\Google.Protobuf.JsonDump.csproj", "{D7282E99-2DC3-405B-946F-177DB2FD2AE2}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Google.Protobuf.Conformance", "Google.Protobuf.Conformance\Google.Protobuf.Conformance.xproj", "{DDDC055B-E185-4181-BAB0-072F0F984569}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.Protobuf.Conformance", "Google.Protobuf.Conformance\Google.Protobuf.Conformance.csproj", "{0607D1B8-80D6-4B35-9857-1263C1B32B94}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Google.Protobuf.JsonDump", "Google.Protobuf.JsonDump\Google.Protobuf.JsonDump.xproj", "{9695E08F-9829-497D-B95C-B38F28D48690}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU - ReleaseSigned|Any CPU = ReleaseSigned|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {6908BDCE-D925-43F3-94AC-A531E6DF2591}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6908BDCE-D925-43F3-94AC-A531E6DF2591}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6908BDCE-D925-43F3-94AC-A531E6DF2591}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6908BDCE-D925-43F3-94AC-A531E6DF2591}.Release|Any CPU.Build.0 = Release|Any CPU - {6908BDCE-D925-43F3-94AC-A531E6DF2591}.ReleaseSigned|Any CPU.ActiveCfg = ReleaseSigned|Any CPU - {6908BDCE-D925-43F3-94AC-A531E6DF2591}.ReleaseSigned|Any CPU.Build.0 = ReleaseSigned|Any CPU - {DD01ED24-3750-4567-9A23-1DB676A15610}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DD01ED24-3750-4567-9A23-1DB676A15610}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DD01ED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DD01ED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.Build.0 = Release|Any CPU - {DD01ED24-3750-4567-9A23-1DB676A15610}.ReleaseSigned|Any CPU.ActiveCfg = ReleaseSigned|Any CPU - {DD01ED24-3750-4567-9A23-1DB676A15610}.ReleaseSigned|Any CPU.Build.0 = ReleaseSigned|Any CPU - {A31F5FB2-4FF3-432A-B35B-5CD203606311}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A31F5FB2-4FF3-432A-B35B-5CD203606311}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A31F5FB2-4FF3-432A-B35B-5CD203606311}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A31F5FB2-4FF3-432A-B35B-5CD203606311}.Release|Any CPU.Build.0 = Release|Any CPU - {A31F5FB2-4FF3-432A-B35B-5CD203606311}.ReleaseSigned|Any CPU.ActiveCfg = Release|Any CPU - {A31F5FB2-4FF3-432A-B35B-5CD203606311}.ReleaseSigned|Any CPU.Build.0 = Release|Any CPU - {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Release|Any CPU.Build.0 = Release|Any CPU - {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.ReleaseSigned|Any CPU.ActiveCfg = Release|Any CPU - {D7282E99-2DC3-405B-946F-177DB2FD2AE2}.ReleaseSigned|Any CPU.Build.0 = Release|Any CPU - {0607D1B8-80D6-4B35-9857-1263C1B32B94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0607D1B8-80D6-4B35-9857-1263C1B32B94}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0607D1B8-80D6-4B35-9857-1263C1B32B94}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0607D1B8-80D6-4B35-9857-1263C1B32B94}.Release|Any CPU.Build.0 = Release|Any CPU - {0607D1B8-80D6-4B35-9857-1263C1B32B94}.ReleaseSigned|Any CPU.ActiveCfg = Release|Any CPU - {0607D1B8-80D6-4B35-9857-1263C1B32B94}.ReleaseSigned|Any CPU.Build.0 = Release|Any CPU + {AFB63919-1E05-43B4-802A-8FB8C9B2F463}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AFB63919-1E05-43B4-802A-8FB8C9B2F463}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AFB63919-1E05-43B4-802A-8FB8C9B2F463}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AFB63919-1E05-43B4-802A-8FB8C9B2F463}.Release|Any CPU.Build.0 = Release|Any CPU + {9B576380-726D-4142-8238-60A43AB0E35A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9B576380-726D-4142-8238-60A43AB0E35A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9B576380-726D-4142-8238-60A43AB0E35A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9B576380-726D-4142-8238-60A43AB0E35A}.Release|Any CPU.Build.0 = Release|Any CPU + {580EB013-D3C7-4578-B845-015F4A3B0591}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {580EB013-D3C7-4578-B845-015F4A3B0591}.Debug|Any CPU.Build.0 = Debug|Any CPU + {580EB013-D3C7-4578-B845-015F4A3B0591}.Release|Any CPU.ActiveCfg = Release|Any CPU + {580EB013-D3C7-4578-B845-015F4A3B0591}.Release|Any CPU.Build.0 = Release|Any CPU + {DDDC055B-E185-4181-BAB0-072F0F984569}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DDDC055B-E185-4181-BAB0-072F0F984569}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DDDC055B-E185-4181-BAB0-072F0F984569}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DDDC055B-E185-4181-BAB0-072F0F984569}.Release|Any CPU.Build.0 = Release|Any CPU + {9695E08F-9829-497D-B95C-B38F28D48690}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9695E08F-9829-497D-B95C-B38F28D48690}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9695E08F-9829-497D-B95C-B38F28D48690}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9695E08F-9829-497D-B95C-B38F28D48690}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj deleted file mode 100644 index 5557612a83..0000000000 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ /dev/null @@ -1,168 +0,0 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {6908BDCE-D925-43F3-94AC-A531E6DF2591} - Library - Properties - Google.Protobuf - Google.Protobuf - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Profile259 - v4.5 - 512 - 3.5 - 10.0 - - - - - true - full - false - bin\Debug - obj\Debug\ - bin\Debug\Google.Protobuf.xml - - - DEBUG;TRACE - prompt - 4 - true - Off - true - - - pdbonly - true - bin\Release - obj\Release\ - $(OutputPath)\$(AssemblyName).xml - - - TRACE - prompt - 4 - true - Off - true - - - pdbonly - true - bin\ReleaseSigned - obj\ReleaseSigned\ - $(OutputPath)\$(AssemblyName).xml - - - TRACE;SIGNED - prompt - 4 - true - Off - True - ..\..\keys\Google.Protobuf.snk - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - \ No newline at end of file diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.nuspec b/csharp/src/Google.Protobuf/Google.Protobuf.nuspec deleted file mode 100644 index e7b47ffbb1..0000000000 --- a/csharp/src/Google.Protobuf/Google.Protobuf.nuspec +++ /dev/null @@ -1,54 +0,0 @@ - - - - Google.Protobuf - Google Protocol Buffers C# - C# runtime library for Protocol Buffers - Google's data interchange format. - See project site for more info. - 3.0.0-beta4 - Google Inc. - protobuf-packages - https://github.com/google/protobuf/blob/master/LICENSE - https://github.com/google/protobuf - false - C# proto3 support - Copyright 2015, Google Inc. - Protocol Buffers Binary Serialization Format Google proto proto3 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.xproj b/csharp/src/Google.Protobuf/Google.Protobuf.xproj new file mode 100644 index 0000000000..c68e0db31a --- /dev/null +++ b/csharp/src/Google.Protobuf/Google.Protobuf.xproj @@ -0,0 +1,19 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 9b576380-726d-4142-8238-60a43ab0e35a + Google.Protobuf + .\obj + .\bin\ + + + + 2.0 + + + \ No newline at end of file diff --git a/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs b/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs index 1673edfb03..9b179bd7cd 100644 --- a/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs +++ b/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs @@ -30,7 +30,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion -using System.Reflection; using System.Runtime.CompilerServices; using System.Security; @@ -38,30 +37,13 @@ using System.Security; // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("Google.Protobuf")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Google.Protobuf")] -[assembly: AssemblyCopyright("Copyright © 2015")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - #if !NCRUNCH [assembly: AllowPartiallyTrustedCallers] #endif -#if SIGNED [assembly: InternalsVisibleTo("Google.Protobuf.Test, PublicKey=" + "002400000480000094000000060200000024000052534131000400000100010025800fbcfc63a1" + "7c66b303aae80b03a6beaa176bb6bef883be436f2a1579edd80ce23edf151a1f4ced97af83abcd" + "981207041fd5b2da3b498346fcfcd94910d52f25537c4a43ce3fbe17dc7d43e6cbdb4d8f1242dc" + "b6bd9b5906be74da8daa7d7280f97130f318a16c07baf118839b156299a48522f9fae2371c9665" + "c5ae9cb6")] -#else -[assembly: InternalsVisibleTo("Google.Protobuf.Test")] -#endif - -[assembly: AssemblyVersion("3.0.0.0")] -[assembly: AssemblyFileVersion("3.0.0.0")] -[assembly: AssemblyInformationalVersion("3.0.0-beta4")] diff --git a/csharp/src/Google.Protobuf/packages.config b/csharp/src/Google.Protobuf/packages.config deleted file mode 100644 index 40b8fd927e..0000000000 --- a/csharp/src/Google.Protobuf/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/csharp/src/Google.Protobuf/project.json b/csharp/src/Google.Protobuf/project.json new file mode 100644 index 0000000000..c8eae6d0b0 --- /dev/null +++ b/csharp/src/Google.Protobuf/project.json @@ -0,0 +1,65 @@ +{ + "version": "3.0.0-beta4", + "title": "Google Protocol Buffers", + "description": "See project site for more info.", + "authors": [ "Google Inc." ], + "copyright": "Copyright 2015, Google Inc.", + + "packOptions": { + "summary": "C# runtime library for Protocol Buffers - Google's data interchange format.", + "tags": [ "Protocol", "Buffers", "Binary", "Serialization", "Format", "Google", "proto", "proto3" ], + "owners": [ "protobuf-packages" ], + "licenseUrl": "https://github.com/google/protobuf/blob/master/LICENSE", + "projectUrl": "https://github.com/google/protobuf", + "releaseNotes": "C# proto3 support", + "requireLicenseAcceptance": false, + "repository": { + "url": "https://github.com/nodatime/nodatime.git" + } + }, + + "buildOptions": { + "debugType": "portable", + "keyFile": "../../keys/Google.Protobuf.snk", + "xmlDoc": true + }, + + "configurations": { + "Debug": { + "buildOptions": { + "define": [ "DEBUG", "TRACE" ] + } + }, + "Release": { + "buildOptions": { + "define": [ "RELEASE", "TRACE" ], + "optimize": true + } + } + }, + + "frameworks": { + // This target allows the package to be installed in a .NET 4.5+ + // project without asking for myriad other dependencies. + "net45": { + }, + "netstandard1.0": { + "dependencies": { + "System.Collections": "4.0.11", + "System.Diagnostics.Debug": "4.0.11", + "System.Globalization": "4.0.11", + "System.IO": "4.1.0", + "System.Linq": "4.1.0", + "System.Linq.Expressions": "4.1.0", + "System.ObjectModel": "4.0.12", + "System.Reflection": "4.1.0", + "System.Reflection.Extensions": "4.0.1", + "System.Runtime": "4.1.0", + "System.Runtime.Extensions": "4.1.0", + "System.Text.Encoding": "4.0.11", + "System.Text.RegularExpressions": "4.1.0", + "System.Threading": "4.0.11" + } + } + } +} diff --git a/jenkins/docker/Dockerfile b/jenkins/docker/Dockerfile index 8467aeff51..c928ac71a3 100644 --- a/jenkins/docker/Dockerfile +++ b/jenkins/docker/Dockerfile @@ -23,6 +23,13 @@ run echo "deb http://download.mono-project.com/repo/debian wheezy main" | tee /e echo "deb http://download.mono-project.com/repo/debian wheezy-libjpeg62-compat main" | tee -a /etc/apt/sources.list.d/mono-xamarin.list && \ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF +# Install dotnet SDK based on https://www.microsoft.com/net/core#debian +# (Ubuntu instructions need apt to support https) +RUN apt-get update && apt-get install -y curl libunwind8 gettext && \ + curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=809130 && \ + mkdir -p /opt/dotnet && tar zxf dotnet.tar.gz -C /opt/dotnet && \ + ln -s /opt/dotnet/dotnet /usr/local/bin + # Install dependencies. We start with the basic ones require to build protoc # and the C++ build RUN apt-get update && apt-get install -y \ diff --git a/tests.sh b/tests.sh index 72465a7b0c..99e5df4ea3 100755 --- a/tests.sh +++ b/tests.sh @@ -57,15 +57,27 @@ build_csharp() { if [ "$TRAVIS" == "true" ]; then # Install latest version of Mono sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF + sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1397BC53640DB551 echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list - echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list sudo apt-get update -qq sudo apt-get install -qq mono-devel referenceassemblies-pcl nunit - wget www.nuget.org/NuGet.exe -O nuget.exe - NUGET=../../nuget.exe + + # Then install the dotnet SDK as per Ubuntu 14.04 instructions on dot.net. + sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list' + sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893 + sudo apt-get update -qq + sudo apt-get install -qq dotnet-dev-1.0.0-preview2-003121 fi - (cd csharp/src; mono $NUGET restore) + # Perform "dotnet new" once to get the setup preprocessing out of the + # way. That spews a lot of output (including backspaces) into logs + # otherwise, and can cause problems. It doesn't matter if this step + # is performed multiple times; it's cheap after the first time anyway. + mkdir dotnettmp + (cd dotnettmp; dotnet new > /dev/null) + rm -rf dotnettmp + + (cd csharp/src; dotnet restore) csharp/buildall.sh cd conformance && make test_csharp && cd .. } From 0b6825516b403ce7f9c830074d3cbb5477b4c6a1 Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Thu, 14 Jul 2016 15:21:10 -0700 Subject: [PATCH 14/18] Add missing golden test file. --- src/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Makefile.am b/src/Makefile.am index b75b6f74de..81ebc9541b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -530,6 +530,7 @@ EXTRA_DIST = \ google/protobuf/io/gzip_stream.h \ google/protobuf/io/gzip_stream_unittest.sh \ google/protobuf/testdata/golden_message \ + google/protobuf/testdata/golden_message_maps \ google/protobuf/testdata/golden_message_oneof_implemented \ google/protobuf/testdata/golden_message_proto3 \ google/protobuf/testdata/golden_packed_fields_message \ From 1bce70dddb57aa82c3e6a74b072f6a742f47c900 Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Thu, 14 Jul 2016 15:33:45 -0700 Subject: [PATCH 15/18] Fix compatiblity issues. Currently some public API methods are defined in GenreatedMessage.java and they have a generric return type: class GeneratedMessage { class Builder> { public BuilderType setField(...); public BuilderType setExtension(...); } } With these definitions, the compiled byte code of a callsite will have a direct reference to GeneratedMessage. For example: fooBuilder.setField(...); becomes: ##: invokevirtual // Method Builder.setField:(...)LGeneratedMessage.Builder ##: checkcast // class Builder This will prevent us from updating generated classes to subclass a different versioned GeneratedMessageV3 class in the future (we can't do it in a binary compatible way). This change addresses the problem by overriding these methods directly in the generated class: class Foo { class Builder extends GeneratedMessage.Builder { public Builder setField(...) { return super.setField(...); } } } After this, fooBuilder.setField(...) will be compiled to: ##: invokevirtual // Method Builder.setField:(...)LFoo.Builder The callsites will no longer reference GeneratedMessage directly and we can change Foo to subclass GeneratedMessageV3 without breaking binary compatiblity. The downside of this change is: 1. It increases generated code size (though it saves some instructions on the callsites). 2. We can never stop generating these overrides because doing that will break binary compatibility. Change-Id: I879afbbc1325a66324a51565e017143489b06e97 --- .../com/google/protobuf/GeneratedMessage.java | 8 +-- .../compiler/java/java_message_builder.cc | 68 +++++++++++++++++++ 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java index 2c87302bc2..cea0579424 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java @@ -1396,7 +1396,7 @@ public abstract class GeneratedMessage extends AbstractMessage return setExtension((ExtensionLite) extension, value); } /** Set the value of an extension. */ - public final BuilderType setExtension( + public BuilderType setExtension( final GeneratedExtension extension, final Type value) { return setExtension((ExtensionLite) extension, value); } @@ -1407,7 +1407,7 @@ public abstract class GeneratedMessage extends AbstractMessage return setExtension((ExtensionLite>) extension, index, value); } /** Set the value of one element of a repeated extension. */ - public final BuilderType setExtension( + public BuilderType setExtension( final GeneratedExtension> extension, final int index, final Type value) { return setExtension((ExtensionLite>) extension, index, value); @@ -1418,7 +1418,7 @@ public abstract class GeneratedMessage extends AbstractMessage return addExtension((ExtensionLite>) extension, value); } /** Append a value to a repeated extension. */ - public final BuilderType addExtension( + public BuilderType addExtension( final GeneratedExtension> extension, final Type value) { return addExtension((ExtensionLite>) extension, value); } @@ -1428,7 +1428,7 @@ public abstract class GeneratedMessage extends AbstractMessage return clearExtension((ExtensionLite) extension); } /** Clear an extension. */ - public final BuilderType clearExtension( + public BuilderType clearExtension( final GeneratedExtension extension) { return clearExtension((ExtensionLite) extension); } diff --git a/src/google/protobuf/compiler/java/java_message_builder.cc b/src/google/protobuf/compiler/java/java_message_builder.cc index b3e9e986c4..81a70a1f51 100644 --- a/src/google/protobuf/compiler/java/java_message_builder.cc +++ b/src/google/protobuf/compiler/java/java_message_builder.cc @@ -181,6 +181,18 @@ Generate(io::Printer* printer) { " return this;\n" "}\n" "\n"); + } else { + printer->Print( + "public final Builder setUnknownFields(\n" + " final com.google.protobuf.UnknownFieldSet unknownFields) {\n" + " return super.setUnknownFields(unknownFields);\n" + "}\n" + "\n" + "public final Builder mergeUnknownFields(\n" + " final com.google.protobuf.UnknownFieldSet unknownFields) {\n" + " return super.mergeUnknownFields(unknownFields);\n" + "}\n" + "\n"); } printer->Print( @@ -438,6 +450,62 @@ GenerateCommonBuilderMethods(io::Printer* printer) { "\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); + printer->Print( + "public Builder clone() {\n" + " return (Builder) super.clone();\n" + "}\n" + "public Builder setField(\n" + " com.google.protobuf.Descriptors.FieldDescriptor field,\n" + " Object value) {\n" + " return (Builder) super.setField(field, value);\n" + "}\n" + "public Builder clearField(\n" + " com.google.protobuf.Descriptors.FieldDescriptor field) {\n" + " return (Builder) super.clearField(field);\n" + "}\n" + "public Builder clearOneof(\n" + " com.google.protobuf.Descriptors.OneofDescriptor oneof) {\n" + " return (Builder) super.clearOneof(oneof);\n" + "}\n" + "public Builder setRepeatedField(\n" + " com.google.protobuf.Descriptors.FieldDescriptor field,\n" + " int index, Object value) {\n" + " return (Builder) super.setRepeatedField(field, index, value);\n" + "}\n" + "public Builder addRepeatedField(\n" + " com.google.protobuf.Descriptors.FieldDescriptor field,\n" + " Object value) {\n" + " return (Builder) super.addRepeatedField(field, value);\n" + "}\n"); + + if (descriptor_->extension_range_count() > 0) { + printer->Print( + "public Builder setExtension(\n" + " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n" + " $classname$, Type> extension,\n" + " Type value) {\n" + " return (Builder) super.setExtension(extension, value);\n" + "}\n" + "public Builder setExtension(\n" + " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n" + " $classname$, java.util.List> extension,\n" + " int index, Type value) {\n" + " return (Builder) super.setExtension(extension, index, value);\n" + "}\n" + "public Builder addExtension(\n" + " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n" + " $classname$, java.util.List> extension,\n" + " Type value) {\n" + " return (Builder) super.addExtension(extension, value);\n" + "}\n" + "public Builder clearExtension(\n" + " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n" + " $classname$, ?> extension) {\n" + " return (Builder) super.clearExtension(extension);\n" + "}\n", + "classname", name_resolver_->GetImmutableClassName(descriptor_)); + } + // ----------------------------------------------------------------- if (context_->HasGeneratedMethods(descriptor_)) { From 1349fb8b14936afc20ec348e1c6a9e7f8efd66a0 Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Fri, 15 Jul 2016 12:19:15 -0700 Subject: [PATCH 16/18] Added 3.0.0-beta-4 changelog. Change-Id: I997012e7e9b58d9ec8b2f59429d71c98d81aa40d --- CHANGES.txt | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 3459cccfa9..f3524b866b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,83 @@ +2016-07-15 version 3.0.0-beta-4 (C++/Java/Python/Ruby/Objective-C/C#/JavaScript) + General + * Added a deterministic serialization API for C++ and Java. The deterministic + serialization guarantees that given a binary, equal messages will be + serialized to the same bytes. This allows applications like MapReduce to + group equal messages based on the serialized bytes. The deterministic + serialization is, however, NOT canonical across languages; it is also + unstable across different builds with schema changes due to unknown fields. + Users who need canonical serialization, e.g. persistent storage in a + canonical form, fingerprinting, etc, should define their own + canonicalization specification and implement the serializer using reflection + APIs rather than relying on this API. + * Added OneofOptions. You can now define custom options for oneof groups. + import "google/protobuf/descriptor.proto"; + extend google.protobuf.OneofOptions { + optional int32 my_oneof_extension = 12345; + } + message Foo { + oneof oneof_group { + (my_oneof_extension) = 54321; + ... + } + } + + C++ (beta) + * Introduced a deterministic serialization API in + CodedOutputStream::SetSerializationDeterministic(bool). See the notes about + deterministic serialization in the General section. + * Added google::protobuf::Map::swap() to swap two map fields. + * Fixed a memory leak when calling Reflection::ReleaseMessage() on a message + allocated on arena. + * Improved error reporting when parsing text format protos. + * JSON + - Added a new parser option to ignore unknown fields when parsing JSON. + - Added convenient methods for message to/from JSON conversion. + * Various performance optimizations. + + Java (beta) + * Introduced a deterministic serialization API in + CodedOutputStream#useDeterministicSerialization(). See the notes about + deterministic serialization in the General section. + * File option "java_generate_equals_and_hash" is now deprecated. equals() and + hashCode() methods are generated by default. + * Added a new JSON printer option "omittingInsignificantWhitespace" to produce + a more compact JSON output. The printer will pretty-print by default. + * Updated Java runtime to be compatible with 2.5.0/2.6.1 generated protos. + + Python (beta) + * Added support to pretty print Any messages in text format. + * Added a flag to ignore unknown fields when parsing JSON. + * Bugfix: "@type" field of a JSON Any message is now correctly put before + other fields. + + Objective-C (beta) + * Updated the code to support compiling with more compiler warnings + enabled. (Issue 1616) + * Exposing more detailed errors for parsing failures. (PR 1623) + * Small (breaking) change to the naming of some methods on the support classes + for map<>. There were collisions with the system provided KVO support, so + the names were changed to avoid those issues. (PR 1699) + * Fixed for proper Swift bridging of error handling during parsing. (PR 1712) + * Complete support for generating sources that will go into a Framework and + depend on generated sources from other Frameworks. (Issue 1457) + + C# (beta) + * RepeatedField optimizations. + * Support for .NET Core. + * Minor bug fixes. + * Ability to format a single value in JsonFormatter (advanced usage only). + * Modifications to attributes applied to generated code. + + Javascript (alpha) + * Maps now have a real map API instead of being treated as repeated fields. + * Well-known types are now provided in the google-protobuf package, and the + code generator knows to require() them from that package. + * Bugfix: non-canonical varints are correctly decoded. + + Ruby (alpha) + * Accessors for oneof fields now return default values instead of nil. + 2016-05-16 version 3.0.0-beta-3 (C++/Java/Python/Ruby/Nano/Objective-C/C#/JavaScript) General * Supported Proto3 lite-runtime in C++/Java for mobile platforms. From 3d9726f919cbbc403538c5a09649c6bf38561fef Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Fri, 15 Jul 2016 15:26:44 -0700 Subject: [PATCH 17/18] Mention Java lite in the changelog. Change-Id: Ic07a7c664930209974244c66885d672288982610 --- CHANGES.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index f3524b866b..5c73be1537 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -78,6 +78,10 @@ Ruby (alpha) * Accessors for oneof fields now return default values instead of nil. + Java Lite + * Java lite support is removed from protocol compiler. It will be supported + as a protocol compiler plugin in a separate code branch. + 2016-05-16 version 3.0.0-beta-3 (C++/Java/Python/Ruby/Nano/Objective-C/C#/JavaScript) General * Supported Proto3 lite-runtime in C++/Java for mobile platforms. From 82b43d1f41d6c374ebdd942dd86602736c2218e8 Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Mon, 18 Jul 2016 10:36:04 -0700 Subject: [PATCH 18/18] Remove Java deterministic API. Change-Id: I43f7e04a53d1445dfa86db310bdb18ceb446398c --- CHANGES.txt | 5 +---- .../src/main/java/com/google/protobuf/CodedOutputStream.java | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 5c73be1537..04fa418efe 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,6 @@ 2016-07-15 version 3.0.0-beta-4 (C++/Java/Python/Ruby/Objective-C/C#/JavaScript) General - * Added a deterministic serialization API for C++ and Java. The deterministic + * Added a deterministic serialization API for C++. The deterministic serialization guarantees that given a binary, equal messages will be serialized to the same bytes. This allows applications like MapReduce to group equal messages based on the serialized bytes. The deterministic @@ -36,9 +36,6 @@ * Various performance optimizations. Java (beta) - * Introduced a deterministic serialization API in - CodedOutputStream#useDeterministicSerialization(). See the notes about - deterministic serialization in the General section. * File option "java_generate_equals_and_hash" is now deprecated. equals() and hashCode() methods are generated by default. * Added a new JSON printer option "omittingInsignificantWhitespace" to produce diff --git a/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java b/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java index 4f5a9b770e..e5515285de 100644 --- a/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java +++ b/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java @@ -173,7 +173,7 @@ public abstract class CodedOutputStream extends ByteOutput { * maps are sorted on the lexicographical order of the UTF8 encoded keys. * */ - public final void useDeterministicSerialization() { + void useDeterministicSerialization() { serializationDeterministic = true; }