diff options
114 files changed, 3684 insertions, 3115 deletions
@@ -541,6 +541,7 @@ cc_test( "src/google/protobuf/any_test.cc", "src/google/protobuf/arena_unittest.cc", "src/google/protobuf/arenastring_unittest.cc", + "src/google/protobuf/compiler/annotation_test_util.cc", "src/google/protobuf/compiler/command_line_interface_unittest.cc", "src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc", "src/google/protobuf/compiler/cpp/cpp_move_unittest.cc", diff --git a/cmake/tests.cmake b/cmake/tests.cmake index 389f6a7b..d4622c6b 100644 --- a/cmake/tests.cmake +++ b/cmake/tests.cmake @@ -121,6 +121,7 @@ set(tests_files ${protobuf_source_dir}/src/google/protobuf/any_test.cc ${protobuf_source_dir}/src/google/protobuf/arena_unittest.cc ${protobuf_source_dir}/src/google/protobuf/arenastring_unittest.cc + ${protobuf_source_dir}/src/google/protobuf/compiler/annotation_test_util.cc ${protobuf_source_dir}/src/google/protobuf/compiler/command_line_interface_unittest.cc ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_move_unittest.cc diff --git a/conformance/failure_list_js.txt b/conformance/failure_list_js.txt index eb20f659..f8f6a578 100644 --- a/conformance/failure_list_js.txt +++ b/conformance/failure_list_js.txt @@ -1,5 +1,3 @@ -Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.INT32.ProtobufOutput -Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT32.ProtobufOutput Required.Proto3.ProtobufInput.ValidDataRepeated.BOOL.ProtobufOutput Required.Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.ProtobufOutput Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.ProtobufOutput @@ -13,7 +11,3 @@ Required.Proto3.ProtobufInput.ValidDataRepeated.SINT32.ProtobufOutput Required.Proto3.ProtobufInput.ValidDataRepeated.SINT64.ProtobufOutput Required.Proto3.ProtobufInput.ValidDataRepeated.UINT32.ProtobufOutput Required.Proto3.ProtobufInput.ValidDataRepeated.UINT64.ProtobufOutput -Required.Proto2.ProtobufInput.RepeatedScalarSelectsLast.INT32.ProtobufOutput -Required.Proto2.ProtobufInput.RepeatedScalarSelectsLast.UINT32.ProtobufOutput -Required.Proto2.ProtobufInput.ValidDataRepeated.INT32.ProtobufOutput -Required.Proto2.ProtobufInput.ValidDataRepeated.UINT32.ProtobufOutput diff --git a/conformance/failure_list_python.txt b/conformance/failure_list_python.txt index 062c22a8..e3ce7af7 100644 --- a/conformance/failure_list_python.txt +++ b/conformance/failure_list_python.txt @@ -7,7 +7,6 @@ Recommended.Proto3.JsonInput.FloatFieldInfinityNotQuoted Recommended.Proto3.JsonInput.FloatFieldNanNotQuoted Recommended.Proto3.JsonInput.FloatFieldNegativeInfinityNotQuoted Required.Proto3.JsonInput.DoubleFieldTooSmall -Required.Proto3.JsonInput.EnumFieldUnknownValue.Validator Required.Proto3.JsonInput.FloatFieldTooLarge Required.Proto3.JsonInput.FloatFieldTooSmall Required.Proto3.JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotBool diff --git a/conformance/failure_list_python_cpp.txt b/conformance/failure_list_python_cpp.txt index e2c258de..a498ad1a 100644 --- a/conformance/failure_list_python_cpp.txt +++ b/conformance/failure_list_python_cpp.txt @@ -16,7 +16,6 @@ Recommended.Proto3.JsonInput.FloatFieldInfinityNotQuoted Recommended.Proto3.JsonInput.FloatFieldNanNotQuoted Recommended.Proto3.JsonInput.FloatFieldNegativeInfinityNotQuoted Required.Proto3.JsonInput.DoubleFieldTooSmall -Required.Proto3.JsonInput.EnumFieldUnknownValue.Validator Required.Proto3.JsonInput.FloatFieldTooLarge Required.Proto3.JsonInput.FloatFieldTooSmall Required.Proto3.JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotBool diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs index 8c37ba86..6aad0e99 100644 --- a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs @@ -3478,7 +3478,8 @@ namespace Google.Protobuf.Reflection { = pb::FieldCodec.ForMessage(7994, global::Google.Protobuf.Reflection.UninterpretedOption.Parser); private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption> uninterpretedOption_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption>(); /// <summary> - /// The parser stores options it doesn't recognize here. See above. + /// The parser stores options it doesn't recognize here. + /// See the documentation for the "Options" section above. /// </summary> [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption> UninterpretedOption { diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs index ef3bc10a..ee4561ff 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs @@ -239,6 +239,12 @@ namespace Google.Protobuf.WellKnownTypes { /// /// Note that oneof type names ("test_oneof" in this case) cannot be used in /// paths. + /// + /// ## Field Mask Verification + /// + /// The implementation of the all the API methods, which have any FieldMask type + /// field in the request, should verify the included field paths, and return + /// `INVALID_ARGUMENT` error if any path is duplicated or unmappable. /// </summary> public sealed partial class FieldMask : pb::IMessage<FieldMask> { private static readonly pb::MessageParser<FieldMask> _parser = new pb::MessageParser<FieldMask>(() => new FieldMask()); diff --git a/java/core/src/main/java/com/google/protobuf/AbstractMessage.java b/java/core/src/main/java/com/google/protobuf/AbstractMessage.java index 065fa1a9..908764df 100644 --- a/java/core/src/main/java/com/google/protobuf/AbstractMessage.java +++ b/java/core/src/main/java/com/google/protobuf/AbstractMessage.java @@ -380,6 +380,10 @@ public abstract class AbstractMessage @Override public BuilderType mergeFrom(final Message other) { + return mergeFrom(other, other.getAllFields()); + } + + BuilderType mergeFrom(final Message other, Map<FieldDescriptor, Object> allFields) { if (other.getDescriptorForType() != getDescriptorForType()) { throw new IllegalArgumentException( "mergeFrom(Message) can only merge messages of the same type."); @@ -394,8 +398,7 @@ public abstract class AbstractMessage // TODO(kenton): Provide a function somewhere called makeDeepCopy() // which allows people to make secure deep copies of messages. - for (final Map.Entry<FieldDescriptor, Object> entry : - other.getAllFields().entrySet()) { + for (final Map.Entry<FieldDescriptor, Object> entry : allFields.entrySet()) { final FieldDescriptor field = entry.getKey(); if (field.isRepeated()) { for (final Object element : (List)entry.getValue()) { diff --git a/java/core/src/main/java/com/google/protobuf/CodedInputStream.java b/java/core/src/main/java/com/google/protobuf/CodedInputStream.java index 511501d4..e08a993b 100644 --- a/java/core/src/main/java/com/google/protobuf/CodedInputStream.java +++ b/java/core/src/main/java/com/google/protobuf/CodedInputStream.java @@ -413,8 +413,7 @@ public abstract class CodedInputStream { private boolean explicitDiscardUnknownFields = false; - /** TODO(liujisi): flip the default.*/ - private static volatile boolean proto3DiscardUnknownFieldsDefault = true; + private static volatile boolean proto3DiscardUnknownFieldsDefault = false; static void setProto3DiscardUnknownsByDefaultForTest() { proto3DiscardUnknownFieldsDefault = true; diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java index 99864964..09084646 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java @@ -31,7 +31,6 @@ package com.google.protobuf; import com.google.protobuf.AbstractMessageLite.Builder.LimitedInputStream; -import com.google.protobuf.GeneratedMessageLite.EqualsVisitor.NotEqualsException; import com.google.protobuf.Internal.BooleanList; import com.google.protobuf.Internal.DoubleList; import com.google.protobuf.Internal.EnumLiteMap; @@ -52,6 +51,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** * Lite version of {@link GeneratedMessage}. @@ -62,6 +62,12 @@ public abstract class GeneratedMessageLite< MessageType extends GeneratedMessageLite<MessageType, BuilderType>, BuilderType extends GeneratedMessageLite.Builder<MessageType, BuilderType>> extends AbstractMessageLite<MessageType, BuilderType> { + // BEGIN REGULAR + static final boolean ENABLE_EXPERIMENTAL_RUNTIME_AT_BUILD_TIME = false; + // END REGULAR + // BEGIN EXPERIMENTAL + // static final boolean ENABLE_EXPERIMENTAL_RUNTIME_AT_BUILD_TIME = true; + // END EXPERIMENTAL /** For use by generated code only. Lazily initialized to reduce allocations. */ protected UnknownFieldSetLite unknownFields = UnknownFieldSetLite.getDefaultInstance(); @@ -110,12 +116,19 @@ public abstract class GeneratedMessageLite< if (memoizedHashCode != 0) { return memoizedHashCode; } + // BEGIN EXPERIMENTAL + // memoizedHashCode = Protobuf.getInstance().schemaFor(this).hashCode(this); + // return memoizedHashCode; + // END EXPERIMENTAL + // BEGIN REGULAR HashCodeVisitor visitor = new HashCodeVisitor(); visit(visitor, (MessageType) this); memoizedHashCode = visitor.hashCode; return memoizedHashCode; + // END REGULAR } + // BEGIN REGULAR @SuppressWarnings("unchecked") // Guaranteed by runtime int hashCode(HashCodeVisitor visitor) { if (memoizedHashCode == 0) { @@ -127,6 +140,7 @@ public abstract class GeneratedMessageLite< } return memoizedHashCode; } + // END REGULAR @SuppressWarnings("unchecked") // Guaranteed by isInstance + runtime @Override @@ -139,18 +153,22 @@ public abstract class GeneratedMessageLite< return false; } + // BEGIN EXPERIMENTAL + // return Protobuf.getInstance().schemaFor(this).equals(this, (MessageType) other); + // END EXPERIMENTAL + // BEGIN REGULAR try { visit(EqualsVisitor.INSTANCE, (MessageType) other); - } catch (NotEqualsException e) { + } catch (EqualsVisitor.NotEqualsException e) { return false; } return true; + // END REGULAR } - /** - * Same as {@link #equals(Object)} but throws {@code NotEqualsException}. - */ + // BEGIN REGULAR + /** Same as {@link #equals(Object)} but throws {@code NotEqualsException}. */ @SuppressWarnings("unchecked") // Guaranteed by isInstance + runtime boolean equals(EqualsVisitor visitor, MessageLite other) { if (this == other) { @@ -164,14 +182,13 @@ public abstract class GeneratedMessageLite< visit(visitor, (MessageType) other); return true; } + // END REGULAR // The general strategy for unknown fields is to use an UnknownFieldSetLite that is treated as // mutable during the parsing constructor and immutable after. This allows us to avoid // any unnecessary intermediary allocations while reducing the generated code size. - /** - * Lazily initializes unknown fields. - */ + /** Lazily initializes unknown fields. */ private final void ensureUnknownFieldsInitialized() { if (unknownFields == UnknownFieldSetLite.getDefaultInstance()) { unknownFields = UnknownFieldSetLite.newInstance(); @@ -218,6 +235,20 @@ public abstract class GeneratedMessageLite< unknownFields.makeImmutable(); } + protected final < + MessageType extends GeneratedMessageLite<MessageType, BuilderType>, + BuilderType extends GeneratedMessageLite.Builder<MessageType, BuilderType>> + BuilderType createBuilder() { + return (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER); + } + + protected final < + MessageType extends GeneratedMessageLite<MessageType, BuilderType>, + BuilderType extends GeneratedMessageLite.Builder<MessageType, BuilderType>> + BuilderType createBuilder(MessageType prototype) { + return ((BuilderType) createBuilder()).mergeFrom(prototype); + } + @Override public final boolean isInitialized() { return isInitialized((MessageType) this, Boolean.TRUE); @@ -238,11 +269,13 @@ public abstract class GeneratedMessageLite< * For use by generated code only. */ public static enum MethodToInvoke { - // Rely on/modify instance state IS_INITIALIZED, + // BEGIN REGULAR + VISIT, + // END REGULAR + // Rely on/modify instance state GET_MEMOIZED_IS_INITIALIZED, SET_MEMOIZED_IS_INITIALIZED, - VISIT, MERGE_FROM_STREAM, MAKE_IMMUTABLE, @@ -299,10 +332,13 @@ public abstract class GeneratedMessageLite< return dynamicMethod(method, null, null); } + // BEGIN REGULAR void visit(Visitor visitor, MessageType other) { dynamicMethod(MethodToInvoke.VISIT, visitor, other); unknownFields = visitor.visitUnknownFields(unknownFields, other.unknownFields); } + // END REGULAR + /** @@ -399,7 +435,12 @@ public abstract class GeneratedMessageLite< } private void mergeFromInstance(MessageType dest, MessageType src) { + // BEGIN EXPERIMENTAL + // Protobuf.getInstance().schemaFor(dest).mergeFrom(dest, src); + // END EXPERIMENTAL + // BEGIN REGULAR dest.visit(MergeFromVisitor.INSTANCE, src); + // END REGULAR } @Override @@ -477,11 +518,13 @@ public abstract class GeneratedMessageLite< extensions.mergeFrom(((ExtendableMessage) other).extensions); } + // BEGIN REGULAR @Override final void visit(Visitor visitor, MessageType other) { super.visit(visitor, other); extensions = visitor.visitExtensions(extensions, other.extensions); } + // END REGULAR /** * Parse an unknown field or an extension. For use by generated code only. @@ -494,7 +537,8 @@ public abstract class GeneratedMessageLite< MessageType defaultInstance, CodedInputStream input, ExtensionRegistryLite extensionRegistry, - int tag) throws IOException { + int tag) + throws IOException { int fieldNumber = WireFormat.getTagFieldNumber(tag); // TODO(dweis): How much bytecode would be saved by not requiring the generated code to @@ -1716,6 +1760,7 @@ public abstract class GeneratedMessageLite< return message; } + // BEGIN REGULAR /** * An abstract visitor that the generated code calls into that we use to implement various * features. Fields that are not members of oneofs are always visited. Members of a oneof are only @@ -2401,4 +2446,5 @@ public abstract class GeneratedMessageLite< return mine; } } + // END REGULAR } diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java index 592869a1..4acd8f2f 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java @@ -358,6 +358,10 @@ public abstract class GeneratedMessageV3 extends AbstractMessage throw e.unwrapIOException(); } } + + protected static boolean canUseUnsafe() { + return UnsafeUtil.hasUnsafeArrayOperations() && UnsafeUtil.hasUnsafeByteBufferOperations(); + } @Override public void writeTo(final CodedOutputStream output) throws IOException { @@ -655,6 +659,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage .build()); } + @Override public boolean isInitialized() { for (final FieldDescriptor field : getDescriptorForType().getFields()) { @@ -2853,3 +2858,4 @@ public abstract class GeneratedMessageV3 extends AbstractMessage } } } + diff --git a/java/core/src/main/java/com/google/protobuf/Message.java b/java/core/src/main/java/com/google/protobuf/Message.java index 94590fb9..0770d417 100644 --- a/java/core/src/main/java/com/google/protobuf/Message.java +++ b/java/core/src/main/java/com/google/protobuf/Message.java @@ -125,7 +125,7 @@ public interface Message extends MessageLite, MessageOrBuilder { * it is merged into the corresponding sub-message of this message * using the same merging rules.<br> * * For repeated fields, the elements in {@code other} are concatenated - * with the elements in this message. + * with the elements in this message.<br> * * For oneof groups, if the other message has one of the fields set, * the group of this message is cleared and replaced by the field * of the other message, so that the oneof constraint is preserved. 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 ff686a0c..42da5bb3 100644 --- a/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java +++ b/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java @@ -404,34 +404,4 @@ public class FieldPresenceTest extends TestCase { assertTrue(builder.buildPartial().isInitialized()); } - - // Test that unknown fields are dropped. - public void testUnknownFields() throws Exception { - TestAllTypes.Builder builder = TestAllTypes.newBuilder(); - builder.setOptionalInt32(1234); - builder.addRepeatedInt32(5678); - TestAllTypes message = builder.build(); - ByteString data = message.toByteString(); - - TestOptionalFieldsOnly optionalOnlyMessage = - TestOptionalFieldsOnly.parseFrom(data); - // UnknownFieldSet should be empty. - assertEquals( - 0, optionalOnlyMessage.getUnknownFields().toByteString().size()); - assertEquals(1234, optionalOnlyMessage.getOptionalInt32()); - message = TestAllTypes.parseFrom(optionalOnlyMessage.toByteString()); - assertEquals(1234, message.getOptionalInt32()); - // The repeated field is discarded because it's unknown to the optional-only - // message. - assertEquals(0, message.getRepeatedInt32Count()); - - DynamicMessage dynamicOptionalOnlyMessage = - DynamicMessage.getDefaultInstance( - TestOptionalFieldsOnly.getDescriptor()) - .getParserForType().parseFrom(data); - assertEquals( - 0, dynamicOptionalOnlyMessage.getUnknownFields().toByteString().size()); - assertEquals(optionalOnlyMessage.toByteString(), - dynamicOptionalOnlyMessage.toByteString()); - } } diff --git a/java/core/src/test/java/com/google/protobuf/LiteTest.java b/java/core/src/test/java/com/google/protobuf/LiteTest.java index ba4d539d..40b44538 100644 --- a/java/core/src/test/java/com/google/protobuf/LiteTest.java +++ b/java/core/src/test/java/com/google/protobuf/LiteTest.java @@ -1453,6 +1453,15 @@ public class LiteTest extends TestCase { UnittestLite.optionalFixed32ExtensionLite)); } + public void testBuilderMergeFromNull() throws Exception { + try { + TestAllTypesLite.newBuilder().mergeFrom((TestAllTypesLite) null); + fail("Expected exception"); + } catch (NullPointerException e) { + // Pass. + } + } + // Builder.mergeFrom() should keep existing extensions. public void testBuilderMergeFromWithExtensions() throws Exception { TestAllExtensionsLite message = diff --git a/java/util/src/main/java/com/google/protobuf/util/FieldMaskTree.java b/java/util/src/main/java/com/google/protobuf/util/FieldMaskTree.java index b192b53e..e017b987 100644 --- a/java/util/src/main/java/com/google/protobuf/util/FieldMaskTree.java +++ b/java/util/src/main/java/com/google/protobuf/util/FieldMaskTree.java @@ -34,7 +34,6 @@ import com.google.protobuf.Descriptors.Descriptor; import com.google.protobuf.Descriptors.FieldDescriptor; import com.google.protobuf.FieldMask; import com.google.protobuf.Message; - import java.util.ArrayList; import java.util.List; import java.util.Map.Entry; @@ -244,6 +243,11 @@ final class FieldMaskTree { + "singluar message field and cannot have sub-fields."); continue; } + if (!source.hasField(field) && !destination.hasField(field)) { + // If the message field is not present in both source and destination, skip recursing + // so we don't create unneccessary empty messages. + continue; + } String childPath = path.isEmpty() ? entry.getKey() : path + "." + entry.getKey(); merge( entry.getValue(), diff --git a/java/util/src/test/java/com/google/protobuf/util/FieldMaskTreeTest.java b/java/util/src/test/java/com/google/protobuf/util/FieldMaskTreeTest.java index 3ee0fc6e..853b6151 100644 --- a/java/util/src/test/java/com/google/protobuf/util/FieldMaskTreeTest.java +++ b/java/util/src/test/java/com/google/protobuf/util/FieldMaskTreeTest.java @@ -33,7 +33,6 @@ package com.google.protobuf.util; import protobuf_unittest.UnittestProto.NestedTestAllTypes; import protobuf_unittest.UnittestProto.TestAllTypes; import protobuf_unittest.UnittestProto.TestAllTypes.NestedMessage; - import junit.framework.TestCase; public class FieldMaskTreeTest extends TestCase { @@ -222,6 +221,13 @@ public class FieldMaskTreeTest extends TestCase { new FieldMaskTree().addFieldPath("payload").merge(clearedSource, builder, options); assertEquals(false, builder.hasPayload()); + // Skip a message field if they are unset in both source and target. + builder = NestedTestAllTypes.newBuilder(); + new FieldMaskTree() + .addFieldPath("payload.optional_int32") + .merge(clearedSource, builder, options); + assertEquals(false, builder.hasPayload()); + // Change to replace message fields. options.setReplaceMessageFields(true); builder = NestedTestAllTypes.newBuilder(); diff --git a/js/binary/arith_test.js b/js/binary/arith_test.js index 89796bf7..dd5791a7 100644 --- a/js/binary/arith_test.js +++ b/js/binary/arith_test.js @@ -36,7 +36,6 @@ * @author cfallin@google.com (Chris Fallin) */ -goog.require('goog.testing.asserts'); goog.require('jspb.arith.Int64'); goog.require('jspb.arith.UInt64'); @@ -48,30 +47,30 @@ describe('binaryArithTest', function() { it('testCompare', function() { var a = new jspb.arith.UInt64(1234, 5678); var b = new jspb.arith.UInt64(1234, 5678); - assertEquals(a.cmp(b), 0); - assertEquals(b.cmp(a), 0); + expect(a.cmp(b)).toEqual(0); + expect(b.cmp(a)).toEqual(0); b.lo -= 1; - assertEquals(a.cmp(b), 1); - assertEquals(b.cmp(a), -1); + expect(a.cmp(b)).toEqual(1); + expect(b.cmp(a)).toEqual(-1); b.lo += 2; - assertEquals(a.cmp(b), -1); - assertEquals(b.cmp(a), 1); + expect(a.cmp(b)).toEqual(-1); + expect(b.cmp(a)).toEqual(1); b.lo = a.lo; b.hi = a.hi - 1; - assertEquals(a.cmp(b), 1); - assertEquals(b.cmp(a), -1); + expect(a.cmp(b)).toEqual(1); + expect(b.cmp(a)).toEqual(-1); - assertEquals(a.zero(), false); - assertEquals(a.msb(), false); - assertEquals(a.lsb(), false); + expect(a.zero()).toEqual(false); + expect(a.msb()).toEqual(false); + expect(a.lsb()).toEqual(false); a.hi = 0; a.lo = 0; - assertEquals(a.zero(), true); + expect(a.zero()).toEqual(true); a.hi = 0x80000000; - assertEquals(a.zero(), false); - assertEquals(a.msb(), true); + expect(a.zero()).toEqual(false); + expect(a.msb()).toEqual(true); a.lo = 0x00000001; - assertEquals(a.lsb(), true); + expect(a.lsb()).toEqual(true); }); @@ -80,35 +79,35 @@ describe('binaryArithTest', function() { */ it('testShifts', function() { var a = new jspb.arith.UInt64(1, 0); - assertEquals(a.lo, 1); - assertEquals(a.hi, 0); + expect(a.lo).toEqual(1); + expect(a.hi).toEqual(0); var orig = a; a = a.leftShift(); - assertEquals(orig.lo, 1); // original unmodified. - assertEquals(orig.hi, 0); - assertEquals(a.lo, 2); - assertEquals(a.hi, 0); + expect(orig.lo).toEqual(1); // original unmodified. + expect(orig.hi).toEqual(0); + expect(a.lo).toEqual(2); + expect(a.hi).toEqual(0); a = a.leftShift(); - assertEquals(a.lo, 4); - assertEquals(a.hi, 0); + expect(a.lo).toEqual(4); + expect(a.hi).toEqual(0); for (var i = 0; i < 29; i++) { a = a.leftShift(); } - assertEquals(a.lo, 0x80000000); - assertEquals(a.hi, 0); + expect(a.lo).toEqual(0x80000000); + expect(a.hi).toEqual(0); a = a.leftShift(); - assertEquals(a.lo, 0); - assertEquals(a.hi, 1); + expect(a.lo).toEqual(0); + expect(a.hi).toEqual(1); a = a.leftShift(); - assertEquals(a.lo, 0); - assertEquals(a.hi, 2); + expect(a.lo).toEqual(0); + expect(a.hi).toEqual(2); a = a.rightShift(); a = a.rightShift(); - assertEquals(a.lo, 0x80000000); - assertEquals(a.hi, 0); + expect(a.lo).toEqual(0x80000000); + expect(a.hi).toEqual(0); a = a.rightShift(); - assertEquals(a.lo, 0x40000000); - assertEquals(a.hi, 0); + expect(a.lo).toEqual(0x40000000); + expect(a.hi).toEqual(0); }); @@ -122,12 +121,12 @@ describe('binaryArithTest', function() { /* hi = */ 0x92fa2123); // Addition with carry. var c = a.add(b); - assertEquals(a.lo, 0x89abcdef); // originals unmodified. - assertEquals(a.hi, 0x01234567); - assertEquals(b.lo, 0xff52ab91); - assertEquals(b.hi, 0x92fa2123); - assertEquals(c.lo, 0x88fe7980); - assertEquals(c.hi, 0x941d668b); + expect(a.lo).toEqual(0x89abcdef); // originals unmodified. + expect(a.hi).toEqual(0x01234567); + expect(b.lo).toEqual(0xff52ab91); + expect(b.hi).toEqual(0x92fa2123); + expect(c.lo).toEqual(0x88fe7980); + expect(c.hi).toEqual(0x941d668b); // Simple addition without carry. a.lo = 2; @@ -135,8 +134,8 @@ describe('binaryArithTest', function() { b.lo = 3; b.hi = 0; c = a.add(b); - assertEquals(c.lo, 5); - assertEquals(c.hi, 0); + expect(c.lo).toEqual(5); + expect(c.hi).toEqual(0); }); @@ -170,8 +169,8 @@ describe('binaryArithTest', function() { var a = new jspb.arith.UInt64(loValues[i], hiValues[j]); var b = new jspb.arith.UInt64(loValues[j], hiValues[i]); var c = a.add(b).sub(b); - assertEquals(c.hi, a.hi); - assertEquals(c.lo, a.lo); + expect(c.hi).toEqual(a.hi); + expect(c.lo).toEqual(a.lo); } } }); @@ -201,8 +200,8 @@ describe('binaryArithTest', function() { var cLow = testData[i][2] >>> 0; var cHigh = testData[i][3] >>> 0; var c = jspb.arith.UInt64.mul32x32(a, b); - assertEquals(c.lo, cLow); - assertEquals(c.hi, cHigh); + expect(c.lo).toEqual(cLow); + expect(c.hi).toEqual(cHigh); } }); @@ -231,8 +230,8 @@ describe('binaryArithTest', function() { for (var i = 0; i < testData.length; i++) { var a = new jspb.arith.UInt64(testData[i][0], testData[i][1]); var prod = a.mul(testData[i][2]); - assertEquals(prod.lo, testData[i][3]); - assertEquals(prod.hi, testData[i][4]); + expect(prod.lo).toEqual(testData[i][3]); + expect(prod.hi).toEqual(testData[i][4]); } }); @@ -274,9 +273,9 @@ describe('binaryArithTest', function() { var result = a.div(testData[i][2]); var quotient = result[0]; var remainder = result[1]; - assertEquals(quotient.lo, testData[i][3]); - assertEquals(quotient.hi, testData[i][4]); - assertEquals(remainder.lo, testData[i][5]); + expect(quotient.lo).toEqual(testData[i][3]); + expect(quotient.hi).toEqual(testData[i][4]); + expect(remainder.lo).toEqual(testData[i][5]); } }); @@ -311,9 +310,9 @@ describe('binaryArithTest', function() { for (var i = 0; i < testData.length; i++) { var a = new jspb.arith.UInt64(testData[i][0], testData[i][1]); var roundtrip = jspb.arith.UInt64.fromString(a.toString()); - assertEquals(roundtrip.lo, a.lo); - assertEquals(roundtrip.hi, a.hi); - assertEquals(a.toString(), testData[i][2]); + expect(roundtrip.lo).toEqual(a.lo); + expect(roundtrip.hi).toEqual(a.hi); + expect(a.toString()).toEqual(testData[i][2]); } }); @@ -349,7 +348,7 @@ describe('binaryArithTest', function() { for (var i = 0; i < testStrings.length; i++) { var roundtrip = jspb.arith.Int64.fromString(testStrings[i]).toString(); - assertEquals(roundtrip, testStrings[i]); + expect(roundtrip).toEqual(testStrings[i]); } }); }); diff --git a/js/binary/constants.js b/js/binary/constants.js index ef5fecdd..75a8a52c 100644 --- a/js/binary/constants.js +++ b/js/binary/constants.js @@ -51,6 +51,9 @@ goog.provide('jspb.ScalarFieldType'); goog.provide('jspb.WriterFunction'); +goog.forwardDeclare('jspb.BinaryMessage'); +goog.forwardDeclare('jspb.BinaryReader'); +goog.forwardDeclare('jspb.BinaryWriter'); goog.forwardDeclare('jspb.Message'); goog.forwardDeclare('jsproto.BinaryExtension'); diff --git a/js/binary/decoder.js b/js/binary/decoder.js index 313d6f3f..4ec3cada 100644 --- a/js/binary/decoder.js +++ b/js/binary/decoder.js @@ -583,27 +583,24 @@ jspb.BinaryDecoder.prototype.readUnsignedVarint32 = function() { x |= (temp & 0x0F) << 28; if (temp < 128) { // We're reading the high bits of an unsigned varint. The byte we just read - // also contains bits 33 through 35, which we're going to discard. Those - // bits _must_ be zero, or the encoding is invalid. - goog.asserts.assert((temp & 0xF0) == 0); + // also contains bits 33 through 35, which we're going to discard. this.cursor_ += 5; goog.asserts.assert(this.cursor_ <= this.end_); return x >>> 0; } - // If we get here, we're reading the sign extension of a negative 32-bit int. - // We can skip these bytes, as we know in advance that they have to be all - // 1's if the varint is correctly encoded. Since we also know the value is - // negative, we don't have to coerce it to unsigned before we return it. - - goog.asserts.assert((temp & 0xF0) == 0xF0); - goog.asserts.assert(bytes[this.cursor_ + 5] == 0xFF); - goog.asserts.assert(bytes[this.cursor_ + 6] == 0xFF); - goog.asserts.assert(bytes[this.cursor_ + 7] == 0xFF); - goog.asserts.assert(bytes[this.cursor_ + 8] == 0xFF); - goog.asserts.assert(bytes[this.cursor_ + 9] == 0x01); + // If we get here, we need to truncate coming bytes. However we need to make + // sure cursor place is correct. + this.cursor_ += 5; + if (bytes[this.cursor_++] >= 128 && + bytes[this.cursor_++] >= 128 && + bytes[this.cursor_++] >= 128 && + bytes[this.cursor_++] >= 128 && + bytes[this.cursor_++] >= 128) { + // If we get here, the varint is too long. + goog.asserts.assert(false); + } - this.cursor_ += 10; goog.asserts.assert(this.cursor_ <= this.end_); return x; }; diff --git a/js/binary/decoder_test.js b/js/binary/decoder_test.js index d0139e29..b19e1d1b 100644 --- a/js/binary/decoder_test.js +++ b/js/binary/decoder_test.js @@ -270,24 +270,7 @@ describe('binaryDecoderTest', function() { assertThrows(function() {decoder.readSignedVarint64()}); decoder.reset(); assertThrows(function() {decoder.readZigzagVarint64()}); - - // Positive 32-bit varints encoded with 1 bits in positions 33 through 35 - // should trigger assertions. - decoder.setBlock([255, 255, 255, 255, 0x1F]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - decoder.setBlock([255, 255, 255, 255, 0x2F]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - decoder.setBlock([255, 255, 255, 255, 0x4F]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - // Negative 32-bit varints encoded with non-1 bits in the high dword should - // trigger assertions. - decoder.setBlock([255, 255, 255, 255, 255, 255, 0, 255, 255, 1]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - decoder.setBlock([255, 255, 255, 255, 255, 255, 255, 255, 255, 0]); + decoder.reset(); assertThrows(function() {decoder.readUnsignedVarint32()}); }); diff --git a/js/compatibility_tests/v3.0.0/binary/decoder_test.js b/js/compatibility_tests/v3.0.0/binary/decoder_test.js index ac312648..fce2fe18 100644 --- a/js/compatibility_tests/v3.0.0/binary/decoder_test.js +++ b/js/compatibility_tests/v3.0.0/binary/decoder_test.js @@ -228,24 +228,7 @@ describe('binaryDecoderTest', function() { assertThrows(function() {decoder.readSignedVarint64()}); decoder.reset(); assertThrows(function() {decoder.readZigzagVarint64()}); - - // Positive 32-bit varints encoded with 1 bits in positions 33 through 35 - // should trigger assertions. - decoder.setBlock([255, 255, 255, 255, 0x1F]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - decoder.setBlock([255, 255, 255, 255, 0x2F]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - decoder.setBlock([255, 255, 255, 255, 0x4F]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - // Negative 32-bit varints encoded with non-1 bits in the high dword should - // trigger assertions. - decoder.setBlock([255, 255, 255, 255, 255, 255, 0, 255, 255, 1]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - decoder.setBlock([255, 255, 255, 255, 255, 255, 255, 255, 255, 0]); + decoder.reset(); assertThrows(function() {decoder.readUnsignedVarint32()}); }); diff --git a/js/compatibility_tests/v3.1.0/binary/decoder_test.js b/js/compatibility_tests/v3.1.0/binary/decoder_test.js index ac312648..fce2fe18 100644 --- a/js/compatibility_tests/v3.1.0/binary/decoder_test.js +++ b/js/compatibility_tests/v3.1.0/binary/decoder_test.js @@ -228,24 +228,7 @@ describe('binaryDecoderTest', function() { assertThrows(function() {decoder.readSignedVarint64()}); decoder.reset(); assertThrows(function() {decoder.readZigzagVarint64()}); - - // Positive 32-bit varints encoded with 1 bits in positions 33 through 35 - // should trigger assertions. - decoder.setBlock([255, 255, 255, 255, 0x1F]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - decoder.setBlock([255, 255, 255, 255, 0x2F]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - decoder.setBlock([255, 255, 255, 255, 0x4F]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - // Negative 32-bit varints encoded with non-1 bits in the high dword should - // trigger assertions. - decoder.setBlock([255, 255, 255, 255, 255, 255, 0, 255, 255, 1]); - assertThrows(function() {decoder.readUnsignedVarint32()}); - - decoder.setBlock([255, 255, 255, 255, 255, 255, 255, 255, 255, 0]); + decoder.reset(); assertThrows(function() {decoder.readUnsignedVarint32()}); }); diff --git a/objectivec/google/protobuf/FieldMask.pbobjc.h b/objectivec/google/protobuf/FieldMask.pbobjc.h index 07e60818..75cf856c 100644 --- a/objectivec/google/protobuf/FieldMask.pbobjc.h +++ b/objectivec/google/protobuf/FieldMask.pbobjc.h @@ -252,6 +252,12 @@ typedef GPB_ENUM(GPBFieldMask_FieldNumber) { * * Note that oneof type names ("test_oneof" in this case) cannot be used in * paths. + * + * ## Field Mask Verification + * + * The implementation of the all the API methods, which have any FieldMask type + * field in the request, should verify the included field paths, and return + * `INVALID_ARGUMENT` error if any path is duplicated or unmappable. **/ @interface GPBFieldMask : GPBMessage diff --git a/php/src/Google/Protobuf/Internal/FileOptions.php b/php/src/Google/Protobuf/Internal/FileOptions.php index ee64e4e0..f3bacad6 100644 --- a/php/src/Google/Protobuf/Internal/FileOptions.php +++ b/php/src/Google/Protobuf/Internal/FileOptions.php @@ -174,7 +174,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message private $php_namespace = ''; private $has_php_namespace = false; /** - * The parser stores options it doesn't recognize here. See above. + * The parser stores options it doesn't recognize here. + * See the documentation for the "Options" section above. * * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> */ @@ -827,7 +828,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * The parser stores options it doesn't recognize here. See above. + * The parser stores options it doesn't recognize here. + * See the documentation for the "Options" section above. * * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> * @return \Google\Protobuf\Internal\RepeatedField @@ -838,7 +840,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * The parser stores options it doesn't recognize here. See above. + * The parser stores options it doesn't recognize here. + * See the documentation for the "Options" section above. * * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> * @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var diff --git a/python/google/protobuf/internal/any_test.proto b/python/google/protobuf/internal/any_test.proto index 76a7ebd6..1a563fd9 100644 --- a/python/google/protobuf/internal/any_test.proto +++ b/python/google/protobuf/internal/any_test.proto @@ -39,6 +39,7 @@ import "google/protobuf/any.proto"; message TestAny { optional google.protobuf.Any value = 1; optional int32 int_value = 2; + map<string,int32> map_value = 3; extensions 10 to max; } diff --git a/python/google/protobuf/internal/api_implementation.py b/python/google/protobuf/internal/api_implementation.py index bce71bb8..553fcdb6 100755 --- a/python/google/protobuf/internal/api_implementation.py +++ b/python/google/protobuf/internal/api_implementation.py @@ -159,7 +159,7 @@ if _implementation_type == 'cpp': # Unrecognized cpp implementation. Skipping the unknown fields APIs. pass else: - _python_proto3_preserve_unknowns_default = False + _python_proto3_preserve_unknowns_default = True def GetPythonProto3PreserveUnknownsDefault(): return _python_proto3_preserve_unknowns_default diff --git a/python/google/protobuf/internal/json_format_test.py b/python/google/protobuf/internal/json_format_test.py index b2cf7622..19182b7f 100644 --- a/python/google/protobuf/internal/json_format_test.py +++ b/python/google/protobuf/internal/json_format_test.py @@ -50,6 +50,7 @@ from google.protobuf import struct_pb2 from google.protobuf import timestamp_pb2 from google.protobuf import wrappers_pb2 from google.protobuf import unittest_mset_pb2 +from google.protobuf import unittest_pb2 from google.protobuf.internal import well_known_types from google.protobuf import json_format from google.protobuf.util import json_format_proto3_pb2 @@ -159,15 +160,15 @@ class JsonFormatTest(JsonFormatBase): json_format.Parse(text, parsed_message) self.assertEqual(message, parsed_message) - def testUnknownEnumToJsonError(self): + def testUnknownEnumToJsonAndBack(self): + text = '{\n "enumValue": 999\n}' message = json_format_proto3_pb2.TestMessage() message.enum_value = 999 - # TODO(jieluo): should accept numeric unknown enum for proto3. - with self.assertRaises(json_format.SerializeToJsonError) as e: - json_format.MessageToJson(message) - self.assertEqual(str(e.exception), - 'Enum field contains an integer value which can ' - 'not mapped to an enum value.') + self.assertEqual(json_format.MessageToJson(message), + text) + parsed_message = json_format_proto3_pb2.TestMessage() + json_format.Parse(text, parsed_message) + self.assertEqual(message, parsed_message) def testExtensionToJsonAndBack(self): message = unittest_mset_pb2.TestMessageSetContainer() @@ -757,11 +758,16 @@ class JsonFormatTest(JsonFormatBase): '{"enumValue": "baz"}', 'Failed to parse enumValue field: Invalid enum value baz ' 'for enum type proto3.EnumType.') - # TODO(jieluo): fix json format to accept numeric unknown enum for proto3. - self.CheckError( - '{"enumValue": 12345}', - 'Failed to parse enumValue field: Invalid enum value 12345 ' - 'for enum type proto3.EnumType.') + # Proto3 accepts numeric unknown enums. + text = '{"enumValue": 12345}' + json_format.Parse(text, message) + # Proto2 does not accept unknown enums. + message = unittest_pb2.TestAllTypes() + self.assertRaisesRegexp( + json_format.ParseError, + 'Failed to parse optionalNestedEnum field: Invalid enum value 12345 ' + 'for enum type protobuf_unittest.TestAllTypes.NestedEnum.', + json_format.Parse, '{"optionalNestedEnum": 12345}', message) def testParseBadIdentifer(self): self.CheckError('{int32Value: 1}', diff --git a/python/google/protobuf/internal/message_factory_test.py b/python/google/protobuf/internal/message_factory_test.py index a1b6bb81..6df52ed2 100644 --- a/python/google/protobuf/internal/message_factory_test.py +++ b/python/google/protobuf/internal/message_factory_test.py @@ -107,8 +107,17 @@ class MessageFactoryTest(unittest.TestCase): def testGetMessages(self): # performed twice because multiple calls with the same input must be allowed for _ in range(2): - messages = message_factory.GetMessages([self.factory_test1_fd, - self.factory_test2_fd]) + # GetMessage should work regardless of the order the FileDescriptorProto + # are provided. In particular, the function should succeed when the files + # are not in the topological order of dependencies. + + # Assuming factory_test2_fd depends on factory_test1_fd. + self.assertIn(self.factory_test1_fd.name, + self.factory_test2_fd.dependency) + # Get messages should work when a file comes before its dependencies: + # factory_test2_fd comes before factory_test1_fd. + messages = message_factory.GetMessages([self.factory_test2_fd, + self.factory_test1_fd]) self.assertTrue( set(['google.protobuf.python.internal.Factory2Message', 'google.protobuf.python.internal.Factory1Message'], diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index 4622f10f..a303b1aa 100755 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py @@ -51,6 +51,7 @@ import operator import pickle import six import sys +import warnings try: import unittest2 as unittest # PY26 @@ -146,13 +147,22 @@ class MessageTest(BaseTestCase): msg = message_module.TestAllTypes() self.assertRaises(TypeError, msg.FromString, 0) self.assertRaises(Exception, msg.FromString, '0') - # TODO(jieluo): Fix cpp extension to check unexpected end-group tag. + # TODO(jieluo): Fix cpp extension to raise error instead of warning. # b/27494216 + end_tag = encoder.TagBytes(1, 4) if api_implementation.Type() == 'python': - end_tag = encoder.TagBytes(1, 4) with self.assertRaises(message.DecodeError) as context: msg.FromString(end_tag) self.assertEqual('Unexpected end-group tag.', str(context.exception)) + else: + with warnings.catch_warnings(record=True) as w: + # Cause all warnings to always be triggered. + warnings.simplefilter('always') + msg.FromString(end_tag) + assert len(w) == 1 + assert issubclass(w[-1].category, RuntimeWarning) + self.assertEqual('Unexpected end-group tag: Not all data was converted', + str(w[-1].message)) def testDeterminismParameters(self, message_module): # This message is always deterministically serialized, even if determinism diff --git a/python/google/protobuf/internal/text_format_test.py b/python/google/protobuf/internal/text_format_test.py index 1214c3ea..a52f133f 100755 --- a/python/google/protobuf/internal/text_format_test.py +++ b/python/google/protobuf/internal/text_format_test.py @@ -1,4 +1,5 @@ #! /usr/bin/env python +# -*- coding: utf-8 -*- # # Protocol Buffers - Google's data interchange format # Copyright 2008 Google Inc. All rights reserved. @@ -298,6 +299,33 @@ class TextFormatTest(TextFormatBase): if message_module is unittest_pb2: test_util.ExpectAllFieldsSet(self, message) + def testParseAndMergeUtf8(self, message_module): + message = message_module.TestAllTypes() + test_util.SetAllFields(message) + ascii_text = text_format.MessageToString(message) + ascii_text = ascii_text.encode('utf-8') + + parsed_message = message_module.TestAllTypes() + text_format.Parse(ascii_text, parsed_message) + self.assertEqual(message, parsed_message) + if message_module is unittest_pb2: + test_util.ExpectAllFieldsSet(self, message) + + parsed_message.Clear() + text_format.Merge(ascii_text, parsed_message) + self.assertEqual(message, parsed_message) + if message_module is unittest_pb2: + test_util.ExpectAllFieldsSet(self, message) + + if six.PY2: + msg2 = message_module.TestAllTypes() + text = (u'optional_string: "café"') + text_format.Merge(text, msg2) + self.assertEqual(msg2.optional_string, u'café') + msg2.Clear() + text_format.Parse(text, msg2) + self.assertEqual(msg2.optional_string, u'café') + def testParseExotic(self, message_module): message = message_module.TestAllTypes() text = ('repeated_int64: -9223372036854775808\n' @@ -399,13 +427,6 @@ class TextFormatTest(TextFormatBase): r'has no value named BARR.'), text_format.Parse, text, message) - message = message_module.TestAllTypes() - text = 'optional_nested_enum: 100' - six.assertRaisesRegex(self, text_format.ParseError, - (r'1:23 : Enum type "\w+.TestAllTypes.NestedEnum" ' - r'has no value with number 100.'), text_format.Parse, - text, message) - def testParseBadIntValue(self, message_module): message = message_module.TestAllTypes() text = 'optional_int32: bork' @@ -920,6 +941,14 @@ class Proto2Tests(TextFormatBase): '1:2 : Message type "protobuf_unittest.TestAllTypes" does not have ' 'extensions.'), text_format.Parse, text, message) + def testParseNumericUnknownEnum(self): + message = unittest_pb2.TestAllTypes() + text = 'optional_nested_enum: 100' + six.assertRaisesRegex(self, text_format.ParseError, + (r'1:23 : Enum type "\w+.TestAllTypes.NestedEnum" ' + r'has no value with number 100.'), text_format.Parse, + text, message) + def testMergeDuplicateExtensionScalars(self): message = unittest_pb2.TestAllExtensions() text = ('[protobuf_unittest.optional_int32_extension]: 42 ' @@ -1113,13 +1142,8 @@ class Proto3Tests(unittest.TestCase): message2 = unittest_proto3_arena_pb2.TestAllTypes() message.optional_nested_enum = 999 text_string = text_format.MessageToString(message) - # TODO(jieluo): proto3 should support numeric unknown enum. - with self.assertRaises(text_format.ParseError) as e: - text_format.Parse(text_string, message2) - self.assertEqual(999, message2.optional_nested_enum) - self.assertEqual(str(e.exception), - '1:23 : Enum type "proto3_arena_unittest.TestAllTypes.' - 'NestedEnum" has no value with number 999.') + text_format.Parse(text_string, message2) + self.assertEqual(999, message2.optional_nested_enum) def testMergeExpandedAny(self): message = any_test_pb2.TestAny() diff --git a/python/google/protobuf/internal/unknown_fields_test.py b/python/google/protobuf/internal/unknown_fields_test.py index 9bdb6f27..8b7de2e7 100755 --- a/python/google/protobuf/internal/unknown_fields_test.py +++ b/python/google/protobuf/internal/unknown_fields_test.py @@ -92,7 +92,6 @@ class UnknownFieldsTest(BaseTestCase): # Verify that proto3 unknown fields behavior. default_preserve = (api_implementation .GetPythonProto3PreserveUnknownsDefault()) - self.assertEqual(False, default_preserve) self.expectSerializeProto3(default_preserve) api_implementation.SetPythonProto3PreserveUnknownsDefault( not default_preserve) diff --git a/python/google/protobuf/internal/well_known_types.py b/python/google/protobuf/internal/well_known_types.py index 57b96998..3573770b 100644 --- a/python/google/protobuf/internal/well_known_types.py +++ b/python/google/protobuf/internal/well_known_types.py @@ -40,6 +40,7 @@ This files defines well known classes which need extra maintenance including: __author__ = 'jieluo@google.com (Jie Luo)' +import collections from datetime import datetime from datetime import timedelta import six @@ -67,13 +68,14 @@ class ParseError(Error): class Any(object): """Class for Any Message type.""" - def Pack(self, msg, type_url_prefix='type.googleapis.com/'): + def Pack(self, msg, type_url_prefix='type.googleapis.com/', + deterministic=None): """Packs the specified message into current Any message.""" if len(type_url_prefix) < 1 or type_url_prefix[-1] != '/': self.type_url = '%s/%s' % (type_url_prefix, msg.DESCRIPTOR.full_name) else: self.type_url = '%s%s' % (type_url_prefix, msg.DESCRIPTOR.full_name) - self.value = msg.SerializeToString() + self.value = msg.SerializeToString(deterministic=deterministic) def Unpack(self, msg): """Unpacks the current Any message into specified message.""" @@ -734,9 +736,30 @@ class Struct(object): def __getitem__(self, key): return _GetStructValue(self.fields[key]) + def __contains__(self, item): + return item in self.fields + def __setitem__(self, key, value): _SetStructValue(self.fields[key], value) + def __delitem__(self, key): + del self.fields[key] + + def __len__(self): + return len(self.fields) + + def __iter__(self): + return iter(self.fields) + + def keys(self): # pylint: disable=invalid-name + return self.fields.keys() + + def values(self): # pylint: disable=invalid-name + return [self[key] for key in self] + + def items(self): # pylint: disable=invalid-name + return [(key, self[key]) for key in self] + def get_or_create_list(self, key): """Returns a list for this key, creating if it didn't exist already.""" if not self.fields[key].HasField('list_value'): @@ -755,6 +778,8 @@ class Struct(object): for key, value in dictionary.items(): _SetStructValue(self.fields[key], value) +collections.MutableMapping.register(Struct) + class ListValue(object): """Class for ListValue message type.""" @@ -776,6 +801,9 @@ class ListValue(object): def __setitem__(self, index, value): _SetStructValue(self.values.__getitem__(index), value) + def __delitem__(self, key): + del self.values[key] + def items(self): for i in range(len(self)): yield self[i] @@ -794,6 +822,8 @@ class ListValue(object): list_value.Clear() return list_value +collections.MutableSequence.register(ListValue) + WKTBASES = { 'google.protobuf.Any': Any, diff --git a/python/google/protobuf/internal/well_known_types_test.py b/python/google/protobuf/internal/well_known_types_test.py index 70975da1..291fe4e8 100644 --- a/python/google/protobuf/internal/well_known_types_test.py +++ b/python/google/protobuf/internal/well_known_types_test.py @@ -34,6 +34,7 @@ __author__ = 'jieluo@google.com (Jie Luo)' +import collections from datetime import datetime try: @@ -667,6 +668,8 @@ class StructTest(unittest.TestCase): def testStruct(self): struct = struct_pb2.Struct() + self.assertIsInstance(struct, collections.Mapping) + self.assertEqual(0, len(struct)) struct_class = struct.__class__ struct['key1'] = 5 @@ -674,11 +677,13 @@ class StructTest(unittest.TestCase): struct['key3'] = True struct.get_or_create_struct('key4')['subkey'] = 11.0 struct_list = struct.get_or_create_list('key5') + self.assertIsInstance(struct_list, collections.Sequence) struct_list.extend([6, 'seven', True, False, None]) struct_list.add_struct()['subkey2'] = 9 struct['key6'] = {'subkey': {}} struct['key7'] = [2, False] + self.assertEqual(7, len(struct)) self.assertTrue(isinstance(struct, well_known_types.Struct)) self.assertEqual(5, struct['key1']) self.assertEqual('abc', struct['key2']) @@ -696,6 +701,20 @@ class StructTest(unittest.TestCase): struct2.ParseFromString(serialized) self.assertEqual(struct, struct2) + for key, value in struct.items(): + self.assertIn(key, struct) + self.assertIn(key, struct2) + self.assertEqual(value, struct2[key]) + + self.assertEqual(7, len(struct.keys())) + self.assertEqual(7, len(struct.values())) + for key in struct.keys(): + self.assertIn(key, struct) + self.assertIn(key, struct2) + self.assertEqual(struct[key], struct2[key]) + + item = (next(iter(struct.keys())), next(iter(struct.values()))) + self.assertEqual(item, next(iter(struct.items()))) self.assertTrue(isinstance(struct2, well_known_types.Struct)) self.assertEqual(5, struct2['key1']) @@ -756,6 +775,16 @@ class StructTest(unittest.TestCase): empty_struct = list2[1] self.assertEqual({}, dict(empty_struct.fields)) + self.assertEqual(9, len(struct)) + del struct['key3'] + del struct['key4'] + self.assertEqual(7, len(struct)) + self.assertEqual(6, len(struct['key5'])) + del struct['key5'][1] + self.assertEqual(5, len(struct['key5'])) + self.assertEqual([6, True, False, None, inner_struct], + list(struct['key5'].items())) + def testMergeFrom(self): struct = struct_pb2.Struct() struct_class = struct.__class__ @@ -863,6 +892,20 @@ class AnyTest(unittest.TestCase): self.assertTrue(msg.Unpack(unpacked_message)) self.assertEqual(submessage, unpacked_message) + def testPackDeterministic(self): + submessage = any_test_pb2.TestAny() + for i in range(10): + submessage.map_value[str(i)] = i * 2 + msg = any_pb2.Any() + msg.Pack(submessage, deterministic=True) + serialized = msg.SerializeToString(deterministic=True) + golden = (b'\n4type.googleapis.com/google.protobuf.internal.TestAny\x12F' + b'\x1a\x05\n\x010\x10\x00\x1a\x05\n\x011\x10\x02\x1a\x05\n\x01' + b'2\x10\x04\x1a\x05\n\x013\x10\x06\x1a\x05\n\x014\x10\x08\x1a' + b'\x05\n\x015\x10\n\x1a\x05\n\x016\x10\x0c\x1a\x05\n\x017\x10' + b'\x0e\x1a\x05\n\x018\x10\x10\x1a\x05\n\x019\x10\x12') + self.assertEqual(golden, serialized) + if __name__ == '__main__': unittest.main() diff --git a/python/google/protobuf/json_format.py b/python/google/protobuf/json_format.py index 801eed60..878291db 100644 --- a/python/google/protobuf/json_format.py +++ b/python/google/protobuf/json_format.py @@ -251,6 +251,8 @@ class _Printer(object): if enum_value is not None: return enum_value.name else: + if field.file.syntax == 'proto3': + return value raise SerializeToJsonError('Enum field contains an integer value ' 'which can not mapped to an enum value.') elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_STRING: @@ -675,6 +677,9 @@ def _ConvertScalarFieldValue(value, field, require_str=False): raise ParseError('Invalid enum value {0} for enum type {1}.'.format( value, field.enum_type.full_name)) if enum_value is None: + if field.file.syntax == 'proto3': + # Proto3 accepts unknown enums. + return number raise ParseError('Invalid enum value {0} for enum type {1}.'.format( value, field.enum_type.full_name)) return enum_value.number diff --git a/python/google/protobuf/message_factory.py b/python/google/protobuf/message_factory.py index 15740280..e4fb065e 100644 --- a/python/google/protobuf/message_factory.py +++ b/python/google/protobuf/message_factory.py @@ -130,13 +130,22 @@ def GetMessages(file_protos): """Builds a dictionary of all the messages available in a set of files. Args: - file_protos: A sequence of file protos to build messages out of. + file_protos: Iterable of FileDescriptorProto to build messages out of. 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. """ - for file_proto in file_protos: + # The cpp implementation of the protocol buffer library requires to add the + # message in topological order of the dependency graph. + file_by_name = {file_proto.name: file_proto for file_proto in file_protos} + def _AddFile(file_proto): + for dependency in file_proto.dependency: + if dependency in file_by_name: + # Remove from elements to be visited, in order to cut cycles. + _AddFile(file_by_name.pop(dependency)) _FACTORY.pool.Add(file_proto) + while file_by_name: + _AddFile(file_by_name.popitem()[1]) return _FACTORY.GetMessages([file_proto.name for file_proto in file_protos]) diff --git a/python/google/protobuf/pyext/extension_dict.cc b/python/google/protobuf/pyext/extension_dict.cc index 43ee5d15..6830b10d 100644 --- a/python/google/protobuf/pyext/extension_dict.cc +++ b/python/google/protobuf/pyext/extension_dict.cc @@ -32,6 +32,10 @@ // Author: tibell@google.com (Johan Tibell) #include <google/protobuf/pyext/extension_dict.h> +#include <memory> +#ifndef _SHARED_PTR_H +#include <google/protobuf/stubs/shared_ptr.h> +#endif #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> @@ -45,7 +49,6 @@ #include <google/protobuf/pyext/repeated_composite_container.h> #include <google/protobuf/pyext/repeated_scalar_container.h> #include <google/protobuf/pyext/scoped_pyobject_ptr.h> -#include <google/protobuf/stubs/shared_ptr.h> #if PY_MAJOR_VERSION >= 3 #if PY_VERSION_HEX < 0x03030000 diff --git a/python/google/protobuf/pyext/message.cc b/python/google/protobuf/pyext/message.cc index 0f54506b..ef75acab 100644 --- a/python/google/protobuf/pyext/message.cc +++ b/python/google/protobuf/pyext/message.cc @@ -2065,6 +2065,11 @@ static PyObject* MergeFromString(CMessage* self, PyObject* arg) { input.SetExtensionRegistry(factory->pool->pool, factory->message_factory); bool success = self->message->MergePartialFromCodedStream(&input); if (success) { + if (!input.ConsumedEntireMessage()) { + // TODO(jieluo): Raise error and return NULL instead. + // b/27494216 + PyErr_Warn(NULL, "Unexpected end-group tag: Not all data was converted"); + } return PyInt_FromLong(input.CurrentPosition()); } else { PyErr_Format(DecodeError_class, "Error parsing message"); diff --git a/python/google/protobuf/text_format.py b/python/google/protobuf/text_format.py index aaca78ad..6b12632e 100755 --- a/python/google/protobuf/text_format.py +++ b/python/google/protobuf/text_format.py @@ -485,7 +485,10 @@ def Parse(text, ParseError: On text parsing problems. """ if not isinstance(text, str): - text = text.decode('utf-8') + if six.PY3: + text = text.decode('utf-8') + else: + text = text.encode('utf-8') return ParseLines(text.split('\n'), message, allow_unknown_extension, @@ -517,6 +520,11 @@ def Merge(text, Raises: ParseError: On text parsing problems. """ + if not isinstance(text, str): + if six.PY3: + text = text.decode('utf-8') + else: + text = text.encode('utf-8') return MergeLines( text.split('\n'), message, @@ -1559,6 +1567,11 @@ def ParseEnum(field, value): (enum_descriptor.full_name, value)) else: # Numeric value. + if hasattr(field.file, 'syntax'): + # Attribute is checked for compatibility. + if field.file.syntax == 'proto3': + # Proto3 accept numeric unknown enums. + return number enum_value = enum_descriptor.values_by_number.get(number, None) if enum_value is None: raise ValueError('Enum type "%s" has no value with number %d.' % diff --git a/src/Makefile.am b/src/Makefile.am index b035fbd2..73abb7f2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -813,6 +813,8 @@ protobuf_test_SOURCES = \ google/protobuf/io/printer_unittest.cc \ google/protobuf/io/tokenizer_unittest.cc \ google/protobuf/io/zero_copy_stream_unittest.cc \ + google/protobuf/compiler/annotation_test_util.h \ + google/protobuf/compiler/annotation_test_util.cc \ google/protobuf/compiler/command_line_interface_unittest.cc \ google/protobuf/compiler/importer_unittest.cc \ google/protobuf/compiler/mock_code_generator.cc \ diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc index 9beb316a..29687477 100644 --- a/src/google/protobuf/any.pb.cc +++ b/src/google/protobuf/any.pb.cc @@ -14,6 +14,10 @@ #include <google/protobuf/generated_message_reflection.h> #include <google/protobuf/reflection_ops.h> #include <google/protobuf/wire_format.h> +// This is a temporary google only hack +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS +#include "third_party/protobuf/version.h" +#endif // @@protoc_insertion_point(includes) namespace google { namespace protobuf { @@ -28,7 +32,11 @@ namespace protobuf_google_2fprotobuf_2fany_2eproto { void InitDefaultsAnyImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_Any_default_instance_; new (ptr) ::google::protobuf::Any(); diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc index 9134426b..439a47c6 100644 --- a/src/google/protobuf/api.pb.cc +++ b/src/google/protobuf/api.pb.cc @@ -14,6 +14,10 @@ #include <google/protobuf/generated_message_reflection.h> #include <google/protobuf/reflection_ops.h> #include <google/protobuf/wire_format.h> +// This is a temporary google only hack +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS +#include "third_party/protobuf/version.h" +#endif // @@protoc_insertion_point(includes) namespace google { namespace protobuf { @@ -38,7 +42,11 @@ namespace protobuf_google_2fprotobuf_2fapi_2eproto { void InitDefaultsApiImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fapi_2eproto::InitDefaultsMethod(); protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaultsOption(); protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::InitDefaultsSourceContext(); @@ -59,7 +67,11 @@ void InitDefaultsApi() { void InitDefaultsMethodImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaultsOption(); { void* ptr = &::google::protobuf::_Method_default_instance_; @@ -77,7 +89,11 @@ void InitDefaultsMethod() { void InitDefaultsMixinImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_Mixin_default_instance_; new (ptr) ::google::protobuf::Mixin(); @@ -208,6 +224,15 @@ void Api::InitAsDefaultInstance() { ::google::protobuf::_Api_default_instance_._instance.get_mutable()->source_context_ = const_cast< ::google::protobuf::SourceContext*>( ::google::protobuf::SourceContext::internal_default_instance()); } +void Api::clear_options() { + options_.Clear(); +} +void Api::clear_source_context() { + if (GetArenaNoVirtual() == NULL && source_context_ != NULL) { + delete source_context_; + } + source_context_ = NULL; +} #if !defined(_MSC_VER) || _MSC_VER >= 1900 const int Api::kNameFieldNumber; const int Api::kMethodsFieldNumber; @@ -343,8 +368,7 @@ bool Api::MergePartialFromCodedStream( case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_methods())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_methods())); } else { goto handle_unusual; } @@ -355,8 +379,7 @@ bool Api::MergePartialFromCodedStream( case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_options())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_options())); } else { goto handle_unusual; } @@ -383,7 +406,7 @@ bool Api::MergePartialFromCodedStream( case 5: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(42u /* 42 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage( input, mutable_source_context())); } else { goto handle_unusual; @@ -395,8 +418,7 @@ bool Api::MergePartialFromCodedStream( case 6: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(50u /* 50 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_mixins())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_mixins())); } else { goto handle_unusual; } @@ -526,7 +548,7 @@ void Api::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->methods_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 2, this->methods(static_cast<int>(i)), deterministic, target); } @@ -534,7 +556,7 @@ void Api::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->options_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 3, this->options(static_cast<int>(i)), deterministic, target); } @@ -552,7 +574,7 @@ void Api::SerializeWithCachedSizes( // .google.protobuf.SourceContext source_context = 5; if (this->has_source_context()) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 5, *this->source_context_, deterministic, target); } @@ -560,7 +582,7 @@ void Api::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->mixins_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 6, this->mixins(static_cast<int>(i)), deterministic, target); } @@ -593,7 +615,7 @@ size_t Api::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->methods(static_cast<int>(i))); } } @@ -604,7 +626,7 @@ size_t Api::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->options(static_cast<int>(i))); } } @@ -615,7 +637,7 @@ size_t Api::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->mixins(static_cast<int>(i))); } } @@ -637,7 +659,7 @@ size_t Api::ByteSizeLong() const { // .google.protobuf.SourceContext source_context = 5; if (this->has_source_context()) { total_size += 1 + - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( *this->source_context_); } @@ -740,6 +762,9 @@ void Api::InternalSwap(Api* other) { void Method::InitAsDefaultInstance() { } +void Method::clear_options() { + options_.Clear(); +} #if !defined(_MSC_VER) || _MSC_VER >= 1900 const int Method::kNameFieldNumber; const int Method::kRequestTypeUrlFieldNumber; @@ -932,8 +957,7 @@ bool Method::MergePartialFromCodedStream( case 6: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(50u /* 50 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_options())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_options())); } else { goto handle_unusual; } @@ -1095,7 +1119,7 @@ void Method::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->options_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 6, this->options(static_cast<int>(i)), deterministic, target); } @@ -1128,7 +1152,7 @@ size_t Method::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->options(static_cast<int>(i))); } } diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index c41d74bd..e74528e1 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -225,8 +225,8 @@ class LIBPROTOBUF_EXPORT Api : public ::google::protobuf::Message /* @@protoc_in void clear_source_context(); static const int kSourceContextFieldNumber = 5; const ::google::protobuf::SourceContext& source_context() const; - ::google::protobuf::SourceContext* mutable_source_context(); ::google::protobuf::SourceContext* release_source_context(); + ::google::protobuf::SourceContext* mutable_source_context(); void set_allocated_source_context(::google::protobuf::SourceContext* source_context); // .google.protobuf.Syntax syntax = 7; @@ -641,9 +641,6 @@ Api::methods() const { inline int Api::options_size() const { return options_.size(); } -inline void Api::clear_options() { - options_.Clear(); -} inline const ::google::protobuf::Option& Api::options(int index) const { // @@protoc_insertion_point(field_get:google.protobuf.Api.options) return options_.Get(index); @@ -724,16 +721,19 @@ inline void Api::set_allocated_version(::std::string* version) { inline bool Api::has_source_context() const { return this != internal_default_instance() && source_context_ != NULL; } -inline void Api::clear_source_context() { - if (GetArenaNoVirtual() == NULL && source_context_ != NULL) delete source_context_; - source_context_ = NULL; -} inline const ::google::protobuf::SourceContext& Api::source_context() const { const ::google::protobuf::SourceContext* p = source_context_; // @@protoc_insertion_point(field_get:google.protobuf.Api.source_context) return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::SourceContext*>( &::google::protobuf::_SourceContext_default_instance_); } +inline ::google::protobuf::SourceContext* Api::release_source_context() { + // @@protoc_insertion_point(field_release:google.protobuf.Api.source_context) + + ::google::protobuf::SourceContext* temp = source_context_; + source_context_ = NULL; + return temp; +} inline ::google::protobuf::SourceContext* Api::mutable_source_context() { if (source_context_ == NULL) { @@ -742,21 +742,22 @@ inline ::google::protobuf::SourceContext* Api::mutable_source_context() { // @@protoc_insertion_point(field_mutable:google.protobuf.Api.source_context) return source_context_; } -inline ::google::protobuf::SourceContext* Api::release_source_context() { - // @@protoc_insertion_point(field_release:google.protobuf.Api.source_context) - - ::google::protobuf::SourceContext* temp = source_context_; - source_context_ = NULL; - return temp; -} inline void Api::set_allocated_source_context(::google::protobuf::SourceContext* source_context) { - delete source_context_; - source_context_ = source_context; + ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); + if (message_arena == NULL) { + delete reinterpret_cast< ::google::protobuf::MessageLite*>(source_context_); + } if (source_context) { + ::google::protobuf::Arena* submessage_arena = NULL; + if (message_arena != submessage_arena) { + source_context = ::google::protobuf::internal::GetOwnedMessage( + message_arena, source_context, submessage_arena); + } } else { } + source_context_ = source_context; // @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.source_context) } @@ -999,9 +1000,6 @@ inline void Method::set_response_streaming(bool value) { inline int Method::options_size() const { return options_.size(); } -inline void Method::clear_options() { - options_.Clear(); -} inline const ::google::protobuf::Option& Method::options(int index) const { // @@protoc_insertion_point(field_get:google.protobuf.Method.options) return options_.Get(index); diff --git a/src/google/protobuf/arena.cc b/src/google/protobuf/arena.cc index f0cc068d..e9289988 100755 --- a/src/google/protobuf/arena.cc +++ b/src/google/protobuf/arena.cc @@ -66,90 +66,78 @@ GOOGLE_THREAD_LOCAL ArenaImpl::ThreadCache ArenaImpl::thread_cache_ = {-1, NULL} void ArenaImpl::Init() { lifecycle_id_ = lifecycle_id_generator_.GetNext(); - blocks_ = 0; - hint_ = 0; - space_allocated_ = 0; - owns_first_block_ = true; - - if (options_.initial_block != NULL && options_.initial_block_size > 0) { - GOOGLE_CHECK_GE(options_.initial_block_size, sizeof(Block)) - << ": Initial block size too small for header."; - - // Add first unowned block to list. - Block* first_block = reinterpret_cast<Block*>(options_.initial_block); - first_block->size = options_.initial_block_size; - first_block->pos = kHeaderSize; - first_block->next = NULL; - first_block->cleanup = NULL; + google::protobuf::internal::NoBarrier_Store(&hint_, 0); + google::protobuf::internal::NoBarrier_Store(&threads_, 0); + + if (initial_block_) { // Thread which calls Init() owns the first block. This allows the - // single-threaded case to allocate on the first block without taking any - // locks. - first_block->owner = &thread_cache(); - AddBlockInternal(first_block); - CacheBlock(first_block); - owns_first_block_ = false; + // single-threaded case to allocate on the first block without having to + // perform atomic operations. + InitBlock(initial_block_, &thread_cache(), options_.initial_block_size); + ThreadInfo* info = NewThreadInfo(initial_block_); + info->next = NULL; + google::protobuf::internal::NoBarrier_Store(&threads_, + reinterpret_cast<google::protobuf::internal::AtomicWord>(info)); + google::protobuf::internal::NoBarrier_Store(&space_allocated_, + options_.initial_block_size); + CacheBlock(initial_block_); + } else { + google::protobuf::internal::NoBarrier_Store(&space_allocated_, 0); } } -ArenaImpl::~ArenaImpl() { ResetInternal(); } - -uint64 ArenaImpl::Reset() { - // Invalidate any ThreadCaches pointing to any blocks we just destroyed. - lifecycle_id_ = lifecycle_id_generator_.GetNext(); - return ResetInternal(); +ArenaImpl::~ArenaImpl() { + // Have to do this in a first pass, because some of the destructors might + // refer to memory in other blocks. + CleanupList(); + FreeBlocks(); } -uint64 ArenaImpl::ResetInternal() { - Block* head = - reinterpret_cast<Block*>(google::protobuf::internal::NoBarrier_Load(&blocks_)); - CleanupList(head); - uint64 space_allocated = FreeBlocks(head); +uint64 ArenaImpl::Reset() { + // Have to do this in a first pass, because some of the destructors might + // refer to memory in other blocks. + CleanupList(); + uint64 space_allocated = FreeBlocks(); + Init(); return space_allocated; } ArenaImpl::Block* ArenaImpl::NewBlock(void* me, Block* my_last_block, - size_t min_bytes, size_t start_block_size, - size_t max_block_size) { + size_t min_bytes) { size_t size; if (my_last_block != NULL) { // Double the current block size, up to a limit. - size = std::min(2 * my_last_block->size, max_block_size); + size = std::min(2 * my_last_block->size, options_.max_block_size); } else { - size = start_block_size; + size = options_.start_block_size; } // Verify that min_bytes + kHeaderSize won't overflow. GOOGLE_CHECK_LE(min_bytes, std::numeric_limits<size_t>::max() - kHeaderSize); size = std::max(size, kHeaderSize + min_bytes); Block* b = reinterpret_cast<Block*>(options_.block_alloc(size)); + InitBlock(b, me, size); + google::protobuf::internal::NoBarrier_AtomicIncrement(&space_allocated_, size); + return b; +} + +void ArenaImpl::InitBlock(Block* b, void *me, size_t size) { b->pos = kHeaderSize; b->size = size; b->owner = me; - b->cleanup = NULL; + b->next = NULL; #ifdef ADDRESS_SANITIZER // Poison the rest of the block for ASAN. It was unpoisoned by the underlying // malloc but it's not yet usable until we return it as part of an allocation. ASAN_POISON_MEMORY_REGION( reinterpret_cast<char*>(b) + b->pos, b->size - b->pos); #endif // ADDRESS_SANITIZER - AddBlock(b); - return b; -} - -void ArenaImpl::AddBlock(Block* b) { - MutexLock l(&blocks_lock_); - AddBlockInternal(b); } -void ArenaImpl::AddBlockInternal(Block* b) { - b->next = reinterpret_cast<Block*>(google::protobuf::internal::NoBarrier_Load(&blocks_)); - google::protobuf::internal::Release_Store(&blocks_, reinterpret_cast<google::protobuf::internal::AtomicWord>(b)); - space_allocated_ += b->size; -} - -ArenaImpl::Block* ArenaImpl::ExpandCleanupList(Block* b) { - size_t size = b->cleanup ? b->cleanup->size * 2 : kMinCleanupListElements; +ArenaImpl::CleanupChunk* ArenaImpl::ExpandCleanupList(CleanupChunk* cleanup, + Block* b) { + size_t size = cleanup ? cleanup->size * 2 : kMinCleanupListElements; size = std::min(size, kMaxCleanupListElements); size_t bytes = internal::AlignUpTo8(CleanupChunk::SizeOf(size)); if (b->avail() < bytes) { @@ -157,24 +145,25 @@ ArenaImpl::Block* ArenaImpl::ExpandCleanupList(Block* b) { } CleanupChunk* list = reinterpret_cast<CleanupChunk*>(AllocFromBlock(b, bytes)); - list->next = b->cleanup; + list->next = b->thread_info->cleanup; list->size = size; list->len = 0; - b->cleanup = list; - return b; + b->thread_info->cleanup = list; + return list; } inline GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE void ArenaImpl::AddCleanupInBlock( - Block* b, void* elem, void (*cleanup)(void*)) { - if (b->cleanup == NULL || b->cleanup->len == b->cleanup->size) { - b = ExpandCleanupList(b); + Block* b, void* elem, void (*func)(void*)) { + CleanupChunk* cleanup = b->thread_info->cleanup; + if (cleanup == NULL || cleanup->len == cleanup->size) { + cleanup = ExpandCleanupList(cleanup, b); } - CleanupNode* node = &b->cleanup->nodes[b->cleanup->len++]; + CleanupNode* node = &cleanup->nodes[cleanup->len++]; node->elem = elem; - node->cleanup = cleanup; + node->cleanup = func; } void ArenaImpl::AddCleanup(void* elem, void (*cleanup)(void*)) { @@ -240,92 +229,82 @@ void* ArenaImpl::AllocFromBlock(Block* b, size_t n) { ArenaImpl::Block* ArenaImpl::GetBlockSlow(void* me, Block* my_full_block, size_t n) { - Block* b = FindBlock(me); // Find block owned by me. - if (b == NULL || b->avail() < n) { - b = NewBlock(me, b, n, options_.start_block_size, options_.max_block_size); - - // Try to steal the cleanup list from my_full_block. It's too full for this - // allocation, but it might have space left in its cleanup list and there's - // no reason to waste that memory. - if (my_full_block) { - GOOGLE_DCHECK_EQ(my_full_block->owner, me); - GOOGLE_DCHECK(b->cleanup == NULL); - b->cleanup = my_full_block->cleanup; - my_full_block->cleanup = NULL; - } + ThreadInfo* info = + my_full_block ? my_full_block->thread_info : GetThreadInfo(me, n); + GOOGLE_DCHECK(info != NULL); + Block* b = info->head; + if (b->avail() < n) { + Block* new_b = NewBlock(me, b, n); + new_b->thread_info = info; + new_b->next = b; + info->head = new_b; + b = new_b; } CacheBlock(b); return b; } uint64 ArenaImpl::SpaceAllocated() const { - MutexLock l(&blocks_lock_); - return space_allocated_; + return google::protobuf::internal::NoBarrier_Load(&space_allocated_); } uint64 ArenaImpl::SpaceUsed() const { + ThreadInfo* info = + reinterpret_cast<ThreadInfo*>(google::protobuf::internal::Acquire_Load(&threads_)); uint64 space_used = 0; - Block* b = reinterpret_cast<Block*>(google::protobuf::internal::NoBarrier_Load(&blocks_)); - while (b != NULL) { - space_used += (b->pos - kHeaderSize); - b = b->next; + + for ( ; info; info = info->next) { + // Remove the overhead of the ThreadInfo itself. + space_used -= sizeof(ThreadInfo); + for (Block* b = info->head; b; b = b->next) { + space_used += (b->pos - kHeaderSize); + } } + return space_used; } -uint64 ArenaImpl::FreeBlocks(Block* head) { +uint64 ArenaImpl::FreeBlocks() { uint64 space_allocated = 0; - Block* first_block = NULL; - Block* b = head; + // By omitting an Acquire barrier we ensure that any user code that doesn't + // properly synchronize Reset() or the destructor will throw a TSAN warning. + ThreadInfo* info = + reinterpret_cast<ThreadInfo*>(google::protobuf::internal::NoBarrier_Load(&threads_)); + + while (info) { + // This is inside the block we are freeing, so we need to read it now. + ThreadInfo* next_info = info->next; + for (Block* b = info->head; b; ) { + // This is inside the block we are freeing, so we need to read it now. + Block* next_block = b->next; + space_allocated += (b->size); - while (b != NULL) { - space_allocated += (b->size); - Block* next = b->next; - if (next != NULL) { #ifdef ADDRESS_SANITIZER // This memory was provided by the underlying allocator as unpoisoned, so // return it in an unpoisoned state. ASAN_UNPOISON_MEMORY_REGION(reinterpret_cast<char*>(b), b->size); #endif // ADDRESS_SANITIZER - options_.block_dealloc(b, b->size); - } else { - if (owns_first_block_) { -#ifdef ADDRESS_SANITIZER - // This memory was provided by the underlying allocator as unpoisoned, - // so return it in an unpoisoned state. - ASAN_UNPOISON_MEMORY_REGION(reinterpret_cast<char*>(b), b->size); -#endif // ADDRESS_SANITIZER + + if (b != initial_block_) { options_.block_dealloc(b, b->size); - } else { - // User passed in the first block, skip free'ing the memory. - first_block = b; } + + b = next_block; } - b = next; - } - blocks_ = 0; - hint_ = 0; - space_allocated_ = 0; - if (!owns_first_block_) { - // Make the first block that was passed in through ArenaOptions - // available for reuse. - first_block->pos = kHeaderSize; - first_block->cleanup = NULL; - // Thread which calls Reset() owns the first block. This allows the - // single-threaded case to allocate on the first block without taking any - // locks. - first_block->owner = &thread_cache(); - AddBlockInternal(first_block); - CacheBlock(first_block); + info = next_info; } + return space_allocated; } -void ArenaImpl::CleanupList(Block* head) { - // Have to do this in a first pass, because some of the destructors might - // refer to memory in other blocks. - for (Block* b = head; b; b = b->next) { - CleanupChunk* list = b->cleanup; +void ArenaImpl::CleanupList() { + // By omitting an Acquire barrier we ensure that any user code that doesn't + // properly synchronize Reset() or the destructor will throw a TSAN warning. + ThreadInfo* info = + reinterpret_cast<ThreadInfo*>(google::protobuf::internal::NoBarrier_Load(&threads_)); + + for ( ; info; info = info->next) { + CleanupChunk* list = info->cleanup; while (list) { size_t n = list->len; CleanupNode* node = &list->nodes[list->len - 1]; @@ -334,24 +313,56 @@ void ArenaImpl::CleanupList(Block* head) { } list = list->next; } - b->cleanup = NULL; } } -ArenaImpl::Block* ArenaImpl::FindBlock(void* me) { - // TODO(sanjay): We might want to keep a separate list with one - // entry per thread. - Block* b = reinterpret_cast<Block*>(google::protobuf::internal::Acquire_Load(&blocks_)); - while (b != NULL && b->owner != me) { - b = b->next; +ArenaImpl::ThreadInfo* ArenaImpl::NewThreadInfo(Block* b) { + GOOGLE_DCHECK(FindThreadInfo(b->owner) == NULL); + ThreadInfo* info = + reinterpret_cast<ThreadInfo*>(AllocFromBlock(b, sizeof(ThreadInfo))); + b->thread_info = info; + info->owner = b->owner; + info->head = b; + info->cleanup = NULL; + return info; +} + +ArenaImpl::ThreadInfo* ArenaImpl::FindThreadInfo(void* me) { + ThreadInfo* info = + reinterpret_cast<ThreadInfo*>(google::protobuf::internal::Acquire_Load(&threads_)); + for ( ; info; info = info->next) { + if (info->owner == me) { + return info; + } } - return b; + + return NULL; +} + +ArenaImpl::ThreadInfo* ArenaImpl::GetThreadInfo(void* me, size_t n) { + ThreadInfo* info = FindThreadInfo(me); + + if (!info) { + // This thread doesn't have any ThreadInfo, which also means it doesn't have + // any blocks yet. So we'll allocate its first block now. + Block* b = NewBlock(me, NULL, sizeof(ThreadInfo) + n); + info = NewThreadInfo(b); + + google::protobuf::internal::AtomicWord head; + do { + head = google::protobuf::internal::NoBarrier_Load(&threads_); + info->next = reinterpret_cast<ThreadInfo*>(head); + } while (google::protobuf::internal::Release_CompareAndSwap( + &threads_, head, reinterpret_cast<google::protobuf::internal::AtomicWord>(info)) != head); + } + + return info; } } // namespace internal void Arena::CallDestructorHooks() { - uint64 space_allocated = SpaceAllocated(); + uint64 space_allocated = impl_.SpaceAllocated(); // Call the reset hook if (on_arena_reset_ != NULL) { on_arena_reset_(this, hooks_cookie_, space_allocated); diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h index a0cee22b..32be9a17 100644 --- a/src/google/protobuf/arena.h +++ b/src/google/protobuf/arena.h @@ -61,7 +61,7 @@ class Arena; // defined below class Message; // message.h namespace internal { -class ArenaString; // arenastring.h +struct ArenaStringPtr; // arenastring.h class LazyField; // lazy_field.h template<typename Type> @@ -223,6 +223,14 @@ class LIBPROTOBUF_EXPORT Arena { Init(options); } + // Block overhead. Use this as a guide for how much to over-allocate the + // initial block if you want an allocation of size N to fit inside it. + // + // WARNING: if you allocate multiple objects, it is difficult to guarantee + // that a series of allocations will fit in the initial block, especially if + // Arena changes its alignment guarantees in the future! + static const size_t kBlockOverhead = internal::ArenaImpl::kHeaderSize; + // Default constructor with sensible default options, tuned for average // use-cases. Arena() : impl_(ArenaOptions()) { Init(ArenaOptions()); } @@ -524,10 +532,9 @@ class LIBPROTOBUF_EXPORT Arena { // returns the total space used by the arena which is the sums of the sizes // of the allocated blocks. This method is not thread-safe. GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE uint64 Reset() { - uint64 space_allocated = SpaceAllocated(); // Call the reset hook if (on_arena_reset_ != NULL) { - on_arena_reset_(this, hooks_cookie_, space_allocated); + on_arena_reset_(this, hooks_cookie_, impl_.SpaceAllocated()); } return impl_.Reset(); } @@ -912,7 +919,7 @@ class LIBPROTOBUF_EXPORT Arena { template <typename Type> friend class ::google::protobuf::internal::GenericTypeHandler; - friend class internal::ArenaString; // For AllocateAligned. + friend struct internal::ArenaStringPtr; // For AllocateAligned. friend class internal::LazyField; // For CreateMaybeMessage. template <typename Key, typename T> friend class Map; diff --git a/src/google/protobuf/arena_impl.h b/src/google/protobuf/arena_impl.h index 5fa2475f..6cc7096b 100644 --- a/src/google/protobuf/arena_impl.h +++ b/src/google/protobuf/arena_impl.h @@ -82,6 +82,14 @@ class LIBPROTOBUF_EXPORT ArenaImpl { template <typename O> explicit ArenaImpl(const O& options) : options_(options) { + if (options_.initial_block != NULL && options_.initial_block_size > 0) { + GOOGLE_CHECK_GE(options_.initial_block_size, sizeof(Block)) + << ": Initial block size too small for header."; + initial_block_ = reinterpret_cast<Block*>(options_.initial_block); + } else { + initial_block_ = NULL; + } + Init(); } @@ -122,13 +130,22 @@ class LIBPROTOBUF_EXPORT ArenaImpl { CleanupNode nodes[1]; // True length is |size|. }; + struct Block; + + // Tracks per-thread info. ThreadInfos are kept in a linked list. + struct ThreadInfo { + void *owner; // &ThreadCache of this thread; + Block* head; // Head of linked list of blocks. + CleanupChunk* cleanup; // Head of cleanup list. + ThreadInfo* next; // Next ThreadInfo in this linked list. + }; + // Blocks are variable length malloc-ed objects. The following structure // describes the common header for all blocks. struct Block { - void* owner; // &ThreadCache of thread that owns this block. - Block* next; // Next block in arena (may have different owner) - CleanupChunk* cleanup; // Head of cleanup list (may point to another block, - // but it must have the same owner). + void* owner; // &ThreadCache of thread that owns this block. + ThreadInfo* thread_info; // ThreadInfo of thread that owns this block. + Block* next; // Next block in arena (may have different owner) // ((char*) &block) + pos is next available byte. It is always // aligned at a multiple of 8 bytes. size_t pos; @@ -139,18 +156,18 @@ class LIBPROTOBUF_EXPORT ArenaImpl { }; struct ThreadCache { +#if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL) + // If we are using the ThreadLocalStorage class to store the ThreadCache, + // then the ThreadCache's default constructor has to be responsible for + // initializing it. + ThreadCache() : last_lifecycle_id_seen(-1), last_block_used_(NULL) {} +#endif + // The ThreadCache is considered valid as long as this matches the // lifecycle_id of the arena being used. int64 last_lifecycle_id_seen; Block* last_block_used_; }; - - // kHeaderSize is sizeof(Block), aligned up to the nearest multiple of 8 to - // protect the invariant that pos is always at a multiple of 8. - static const size_t kHeaderSize = (sizeof(Block) + 7) & -8; -#if LANG_CXX11 - static_assert(kHeaderSize % 8 == 0, "kHeaderSize must be a multiple of 8."); -#endif static google::protobuf::internal::SequenceNumber lifecycle_id_generator_; #if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL) // Android ndk does not support GOOGLE_THREAD_LOCAL keyword so we use a custom thread @@ -170,44 +187,52 @@ class LIBPROTOBUF_EXPORT ArenaImpl { // Free all blocks and return the total space used which is the sums of sizes // of the all the allocated blocks. - uint64 FreeBlocks(Block* head); + uint64 FreeBlocks(); - void AddCleanupInBlock(Block* b, void* elem, void (*cleanup)(void*)); - Block* ExpandCleanupList(Block* b); + void AddCleanupInBlock(Block* b, void* elem, void (*func)(void*)); + CleanupChunk* ExpandCleanupList(CleanupChunk* cleanup, Block* b); // Delete or Destruct all objects owned by the arena. - void CleanupList(Block* head); - uint64 ResetInternal(); + void CleanupList(); inline void CacheBlock(Block* block) { thread_cache().last_block_used_ = block; thread_cache().last_lifecycle_id_seen = lifecycle_id_; + // TODO(haberman): evaluate whether we would gain efficiency by getting rid + // of hint_. It's the only write we do to ArenaImpl in the allocation path, + // which will dirty the cache line. google::protobuf::internal::Release_Store(&hint_, reinterpret_cast<google::protobuf::internal::AtomicWord>(block)); } - google::protobuf::internal::AtomicWord blocks_; // Head of linked list of all allocated blocks - google::protobuf::internal::AtomicWord hint_; // Fast thread-local block access - uint64 space_allocated_; // Sum of sizes of all allocated blocks. + google::protobuf::internal::AtomicWord threads_; // Pointer to a linked list of ThreadInfo. + google::protobuf::internal::AtomicWord hint_; // Fast thread-local block access + google::protobuf::internal::AtomicWord space_allocated_; // Sum of sizes of all allocated blocks. - bool owns_first_block_; // Indicates that arena owns the first block - mutable Mutex blocks_lock_; + Block *initial_block_; // If non-NULL, points to the block that came from + // user data. - void AddBlock(Block* b); - // Access must be synchronized, either by blocks_lock_ or by being called from - // Init()/Reset(). - void AddBlockInternal(Block* b); // Returns a block owned by this thread. Block* GetBlock(size_t n); Block* GetBlockSlow(void* me, Block* my_full_block, size_t n); - Block* FindBlock(void* me); - Block* NewBlock(void* me, Block* my_last_block, size_t min_bytes, - size_t start_block_size, size_t max_block_size); + Block* NewBlock(void* me, Block* my_last_block, size_t min_bytes); + void InitBlock(Block* b, void *me, size_t size); static void* AllocFromBlock(Block* b, size_t n); + ThreadInfo* NewThreadInfo(Block* b); + ThreadInfo* FindThreadInfo(void* me); + ThreadInfo* GetThreadInfo(void* me, size_t n); int64 lifecycle_id_; // Unique for each arena. Changes on Reset(). Options options_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ArenaImpl); + + public: + // kHeaderSize is sizeof(Block), aligned up to the nearest multiple of 8 to + // protect the invariant that pos is always at a multiple of 8. + static const size_t kHeaderSize = (sizeof(Block) + 7) & -8; +#if LANG_CXX11 + static_assert(kHeaderSize % 8 == 0, "kHeaderSize must be a multiple of 8."); +#endif }; } // namespace internal diff --git a/src/google/protobuf/arena_unittest.cc b/src/google/protobuf/arena_unittest.cc index 6172cade..c6ff25e8 100644 --- a/src/google/protobuf/arena_unittest.cc +++ b/src/google/protobuf/arena_unittest.cc @@ -270,7 +270,7 @@ TEST(ArenaTest, InitialBlockTooSmall) { // Construct a small (64 byte) initial block of memory to be used by the // arena allocator; then, allocate an object which will not fit in the // initial block. - std::vector<char> arena_block(64); + std::vector<char> arena_block(72); ArenaOptions options; options.initial_block = &arena_block[0]; options.initial_block_size = arena_block.size(); @@ -1299,12 +1299,12 @@ TEST(ArenaTest, SpaceAllocated_and_Used) { options.initial_block_size = 0; Arena arena_3(options); EXPECT_EQ(0, arena_3.SpaceUsed()); - ::google::protobuf::Arena::CreateArray<char>(&arena_3, 190); + ::google::protobuf::Arena::CreateArray<char>(&arena_3, 182); EXPECT_EQ(256, arena_3.SpaceAllocated()); - EXPECT_EQ(Align8(190), arena_3.SpaceUsed()); + EXPECT_EQ(Align8(182), arena_3.SpaceUsed()); ::google::protobuf::Arena::CreateArray<char>(&arena_3, 70); EXPECT_EQ(256 + 512, arena_3.SpaceAllocated()); - EXPECT_EQ(Align8(190) + Align8(70), arena_3.SpaceUsed()); + EXPECT_EQ(Align8(182) + Align8(70), arena_3.SpaceUsed()); EXPECT_EQ(256 + 512, arena_3.Reset()); } diff --git a/src/google/protobuf/arenastring_unittest.cc b/src/google/protobuf/arenastring_unittest.cc index c330b903..d5d995a6 100644 --- a/src/google/protobuf/arenastring_unittest.cc +++ b/src/google/protobuf/arenastring_unittest.cc @@ -49,7 +49,6 @@ namespace google { -using google::protobuf::internal::ArenaString; using google::protobuf::internal::ArenaStringPtr; namespace protobuf { @@ -110,6 +109,33 @@ TEST(ArenaStringPtrTest, ArenaStringPtrOnArena) { field2.Destroy(&default_value, &arena); } +TEST(ArenaStringPtrTest, ArenaStringPtrOnArenaNoSSO) { + google::protobuf::Arena arena; + ArenaStringPtr field; + ::std::string default_value = "default"; + field.UnsafeSetDefault(&default_value); + EXPECT_EQ(string("default"), field.Get()); + + // Avoid triggering the SSO optimization by setting the string to something + // larger than the internal buffer. + field.Set(&default_value, WrapString("Test long long long long value"), + &arena); + EXPECT_EQ(string("Test long long long long value"), field.Get()); + field.Set(&default_value, string(""), &arena); + field.Destroy(&default_value, &arena); + + ArenaStringPtr field2; + field2.UnsafeSetDefault(&default_value); + ::std::string* mut = field2.Mutable(&default_value, &arena); + EXPECT_EQ(mut, field2.Mutable(&default_value, &arena)); + EXPECT_EQ(mut, &field2.Get()); + EXPECT_NE(&default_value, mut); + EXPECT_EQ(string("default"), *mut); + *mut = "Test long long long long value"; // ensure string allocates storage + EXPECT_EQ(string("Test long long long long value"), field2.Get()); + field2.Destroy(&default_value, &arena); +} + } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/compiler/annotation_test_util.cc b/src/google/protobuf/compiler/annotation_test_util.cc new file mode 100644 index 00000000..aa14faf6 --- /dev/null +++ b/src/google/protobuf/compiler/annotation_test_util.cc @@ -0,0 +1,187 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include <google/protobuf/compiler/annotation_test_util.h> + +#include <memory> +#ifndef _SHARED_PTR_H +#include <google/protobuf/stubs/shared_ptr.h> +#endif +#include <google/protobuf/compiler/code_generator.h> +#include <google/protobuf/compiler/command_line_interface.h> +#include <google/protobuf/io/printer.h> +#include <google/protobuf/io/zero_copy_stream.h> +#include <google/protobuf/io/zero_copy_stream_impl_lite.h> +#include <google/protobuf/descriptor.pb.h> + +#include <google/protobuf/testing/file.h> +#include <google/protobuf/testing/file.h> +#include <google/protobuf/testing/googletest.h> +#include <gtest/gtest.h> + +namespace google { +namespace protobuf { +namespace compiler { +namespace annotation_test_util { +namespace { + +// A CodeGenerator that captures the FileDescriptor it's passed as a +// FileDescriptorProto. +class DescriptorCapturingGenerator : public CodeGenerator { + public: + // Does not own file; file must outlive the Generator. + explicit DescriptorCapturingGenerator(FileDescriptorProto* file) + : file_(file) {} + + virtual bool Generate(const FileDescriptor* file, const string& parameter, + GeneratorContext* context, string* error) const { + file->CopyTo(file_); + return true; + } + + private: + FileDescriptorProto* file_; +}; +} // namespace + +void AddFile(const string& filename, const string& data) { + GOOGLE_CHECK_OK(File::SetContents(TestTempDir() + "/" + filename, data, + true)); +} + +bool CaptureMetadata(const string& filename, const string& plugin_specific_args, + const string& meta_file_suffix, CommandLineInterface* cli, + FileDescriptorProto* file, + std::vector<ExpectedOutput>* outputs) { + cli->SetInputsAreProtoPathRelative(true); + + DescriptorCapturingGenerator capturing_generator(file); + cli->RegisterGenerator("--capture_out", &capturing_generator, ""); + + string proto_path = "-I" + TestTempDir(); + string capture_out = "--capture_out=" + TestTempDir(); + + const char* argv[] = {"protoc", proto_path.c_str(), + plugin_specific_args.c_str(), capture_out.c_str(), + filename.c_str()}; + + if (cli->Run(5, argv) != 0) { + return false; + } + + if (outputs != NULL) { + for (std::vector<ExpectedOutput>::iterator i = outputs->begin(); + i != outputs->end(); ++i) { + GOOGLE_CHECK_OK(File::GetContents(TestTempDir() + "/" + i->file_path, + &i->file_content, true)); + if (!DecodeMetadata( + TestTempDir() + "/" + i->file_path + meta_file_suffix, + &i->file_info)) { + return false; + } + } + } + + return true; +} + +bool DecodeMetadata(const string& path, GeneratedCodeInfo* info) { + string data; + GOOGLE_CHECK_OK(File::GetContents(path, &data, true)); + io::ArrayInputStream input(data.data(), data.size()); + return info->ParseFromZeroCopyStream(&input); +} + +void FindAnnotationsOnPath( + const GeneratedCodeInfo& info, const string& source_file, + const std::vector<int>& path, + std::vector<const GeneratedCodeInfo::Annotation*>* annotations) { + for (int i = 0; i < info.annotation_size(); ++i) { + const GeneratedCodeInfo::Annotation* annotation = &info.annotation(i); + if (annotation->source_file() != source_file || + annotation->path_size() != path.size()) { + continue; + } + int node = 0; + for (; node < path.size(); ++node) { + if (annotation->path(node) != path[node]) { + break; + } + } + if (node == path.size()) { + annotations->push_back(annotation); + } + } +} + +const GeneratedCodeInfo::Annotation* FindAnnotationOnPath( + const GeneratedCodeInfo& info, const string& source_file, + const std::vector<int>& path) { + std::vector<const GeneratedCodeInfo::Annotation*> annotations; + FindAnnotationsOnPath(info, source_file, path, &annotations); + if (annotations.empty()) { + return NULL; + } + return annotations[0]; +} + +bool AtLeastOneAnnotationMatchesSubstring( + const string& file_content, + const std::vector<const GeneratedCodeInfo::Annotation*>& annotations, + const string& expected_text) { + for (std::vector<const GeneratedCodeInfo::Annotation*>::const_iterator + i = annotations.begin(), + e = annotations.end(); + i != e; ++i) { + const GeneratedCodeInfo::Annotation* annotation = *i; + uint32 begin = annotation->begin(); + uint32 end = annotation->end(); + if (end < begin || end > file_content.size()) { + return false; + } + if (file_content.substr(begin, end - begin) == expected_text) { + return true; + } + } + return false; +} + +bool AnnotationMatchesSubstring(const string& file_content, + const GeneratedCodeInfo::Annotation* annotation, + const string& expected_text) { + std::vector<const GeneratedCodeInfo::Annotation*> annotations; + annotations.push_back(annotation); + return AtLeastOneAnnotationMatchesSubstring(file_content, annotations, + expected_text); +} +} // namespace annotation_test_util +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/src/google/protobuf/compiler/annotation_test_util.h b/src/google/protobuf/compiler/annotation_test_util.h new file mode 100644 index 00000000..4598a45a --- /dev/null +++ b/src/google/protobuf/compiler/annotation_test_util.h @@ -0,0 +1,119 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef GOOGLE_PROTOBUF_COMPILER_ANNOTATION_TEST_UTIL_H__ +#define GOOGLE_PROTOBUF_COMPILER_ANNOTATION_TEST_UTIL_H__ + +#include <google/protobuf/descriptor.pb.h> +#include <google/protobuf/testing/googletest.h> +#include <gtest/gtest.h> + +// Utilities that assist in writing tests for generator annotations. +// See java/internal/annotation_unittest.cc for an example. +namespace google { +namespace protobuf { +namespace compiler { +namespace annotation_test_util { + +// Struct that contains the file generated from a .proto file and its +// GeneratedCodeInfo. For example, the Java generator will fill this struct +// (for some 'foo.proto') with: +// file_path = "Foo.java" +// file_content = content of Foo.java +// file_info = parsed content of Foo.java.pb.meta +struct ExpectedOutput { + string file_path; + string file_content; + GeneratedCodeInfo file_info; + explicit ExpectedOutput(const string& file_path) : file_path(file_path) {} +}; + +// Creates a file with name `filename` and content `data` in temp test +// directory. +void AddFile(const string& filename, const string& data); + +// Tries to capture a FileDescriptorProto, GeneratedCodeInfo, and output +// code from the previously added file with name `filename`. +// +// filename: source .proto file used to generate code. +// plugin_specific_args: command line arguments specific to current generator. +// For Java, this value might be "--java_out=annotate_code:test_temp_dir" +// meta_file_suffix: suffix of meta files that contain annotations. For Java +// it is ".pb.meta" because for file Foo.java meta file is Foo.java.pb.meta +// cli: instance of command line interface to run generator. See Java's +// annotation_unittest.cc for an example of how to initialize it. +// file: output parameter, will be set to the descriptor of the proto file +// specified in filename. +// outputs: output parameter. If not NULL, each ExpectedOutput in the vector +// should have its file_path set; CaptureMetadata will fill the rest of +// the fields appropriately. +bool CaptureMetadata(const string& filename, const string& plugin_specific_args, + const string& meta_file_suffix, CommandLineInterface* cli, + FileDescriptorProto* file, + std::vector<ExpectedOutput>* outputs); + +bool DecodeMetadata(const string& path, GeneratedCodeInfo* info); + +// Finds all of the Annotations for a given source file and path. +// See Location.path in http://google/protobuf/descriptor.proto for +// explanation of what path vector is. +void FindAnnotationsOnPath( + const GeneratedCodeInfo& info, const string& source_file, + const std::vector<int>& path, + std::vector<const GeneratedCodeInfo::Annotation*>* annotations); + +// Finds the Annotation for a given source file and path (or returns null if it +// couldn't). If there are several annotations for given path, returns the first +// one. See Location.path in +// http://google/protobuf/descriptor.proto for explanation of what path +// vector is. +const GeneratedCodeInfo::Annotation* FindAnnotationOnPath( + const GeneratedCodeInfo& info, const string& source_file, + const std::vector<int>& path); + +// Returns true if at least one of the provided annotations covers a given +// substring in file_content. +bool AtLeastOneAnnotationMatchesSubstring( + const string& file_content, + const std::vector<const GeneratedCodeInfo::Annotation*>& annotations, + const string& expected_text); + +// Returns true if the provided annotation covers a given substring in +// file_content. +bool AnnotationMatchesSubstring(const string& file_content, + const GeneratedCodeInfo::Annotation* annotation, + const string& expected_text); + +} // namespace annotation_test_util +} // namespace compiler +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_COMPILER_ANNOTATION_TEST_UTIL_H__ diff --git a/src/google/protobuf/compiler/cpp/cpp_enum_field.cc b/src/google/protobuf/compiler/cpp/cpp_enum_field.cc index 008490ed..3d5b5b8d 100644 --- a/src/google/protobuf/compiler/cpp/cpp_enum_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_enum_field.cc @@ -82,21 +82,18 @@ GenerateAccessorDeclarations(io::Printer* printer) const { } void EnumFieldGenerator:: -GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const { - std::map<string, string> variables(variables_); - variables["inline"] = is_inline ? "inline " : ""; - printer->Print(variables, - "$inline$$type$ $classname$::$name$() const {\n" +GenerateInlineAccessorDefinitions(io::Printer* printer) const { + printer->Print(variables_, + "inline $type$ $classname$::$name$() const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " return static_cast< $type$ >($name$_);\n" "}\n" - "$inline$void $classname$::set_$name$($type$ value) {\n"); + "inline void $classname$::set_$name$($type$ value) {\n"); if (!HasPreservingUnknownEnumSemantics(descriptor_->file())) { - printer->Print(variables, + printer->Print(variables_, " assert($type$_IsValid(value));\n"); } - printer->Print(variables, + printer->Print(variables_, " $set_hasbit$\n" " $name$_ = value;\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" @@ -193,24 +190,21 @@ EnumOneofFieldGenerator(const FieldDescriptor* descriptor, EnumOneofFieldGenerator::~EnumOneofFieldGenerator() {} void EnumOneofFieldGenerator:: -GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const { - std::map<string, string> variables(variables_); - variables["inline"] = is_inline ? "inline " : ""; - printer->Print(variables, - "$inline$$type$ $classname$::$name$() const {\n" +GenerateInlineAccessorDefinitions(io::Printer* printer) const { + printer->Print(variables_, + "inline $type$ $classname$::$name$() const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " if (has_$name$()) {\n" " return static_cast< $type$ >($oneof_prefix$$name$_);\n" " }\n" " return static_cast< $type$ >($default$);\n" "}\n" - "$inline$void $classname$::set_$name$($type$ value) {\n"); + "inline void $classname$::set_$name$($type$ value) {\n"); if (!HasPreservingUnknownEnumSemantics(descriptor_->file())) { - printer->Print(variables, + printer->Print(variables_, " assert($type$_IsValid(value));\n"); } - printer->Print(variables, + printer->Print(variables_, " if (!has_$name$()) {\n" " clear_$oneof_name$();\n" " set_has_$name$();\n" @@ -280,39 +274,36 @@ GenerateAccessorDeclarations(io::Printer* printer) const { } void RepeatedEnumFieldGenerator:: -GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const { - std::map<string, string> variables(variables_); - variables["inline"] = is_inline ? "inline " : ""; - printer->Print(variables, - "$inline$$type$ $classname$::$name$(int index) const {\n" +GenerateInlineAccessorDefinitions(io::Printer* printer) const { + printer->Print(variables_, + "inline $type$ $classname$::$name$(int index) const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " return static_cast< $type$ >($name$_.Get(index));\n" "}\n" - "$inline$void $classname$::set_$name$(int index, $type$ value) {\n"); + "inline void $classname$::set_$name$(int index, $type$ value) {\n"); if (!HasPreservingUnknownEnumSemantics(descriptor_->file())) { - printer->Print(variables, + printer->Print(variables_, " assert($type$_IsValid(value));\n"); } - printer->Print(variables, + printer->Print(variables_, " $name$_.Set(index, value);\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" "}\n" - "$inline$void $classname$::add_$name$($type$ value) {\n"); + "inline void $classname$::add_$name$($type$ value) {\n"); if (!HasPreservingUnknownEnumSemantics(descriptor_->file())) { - printer->Print(variables, + printer->Print(variables_, " assert($type$_IsValid(value));\n"); } - printer->Print(variables, + printer->Print(variables_, " $name$_.Add(value);\n" " // @@protoc_insertion_point(field_add:$full_name$)\n" "}\n" - "$inline$const ::google::protobuf::RepeatedField<int>&\n" + "inline const ::google::protobuf::RepeatedField<int>&\n" "$classname$::$name$() const {\n" " // @@protoc_insertion_point(field_list:$full_name$)\n" " return $name$_;\n" "}\n" - "$inline$::google::protobuf::RepeatedField<int>*\n" + "inline ::google::protobuf::RepeatedField<int>*\n" "$classname$::mutable_$name$() {\n" " // @@protoc_insertion_point(field_mutable_list:$full_name$)\n" " return &$name$_;\n" diff --git a/src/google/protobuf/compiler/cpp/cpp_enum_field.h b/src/google/protobuf/compiler/cpp/cpp_enum_field.h index 3ecd7ba8..d0e87b79 100644 --- a/src/google/protobuf/compiler/cpp/cpp_enum_field.h +++ b/src/google/protobuf/compiler/cpp/cpp_enum_field.h @@ -52,8 +52,7 @@ class EnumFieldGenerator : public FieldGenerator { // implements FieldGenerator --------------------------------------- void GeneratePrivateMembers(io::Printer* printer) const; void GenerateAccessorDeclarations(io::Printer* printer) const; - void GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const; + void GenerateInlineAccessorDefinitions(io::Printer* printer) const; void GenerateClearingCode(io::Printer* printer) const; void GenerateMergingCode(io::Printer* printer) const; void GenerateSwappingCode(io::Printer* printer) const; @@ -79,8 +78,7 @@ class EnumOneofFieldGenerator : public EnumFieldGenerator { ~EnumOneofFieldGenerator(); // implements FieldGenerator --------------------------------------- - void GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const; + void GenerateInlineAccessorDefinitions(io::Printer* printer) const; void GenerateClearingCode(io::Printer* printer) const; void GenerateSwappingCode(io::Printer* printer) const; void GenerateConstructorCode(io::Printer* printer) const; @@ -98,8 +96,7 @@ class RepeatedEnumFieldGenerator : public FieldGenerator { // implements FieldGenerator --------------------------------------- void GeneratePrivateMembers(io::Printer* printer) const; void GenerateAccessorDeclarations(io::Printer* printer) const; - void GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const; + void GenerateInlineAccessorDefinitions(io::Printer* printer) const; void GenerateClearingCode(io::Printer* printer) const; void GenerateMergingCode(io::Printer* printer) const; void GenerateSwappingCode(io::Printer* printer) const; diff --git a/src/google/protobuf/compiler/cpp/cpp_field.h b/src/google/protobuf/compiler/cpp/cpp_field.h index d9dd3850..891e30f6 100644 --- a/src/google/protobuf/compiler/cpp/cpp_field.h +++ b/src/google/protobuf/compiler/cpp/cpp_field.h @@ -109,19 +109,19 @@ class FieldGenerator { // Generate inline definitions of depenent accessor functions for this field. // These are placed inside the header after all class definitions. virtual void GenerateDependentInlineAccessorDefinitions( - io::Printer* printer) const {} + io::Printer* printer) const {} // Generate inline definitions of accessor functions for this field. // These are placed inside the header after all class definitions. // In non-.proto.h mode, this generates dependent accessor functions as well. virtual void GenerateInlineAccessorDefinitions( - io::Printer* printer, bool is_inline) const = 0; + io::Printer* printer) const = 0; // Generate definitions of accessors that aren't inlined. These are // placed somewhere in the .cc file. // Most field types don't need this, so the default implementation is empty. virtual void GenerateNonInlineAccessorDefinitions( - io::Printer* /*printer*/) const {} + io::Printer* /*printer*/) const {} // Generate lines of code (statements, not declarations) which clear the // field. This is used to define the clear_$name$() method diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc index 0e74f215..52a16835 100644 --- a/src/google/protobuf/compiler/cpp/cpp_file.cc +++ b/src/google/protobuf/compiler/cpp/cpp_file.cc @@ -303,6 +303,18 @@ void FileGenerator::GenerateSourceIncludes(io::Printer* printer) { } } + // TODO(gerbens) Remove this when all code in google is using the same + // proto library. This is a temporary hack to force build errors if + // the proto library is compiled with GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + // and is also linking internal proto2. This is to prevent regressions while + // we work cleaning up the code base. After this is completed and we have + // one proto lib all code uses this should be removed. + printer->Print( + "// This is a temporary google only hack\n" + "#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS\n" + "#include \"third_party/protobuf/version.h\"\n" + "#endif\n"); + printer->Print( "// @@protoc_insertion_point(includes)\n"); } @@ -385,6 +397,10 @@ void FileGenerator::GenerateSourceForMessage(int idx, io::Printer* printer) { // Define default instances GenerateSourceDefaultInstance(idx, printer); + if (UsingImplicitWeakFields(file_, options_)) { + printer->Print("void $classname$_ReferenceStrong() {}\n", "classname", + message_generators_[idx]->classname_); + } // Generate classes. printer->Print("\n"); @@ -452,7 +468,7 @@ void FileGenerator::GenerateSource(io::Printer* printer) { for (int i = 0; i < message_generators_.size(); i++) { GenerateSourceDefaultInstance(i, printer); if (UsingImplicitWeakFields(file_, options_)) { - printer->Print("void $classname$_Reference() {}\n", "classname", + printer->Print("void $classname$_ReferenceStrong() {}\n", "classname", message_generators_[i]->classname_); } } @@ -564,7 +580,7 @@ class FileGenerator::ForwardDeclarations { "classname", it->first); if (options.lite_implicit_weak_fields) { - printer->Print("void $classname$_Reference();\n", + printer->Print("void $classname$_ReferenceStrong();\n", "classname", it->first); } } @@ -827,8 +843,12 @@ void FileGenerator::GenerateInitForSCC(const SCC* scc, io::Printer* printer) { printer->Print( "void InitDefaults$scc_name$Impl() {\n" " GOOGLE_PROTOBUF_VERIFY_VERSION;\n\n" + "#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS\n" + " ::google::protobuf::internal::InitProtobufDefaultsForceUnique();\n" + "#else\n" + " ::google::protobuf::internal::InitProtobufDefaults();\n" + "#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS\n", // Force initialization of primitive values we depend on. - " ::google::protobuf::internal::InitProtobufDefaults();\n", "scc_name", scc_name); printer->Indent(); @@ -1317,8 +1337,7 @@ void FileGenerator::GenerateInlineFunctionDefinitions(io::Printer* printer) { printer->Print(kThinSeparator); printer->Print("\n"); } - message_generators_[i]->GenerateInlineMethods(printer, - /* is_inline = */ true); + message_generators_[i]->GenerateInlineMethods(printer); } printer->Print( "#ifdef __GNUC__\n" diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/src/google/protobuf/compiler/cpp/cpp_helpers.cc index 4aa77d06..96950e52 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.cc +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.cc @@ -216,7 +216,7 @@ string DefaultInstanceName(const Descriptor* descriptor) { } string ReferenceFunctionName(const Descriptor* descriptor) { - return QualifiedClassName(descriptor) + "_Reference"; + return QualifiedClassName(descriptor) + "_ReferenceStrong"; } string DependentBaseClassTemplateName(const Descriptor* descriptor) { @@ -753,8 +753,7 @@ bool IsImplicitWeakField(const FieldDescriptor* field, const Options& options) { return UsingImplicitWeakFields(field->file(), options) && field->type() == FieldDescriptor::TYPE_MESSAGE && !field->is_required() && !field->is_repeated() && !field->is_map() && - field->containing_oneof() == NULL && - field->message_type()->file() != field->file(); + field->containing_oneof() == NULL; } struct CompareDescriptors { diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.h b/src/google/protobuf/compiler/cpp/cpp_helpers.h index 550438dd..e0f809c9 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.h +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.h @@ -305,6 +305,11 @@ inline bool SupportsArenas(const FieldDescriptor* field) { return SupportsArenas(field->file()); } +inline bool IsCrossFileMessage(const FieldDescriptor* field) { + return field->type() == FieldDescriptor::TYPE_MESSAGE && + field->message_type()->file() != field->file(); +} + bool IsAnyMessage(const FileDescriptor* descriptor); bool IsAnyMessage(const Descriptor* descriptor); diff --git a/src/google/protobuf/compiler/cpp/cpp_map_field.cc b/src/google/protobuf/compiler/cpp/cpp_map_field.cc index d06a1d39..b22c0754 100644 --- a/src/google/protobuf/compiler/cpp/cpp_map_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_map_field.cc @@ -137,17 +137,14 @@ GenerateAccessorDeclarations(io::Printer* printer) const { } void MapFieldGenerator:: -GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const { - std::map<string, string> variables(variables_); - variables["inline"] = is_inline ? "inline" : ""; - printer->Print(variables, - "$inline$ const ::google::protobuf::Map< $key_cpp$, $val_cpp$ >&\n" +GenerateInlineAccessorDefinitions(io::Printer* printer) const { + printer->Print(variables_, + "inline const ::google::protobuf::Map< $key_cpp$, $val_cpp$ >&\n" "$classname$::$name$() const {\n" " // @@protoc_insertion_point(field_map:$full_name$)\n" " return $name$_.GetMap();\n" "}\n" - "$inline$ ::google::protobuf::Map< $key_cpp$, $val_cpp$ >*\n" + "inline ::google::protobuf::Map< $key_cpp$, $val_cpp$ >*\n" "$classname$::mutable_$name$() {\n" " // @@protoc_insertion_point(field_mutable_map:$full_name$)\n" " return $name$_.MutableMap();\n" @@ -156,9 +153,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, void MapFieldGenerator:: GenerateClearingCode(io::Printer* printer) const { - std::map<string, string> variables(variables_); - variables["this_message"] = dependent_field_ ? DependentBaseDownCast() : ""; - printer->Print(variables, "$this_message$$name$_.Clear();\n"); + printer->Print(variables_, "$name$_.Clear();\n"); } void MapFieldGenerator:: diff --git a/src/google/protobuf/compiler/cpp/cpp_map_field.h b/src/google/protobuf/compiler/cpp/cpp_map_field.h index 02e66497..88e3b464 100644 --- a/src/google/protobuf/compiler/cpp/cpp_map_field.h +++ b/src/google/protobuf/compiler/cpp/cpp_map_field.h @@ -49,8 +49,7 @@ class MapFieldGenerator : public FieldGenerator { // implements FieldGenerator --------------------------------------- void GeneratePrivateMembers(io::Printer* printer) const; void GenerateAccessorDeclarations(io::Printer* printer) const; - void GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const; + void GenerateInlineAccessorDefinitions(io::Printer* printer) const; void GenerateClearingCode(io::Printer* printer) const; void GenerateMergingCode(io::Printer* printer) const; void GenerateSwappingCode(io::Printer* printer) const; diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc index cf9c1233..60467598 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message.cc @@ -306,6 +306,25 @@ void SetUnknkownFieldsVariable(const Descriptor* descriptor, "_internal_metadata_.mutable_unknown_fields()"; } +bool IsCrossFileMapField(const FieldDescriptor* field) { + if (!field->is_map()) { + return false; + } + + const Descriptor* d = field->message_type(); + const FieldDescriptor* value = d->FindFieldByNumber(2); + + return IsCrossFileMessage(value); +} + +bool IsCrossFileMaybeMap(const FieldDescriptor* field) { + if (IsCrossFileMapField(field)) { + return true; + } + + return IsCrossFileMessage(field); +} + } // anonymous namespace // =================================================================== @@ -426,12 +445,6 @@ GenerateDependentFieldAccessorDeclarations(io::Printer* printer) { std::map<string, string> vars; SetCommonFieldVariables(field, &vars, options_); - if (use_dependent_base_ && IsFieldDependent(field)) { - // If the message is dependent, the inline clear_*() method will need - // to delete the message type, so it must be in the dependent base - // class. (See also GenerateFieldAccessorDeclarations.) - printer->Print(vars, "$deprecated_attr$void clear_$name$();\n"); - } // Generate type-specific accessor declarations. field_generators_.get(field).GenerateDependentAccessorDeclarations(printer); printer->Print("\n"); @@ -498,12 +511,8 @@ GenerateFieldAccessorDeclarations(io::Printer* printer) { printer->Annotate("{", "}", field); } - if (!dependent_field) { - // If this field is dependent, then its clear_() method is in the - // depenent base class. (See also GenerateDependentAccessorDeclarations.) - printer->Print(vars, "$deprecated_attr$void ${$clear_$name$$}$();\n"); - printer->Annotate("{", "}", field); - } + printer->Print(vars, "$deprecated_attr$void ${$clear_$name$$}$();\n"); + printer->Annotate("{", "}", field); printer->Print(vars, "$deprecated_attr$static const int $constant_name$ = " "$number$;\n"); @@ -545,36 +554,6 @@ GenerateDependentFieldAccessorDefinitions(io::Printer* printer) { if (field->options().weak()) continue; PrintFieldComment(printer, field); - - // These functions are not really dependent: they are part of the - // (non-dependent) derived class. However, they need to live outside - // any #ifdef guards, so we treat them as if they were dependent. - // - // See the comment in FileGenerator::GenerateInlineFunctionDefinitions - // for a more complete explanation. - if (use_dependent_base_ && IsFieldDependent(field)) { - std::map<string, string> vars; - SetCommonFieldVariables(field, &vars, options_); - vars["inline"] = "inline "; - if (field->containing_oneof()) { - vars["field_name"] = UnderscoresToCamelCase(field->name(), true); - vars["oneof_name"] = field->containing_oneof()->name(); - vars["oneof_index"] = SimpleItoa(field->containing_oneof()->index()); - GenerateOneofMemberHasBits(field, vars, printer); - } else if (!field->is_repeated()) { - // There will be no header guard, so this always has to be inline. - GenerateSingularFieldHasBits(field, vars, printer); - } - // vars needed for clear_(), which is in the dependent base: - // (See also GenerateDependentFieldAccessorDeclarations.) - vars["tmpl"] = "template<class T>\n"; - vars["dependent_classname"] = - DependentBaseClassTemplateName(descriptor_) + "<T>"; - vars["this_message"] = DependentBaseDownCast(); - vars["this_const_message"] = DependentBaseConstDownCast(); - GenerateFieldClear(field, vars, printer); - } - // Generate type-specific accessors. field_generators_.get(field) .GenerateDependentInlineAccessorDefinitions(printer); @@ -585,7 +564,7 @@ GenerateDependentFieldAccessorDefinitions(io::Printer* printer) { // Generate has_$name$() and clear_has_$name$() functions for oneofs // Similar to other has-bits, these must always be in the header if we // are using a dependent base class. - GenerateOneofHasBits(printer, true /* is_inline */); + GenerateOneofHasBits(printer); } void MessageGenerator:: @@ -595,8 +574,7 @@ GenerateSingularFieldHasBits(const FieldDescriptor* field, if (field->options().weak()) { printer->Print( vars, - "$inline$" - "bool $classname$::has_$name$() const {\n" + "inline bool $classname$::has_$name$() const {\n" " return _weak_field_map_.Has($number$);\n" "}\n"); return; @@ -611,16 +589,13 @@ GenerateSingularFieldHasBits(const FieldDescriptor* field, vars["has_mask"] = StrCat(strings::Hex(1u << (has_bit_index % 32), strings::ZERO_PAD_8)); printer->Print(vars, - "$inline$" - "bool $classname$::has_$name$() const {\n" + "inline bool $classname$::has_$name$() const {\n" " return (_has_bits_[$has_array_index$] & 0x$has_mask$u) != 0;\n" "}\n" - "$inline$" - "void $classname$::set_has_$name$() {\n" + "inline void $classname$::set_has_$name$() {\n" " _has_bits_[$has_array_index$] |= 0x$has_mask$u;\n" "}\n" - "$inline$" - "void $classname$::clear_has_$name$() {\n" + "inline void $classname$::clear_has_$name$() {\n" " _has_bits_[$has_array_index$] &= ~0x$has_mask$u;\n" "}\n"); } else { @@ -629,15 +604,13 @@ GenerateSingularFieldHasBits(const FieldDescriptor* field, bool is_lazy = false; if (is_lazy) { printer->Print(vars, - "$inline$" - "bool $classname$::has_$name$() const {\n" + "inline bool $classname$::has_$name$() const {\n" " return !$name$_.IsCleared();\n" "}\n"); } else { printer->Print( vars, - "$inline$" - "bool $classname$::has_$name$() const {\n" + "inline bool $classname$::has_$name$() const {\n" " return this != internal_default_instance() && $name$_ != NULL;\n" "}\n"); } @@ -646,7 +619,7 @@ GenerateSingularFieldHasBits(const FieldDescriptor* field, } void MessageGenerator:: -GenerateOneofHasBits(io::Printer* printer, bool is_inline) { +GenerateOneofHasBits(io::Printer* printer) { for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { std::map<string, string> vars; vars["oneof_name"] = descriptor_->oneof_decl(i)->name(); @@ -654,15 +627,12 @@ GenerateOneofHasBits(io::Printer* printer, bool is_inline) { vars["cap_oneof_name"] = ToUpper(descriptor_->oneof_decl(i)->name()); vars["classname"] = classname_; - vars["inline"] = (is_inline ? "inline " : ""); printer->Print( vars, - "$inline$" - "bool $classname$::has_$oneof_name$() const {\n" + "inline bool $classname$::has_$oneof_name$() const {\n" " return $oneof_name$_case() != $cap_oneof_name$_NOT_SET;\n" "}\n" - "$inline$" - "void $classname$::clear_has_$oneof_name$() {\n" + "inline void $classname$::clear_has_$oneof_name$() {\n" " _oneof_case_[$oneof_index$] = $cap_oneof_name$_NOT_SET;\n" "}\n"); } @@ -679,13 +649,11 @@ GenerateOneofMemberHasBits(const FieldDescriptor* field, // method, so that generated code is slightly cleaner (vs. comparing // _oneof_case_[index] against a constant everywhere). printer->Print(vars, - "$inline$" - "bool $classname$::has_$name$() const {\n" + "inline bool $classname$::has_$name$() const {\n" " return $oneof_name$_case() == k$field_name$;\n" "}\n"); printer->Print(vars, - "$inline$" - "void $classname$::set_has_$name$() {\n" + "inline void $classname$::set_has_$name$() {\n" " _oneof_case_[$oneof_index$] = k$field_name$;\n" "}\n"); } @@ -693,14 +661,14 @@ GenerateOneofMemberHasBits(const FieldDescriptor* field, void MessageGenerator:: GenerateFieldClear(const FieldDescriptor* field, const std::map<string, string>& vars, + bool is_inline, io::Printer* printer) { - // Generate clear_$name$() (See GenerateFieldAccessorDeclarations and - // GenerateDependentFieldAccessorDeclarations, $dependent_classname$ is - // set by the Generate*Definitions functions.) + // Generate clear_$name$(). + if (is_inline) { + printer->Print("inline "); + } printer->Print(vars, - "$tmpl$" - "$inline$" - "void $dependent_classname$::clear_$name$() {\n"); + "void $classname$::clear_$name$() {\n"); printer->Indent(); @@ -708,12 +676,12 @@ GenerateFieldClear(const FieldDescriptor* field, // Clear this field only if it is the active field in this oneof, // otherwise ignore printer->Print(vars, - "if ($this_message$has_$name$()) {\n"); + "if (has_$name$()) {\n"); printer->Indent(); field_generators_.get(field) .GenerateClearingCode(printer); printer->Print(vars, - "$this_message$clear_has_$oneof_name$();\n"); + "clear_has_$oneof_name$();\n"); printer->Outdent(); printer->Print("}\n"); } else { @@ -721,8 +689,7 @@ GenerateFieldClear(const FieldDescriptor* field, .GenerateClearingCode(printer); if (HasFieldPresence(descriptor_->file())) { if (!field->is_repeated() && !field->options().weak()) { - printer->Print(vars, - "$this_message$clear_has_$name$();\n"); + printer->Print(vars, "clear_has_$name$();\n"); } } } @@ -732,7 +699,7 @@ GenerateFieldClear(const FieldDescriptor* field, } void MessageGenerator:: -GenerateFieldAccessorDefinitions(io::Printer* printer, bool is_inline) { +GenerateFieldAccessorDefinitions(io::Printer* printer) { printer->Print("// $classname$\n\n", "classname", classname_); for (int i = 0; i < descriptor_->field_count(); i++) { @@ -742,7 +709,6 @@ GenerateFieldAccessorDefinitions(io::Printer* printer, bool is_inline) { std::map<string, string> vars; SetCommonFieldVariables(field, &vars, options_); - vars["inline"] = is_inline ? "inline " : ""; if (use_dependent_base_ && IsFieldDependent(field)) { vars["tmpl"] = "template<class T>\n"; vars["dependent_classname"] = @@ -759,31 +725,25 @@ GenerateFieldAccessorDefinitions(io::Printer* printer, bool is_inline) { // Generate has_$name$() or $name$_size(). if (field->is_repeated()) { printer->Print(vars, - "$inline$" - "int $classname$::$name$_size() const {\n" + "inline int $classname$::$name$_size() const {\n" " return $name$_.size();\n" "}\n"); } else if (field->containing_oneof()) { vars["field_name"] = UnderscoresToCamelCase(field->name(), true); vars["oneof_name"] = field->containing_oneof()->name(); vars["oneof_index"] = SimpleItoa(field->containing_oneof()->index()); - if (!use_dependent_base_ || !IsFieldDependent(field)) { - GenerateOneofMemberHasBits(field, vars, printer); - } + GenerateOneofMemberHasBits(field, vars, printer); } else { // Singular field. - if (!use_dependent_base_ || !IsFieldDependent(field)) { - GenerateSingularFieldHasBits(field, vars, printer); - } + GenerateSingularFieldHasBits(field, vars, printer); } - if (!use_dependent_base_ || !IsFieldDependent(field)) { - GenerateFieldClear(field, vars, printer); + if (!IsCrossFileMaybeMap(field)) { + GenerateFieldClear(field, vars, true, printer); } // Generate type-specific accessors. - field_generators_.get(field).GenerateInlineAccessorDefinitions( - printer, /* is_inline = */ true); + field_generators_.get(field).GenerateInlineAccessorDefinitions(printer); printer->Print("\n"); } @@ -792,7 +752,7 @@ GenerateFieldAccessorDefinitions(io::Printer* printer, bool is_inline) { // Generate has_$name$() and clear_has_$name$() functions for oneofs // If we aren't using a dependent base, they can be with the other functions // that are #ifdef-guarded. - GenerateOneofHasBits(printer, is_inline); + GenerateOneofHasBits(printer); } } @@ -1381,9 +1341,9 @@ GenerateDependentInlineMethods(io::Printer* printer) { } void MessageGenerator:: -GenerateInlineMethods(io::Printer* printer, bool is_inline) { +GenerateInlineMethods(io::Printer* printer) { if (IsMapEntryMessage(descriptor_)) return; - GenerateFieldAccessorDefinitions(printer, /* is_inline = */ true); + GenerateFieldAccessorDefinitions(printer); // Generate oneof_case() functions. for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { @@ -1393,11 +1353,9 @@ GenerateInlineMethods(io::Printer* printer, bool is_inline) { descriptor_->oneof_decl(i)->name(), true); vars["oneof_name"] = descriptor_->oneof_decl(i)->name(); vars["oneof_index"] = SimpleItoa(descriptor_->oneof_decl(i)->index()); - vars["inline"] = is_inline ? "inline " : ""; printer->Print( vars, - "$inline$" - "$class_name$::$camel_oneof_name$Case $class_name$::" + "inline $class_name$::$camel_oneof_name$Case $class_name$::" "$oneof_name$_case() const {\n" " return $class_name$::$camel_oneof_name$Case(" "_oneof_case_[$oneof_index$]);\n" @@ -1852,8 +1810,17 @@ GenerateClassMethods(io::Printer* printer) { // Generate non-inline field definitions. for (int i = 0; i < descriptor_->field_count(); i++) { - field_generators_.get(descriptor_->field(i)) + const FieldDescriptor* field = descriptor_->field(i); + field_generators_.get(field) .GenerateNonInlineAccessorDefinitions(printer); + if (IsCrossFileMaybeMap(field)) { + std::map<string, string> vars; + SetCommonFieldVariables(field, &vars, options_); + if (field->containing_oneof()) { + SetCommonOneofFieldVariables(field, &vars); + } + GenerateFieldClear(field, vars, false, printer); + } } // Generate field number constants. @@ -2244,16 +2211,9 @@ GenerateSharedDestructorCode(io::Printer* printer) { "classname", classname_); printer->Indent(); if (SupportsArenas(descriptor_)) { - // Do nothing when the message is allocated in an arena. printer->Print( - "::google::protobuf::Arena* arena = GetArenaNoVirtual();\n" - "GOOGLE_DCHECK(arena == NULL);\n" - "if (arena != NULL) {\n" - " return;\n" - "}\n" - "\n"); + "GOOGLE_DCHECK(GetArenaNoVirtual() == NULL);\n"); } - // Write the destructors for each field except oneof members. // optimized_order_ does not contain oneof fields. for (int i = 0; i < optimized_order_.size(); i++) { @@ -2748,11 +2708,7 @@ GenerateClear(io::Printer* printer) { break; } - if (use_dependent_base_ && IsFieldDependent(field)) { - printer->Print("clear_$name$();\n", "name", FieldName(field)); - } else { - generator.GenerateMessageClearingCode(printer); - } + generator.GenerateMessageClearingCode(printer); } // Step 3: Greedily seek runs of fields that can be cleared by @@ -2780,8 +2736,7 @@ GenerateClear(io::Printer* printer) { if (last_chunk == -1) { last_chunk = chunk; last_chunk_start = i; - } else if ((memset_run_start == -1 || unconditional_budget < 0) && - chunk != last_chunk) { + } else if (chunk != last_chunk) { // Emit the fields for this chunk so far. break; } @@ -2900,6 +2855,12 @@ flush: if (should_check_bit && // If no field presence, then always clear strings/messages as well. HasFieldPresence(descriptor_->file())) { + if (!field->options().weak() && + cached_has_bit_index != (has_bit_indices_[field->index()] / 32)) { + cached_has_bit_index = (has_bit_indices_[field->index()] / 32); + printer->Print("cached_has_bits = _has_bits_[$new_index$];\n", + "new_index", SimpleItoa(cached_has_bit_index)); + } if (!MaybeGenerateOptionalFieldCondition(printer, field, cached_has_bit_index)) { printer->Print( diff --git a/src/google/protobuf/compiler/cpp/cpp_message.h b/src/google/protobuf/compiler/cpp/cpp_message.h index cf64f483..0387f0ca 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.h +++ b/src/google/protobuf/compiler/cpp/cpp_message.h @@ -85,7 +85,7 @@ class MessageGenerator { // Generate definitions of inline methods (placed at the end of the header // file). - void GenerateInlineMethods(io::Printer* printer, bool is_inline); + void GenerateInlineMethods(io::Printer* printer); // Dependent methods are always inline. void GenerateDependentInlineMethods(io::Printer* printer); @@ -112,7 +112,7 @@ class MessageGenerator { void GenerateDependentFieldAccessorDeclarations(io::Printer* printer); void GenerateFieldAccessorDeclarations(io::Printer* printer); void GenerateDependentFieldAccessorDefinitions(io::Printer* printer); - void GenerateFieldAccessorDefinitions(io::Printer* printer, bool is_inline); + void GenerateFieldAccessorDefinitions(io::Printer* printer); // Generate the table-driven parsing array. Returns the number of entries // generated. @@ -189,7 +189,7 @@ class MessageGenerator { std::map<string, string> vars, io::Printer* printer); // Generates has_foo() functions and variables for oneof field has-bits. - void GenerateOneofHasBits(io::Printer* printer, bool is_inline); + void GenerateOneofHasBits(io::Printer* printer); // Generates has_foo_bar() functions for oneof members. void GenerateOneofMemberHasBits(const FieldDescriptor* field, const std::map<string, string>& vars, @@ -197,6 +197,7 @@ class MessageGenerator { // Generates the clear_foo() method for a field. void GenerateFieldClear(const FieldDescriptor* field, const std::map<string, string>& vars, + bool is_inline, io::Printer* printer); void GenerateConstructorBody(io::Printer* printer, diff --git a/src/google/protobuf/compiler/cpp/cpp_message_field.cc b/src/google/protobuf/compiler/cpp/cpp_message_field.cc index 5888f51a..fe60a283 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message_field.cc @@ -75,7 +75,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor, SetCommonFieldVariables(descriptor, variables, options); (*variables)["type"] = FieldMessageTypeName(descriptor); (*variables)["casted_member"] = - StaticCast((*variables)["type"] + "*", (*variables)["name"] + "_", + ReinterpretCast((*variables)["type"] + "*", (*variables)["name"] + "_", IsImplicitWeakField(descriptor, options)); (*variables)["type_default_instance"] = DefaultInstanceName(descriptor->message_type()); @@ -131,54 +131,21 @@ GeneratePrivateMembers(io::Printer* printer) const { } void MessageFieldGenerator:: -GenerateGetterDeclaration(io::Printer* printer) const { - printer->Print(variables_, - "$deprecated_attr$const $type$& $name$() const;\n"); - printer->Annotate("name", descriptor_); -} - -void MessageFieldGenerator:: GenerateDependentAccessorDeclarations(io::Printer* printer) const { if (!dependent_field_) { return; } - // Arena manipulation code is out-of-line in the derived message class. The - // one exception is unsafe_arena_release_; this method has to be inline so - // that when the implicit weak field optimization is enabled, the method does - // not introduce a strong dependency on the submessage type unless the - // accessor actually gets called somewhere. printer->Print(variables_, "$deprecated_attr$$type$* ${$mutable_$name$$}$();\n"); printer->Annotate("{", "}", descriptor_); - printer->Print(variables_, "$deprecated_attr$$type$* $release_name$();\n"); - printer->Annotate("release_name", descriptor_); - printer->Print(variables_, - "$deprecated_attr$void ${$set_allocated_$name$$}$" - "($type$* $name$);\n"); - printer->Annotate("{", "}", descriptor_); - if (SupportsArenas(descriptor_)) { - printer->Print( - variables_, - "$deprecated_attr$$type$* ${$unsafe_arena_release_$name$$}$();\n"); - printer->Annotate("{", "}", descriptor_); - } } void MessageFieldGenerator:: GenerateAccessorDeclarations(io::Printer* printer) const { - if (SupportsArenas(descriptor_)) { + if (SupportsArenas(descriptor_) && !implicit_weak_field_) { printer->Print(variables_, - "private:\n"); - if (!implicit_weak_field_) { - printer->Print(variables_, "void _slow_mutable_$name$();\n"); - } - if (SupportsArenas(descriptor_->message_type())) { - printer->Print(variables_, - "void _slow_set_allocated_$name$(\n" - " ::google::protobuf::Arena* message_arena, $type$** $name$);\n"); - } - printer->Print(variables_, - "$type$* _slow_$release_name$();\n" + "private:\n" + "void _slow_mutable_$name$();\n" "public:\n"); } if (implicit_weak_field_) { @@ -191,30 +158,30 @@ GenerateAccessorDeclarations(io::Printer* printer) const { "google::protobuf::MessageLite* _internal_mutable_$name$();\n" "public:\n"); } - GenerateGetterDeclaration(printer); + printer->Print(variables_, + "$deprecated_attr$const $type$& $name$() const;\n"); + printer->Annotate("name", descriptor_); + printer->Print(variables_, "$deprecated_attr$$type$* $release_name$();\n"); + printer->Annotate("release_name", descriptor_); if (!dependent_field_) { printer->Print(variables_, "$deprecated_attr$$type$* ${$mutable_$name$$}$();\n"); printer->Annotate("{", "}", descriptor_); - printer->Print(variables_, "$deprecated_attr$$type$* $release_name$();\n"); - printer->Annotate("release_name", descriptor_); - printer->Print(variables_, - "$deprecated_attr$void ${$set_allocated_$name$$}$" - "($type$* $name$);\n"); - printer->Annotate("{", "}", descriptor_); - if (SupportsArenas(descriptor_)) { - printer->Print( - variables_, - "$deprecated_attr$$type$* ${$unsafe_arena_release_$name$$}$();\n"); - printer->Annotate("{", "}", descriptor_); - } } + printer->Print(variables_, + "$deprecated_attr$void ${$set_allocated_$name$$}$" + "($type$* $name$);\n"); + printer->Annotate("{", "}", descriptor_); if (SupportsArenas(descriptor_)) { printer->Print(variables_, "$deprecated_attr$void " "${$unsafe_arena_set_allocated_$name$$}$(\n" " $type$* $name$);\n"); printer->Annotate("{", "}", descriptor_); + printer->Print( + variables_, + "$deprecated_attr$$type$* ${$unsafe_arena_release_$name$$}$();\n"); + printer->Annotate("{", "}", descriptor_); } } @@ -264,56 +231,8 @@ void MessageFieldGenerator::GenerateNonInlineAccessorDefinitions( } } printer->Print(variables_, - "}\n" - "$type$* $classname$::_slow_$release_name$() {\n" - " if ($name$_ == NULL) {\n" - " return NULL;\n" - " } else {\n"); - if (implicit_weak_field_) { - printer->Print(variables_, - " google::protobuf::MessageLite* temp = $name$_->New();\n" - " temp->CheckTypeAndMergeFrom(*$name$_);\n"); - } else { - printer->Print(variables_, - " $type$* temp = new $type$(*$name$_);\n"); - } - printer->Print(variables_, " $name$_ = NULL;\n"); - printer->Print( - " return $result$;\n", "result", - StaticCast(variables_.at("type") + "*", "temp", implicit_weak_field_)); - printer->Print(variables_, - " }\n" "}\n"); - if (SupportsArenas(descriptor_->message_type())) { - // NOTE: the same logic is mirrored in weak_message_field.cc. Any - // arena-related semantics changes should be made in both places. - printer->Print(variables_, - "void $classname$::_slow_set_allocated_$name$(\n" - " ::google::protobuf::Arena* message_arena, $type$** $name$) {\n" - " if (message_arena != NULL && \n" - " ::google::protobuf::Arena::GetArena(*$name$) == NULL) {\n" - " message_arena->Own(*$name$);\n" - " } else if (message_arena !=\n" - " ::google::protobuf::Arena::GetArena(*$name$)) {\n"); - if (implicit_weak_field_) { - printer->Print(variables_, - " google::protobuf::MessageLite* new_$name$ =\n" - " reinterpret_cast<const google::protobuf::MessageLite*>(\n" - " &$type_default_instance$)->New(GetArenaNoVirtual());\n" - " new_$name$->CheckTypeAndMergeFrom(**$name$);\n" - " *$name$ = static_cast< $type$* >(new_$name$);\n"); - } else { - printer->Print(variables_, - " $type$* new_$name$ =\n" - " ::google::protobuf::Arena::CreateMessage< $type$ >(\n" - " message_arena);\n" - " new_$name$->CopyFrom(**$name$);\n" - " *$name$ = new_$name$;\n"); - } - printer->Print(variables_, - " }\n" - "}\n"); - } + printer->Print(variables_, "void $classname$::unsafe_arena_set_allocated_$name$(\n" " $type$* $name$) {\n" @@ -385,13 +304,11 @@ GenerateDependentInlineAccessorDefinitions(io::Printer* printer) const { " $dependent_typename$*& $name$_ = $casted_reference$;\n" " if ($name$_ == NULL) {\n"); if (implicit_weak_field_) { - if (SupportsArenas(descriptor_->message_type())) { - printer->Print(variables, - " $name$_ = reinterpret_cast<$dependent_typename$*>(\n" - " reinterpret_cast<const google::protobuf::MessageLite*>(\n" - " &$type_default_instance$)->New(\n" - " $this_message$GetArenaNoVirtual()));\n"); - } + printer->Print(variables, + " $name$_ = reinterpret_cast<$dependent_typename$*>(\n" + " reinterpret_cast<const google::protobuf::MessageLite*>(\n" + " &$type_default_instance$)->New(\n" + " $this_message$GetArenaNoVirtual()));\n"); } else { printer->Print(variables, " $this_message$_slow_mutable_$name$();\n"); @@ -400,72 +317,6 @@ GenerateDependentInlineAccessorDefinitions(io::Printer* printer) const { " }\n" " // @@protoc_insertion_point(field_mutable:$full_name$)\n" " return $name$_;\n" - "}\n" - "template <class T>\n" - "inline $type$* $dependent_classname$::$release_name$() {\n" - " // @@protoc_insertion_point(field_release:$full_name$)\n"); - if (implicit_weak_field_) { - printer->Print(variables, " $type_reference_function$();\n"); - } - printer->Print(variables, - " $dependent_typename$*& $name$_ = $casted_reference$;\n" - " $clear_hasbit$\n" - " if ($this_message$GetArenaNoVirtual() != NULL) {\n" - " return $this_message$_slow_$release_name$();\n" - " } else {\n" - " $dependent_typename$* temp = $name$_;\n" - " $name$_ = NULL;\n" - " return temp;\n" - " }\n" - "}\n" - "template <class T>\n" - "inline void $dependent_classname$::" - "set_allocated_$name$($type$* $name$) {\n" - " ::google::protobuf::Arena* message_arena = $this_message$GetArenaNoVirtual();\n" - " $dependent_typename$*& $name$_ = $casted_reference$;\n" - " if (message_arena == NULL) {\n" - " delete $name$_;\n" - " }\n" - " if ($name$ != NULL) {\n"); - if (SupportsArenas(descriptor_->message_type())) { - // If we're on an arena and the incoming message is not, simply Own() it - // rather than copy to the arena -- either way we need a heap dealloc, - // so we might as well defer it. Otherwise, if incoming message is on a - // different ownership domain (specific arena, or the heap) than we are, - // copy to our arena (or heap, as the case may be). - printer->Print(variables, - " $this_message$_slow_set_allocated_$name$(message_arena, " - "&$name$);\n"); - } else { - printer->Print(variables, - " if (message_arena != NULL) {\n" - " message_arena->Own($name$);\n" - " }\n"); - } - printer->Print(variables, - " }\n" - " $name$_ = $name$;\n" - " if ($name$) {\n" - " $set_hasbit$\n" - " } else {\n" - " $clear_hasbit$\n" - " }\n" - // TODO(dlj): move insertion points to message class. - " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" - "}\n" - "template <class T>\n" - "inline $type$* $dependent_classname$::unsafe_arena_release_$name$() {\n" - " // @@protoc_insertion_point(" - "field_unsafe_arena_release:$full_name$)\n"); - if (implicit_weak_field_) { - printer->Print(variables, " $type_reference_function$();\n"); - } - printer->Print(variables, - " $clear_hasbit$\n" - " $dependent_typename$*& $name$_ = $casted_reference$;\n" - " $dependent_typename$* temp = $name$_;\n" - " $name$_ = NULL;\n" - " return temp;\n" "}\n"); } else { printer->Print(variables, @@ -478,58 +329,18 @@ GenerateDependentInlineAccessorDefinitions(io::Printer* printer) const { " }\n" " // @@protoc_insertion_point(field_mutable:$full_name$)\n" " return $name$_;\n" - "}\n" - "template <class T>\n" - "inline $type$* $dependent_classname$::$release_name$() {\n" - " // @@protoc_insertion_point(field_release:$full_name$)\n"); - if (implicit_weak_field_) { - printer->Print(variables, " $type_reference_function$();\n"); - } - printer->Print(variables, - " $clear_hasbit$\n" - " $dependent_typename$*& $name$_ = $casted_reference$;\n" - " $dependent_typename$* temp = $name$_;\n" - " $name$_ = NULL;\n" - " return temp;\n" - "}\n" - "template <class T>\n" - "inline void $dependent_classname$::" - "set_allocated_$name$($type$* $name$) {\n" - " $dependent_typename$*& $name$_ = $casted_reference$;\n" - " delete $name$_;\n"); - - if (SupportsArenas(descriptor_->message_type())) { - printer->Print(variables, - " if ($name$ != NULL && static_cast< $dependent_typename$* >($name$)" - "->GetArena() != NULL) {\n" - " $dependent_typename$* new_$name$ = new $dependent_typename$;\n" - " new_$name$->CopyFrom(*$name$);\n" - " $name$ = new_$name$;\n" - " }\n"); - } - - printer->Print(variables, - " $name$_ = $name$;\n" - " if ($name$) {\n" - " $set_hasbit$\n" - " } else {\n" - " $clear_hasbit$\n" - " }\n" - " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" "}\n"); } } void MessageFieldGenerator:: -GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const { +GenerateInlineAccessorDefinitions(io::Printer* printer) const { std::map<string, string> variables(variables_); - variables["inline"] = is_inline ? "inline " : ""; variables["const_member"] = ReinterpretCast( "const " + variables["type"] + "*", variables["name"] + "_", implicit_weak_field_); printer->Print(variables, - "$inline$const $type$& $classname$::$name$() const {\n"); + "inline const $type$& $classname$::$name$() const {\n"); if (implicit_weak_field_) { printer->Print(variables, " $type_reference_function$();\n"); } @@ -540,71 +351,29 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " &$type_default_instance$);\n" "}\n"); - if (dependent_field_) return; - + printer->Print(variables, + "inline $type$* $classname$::$release_name$() {\n" + " // @@protoc_insertion_point(field_release:$full_name$)\n"); + if (implicit_weak_field_) { + printer->Print(variables, " $type_reference_function$();\n"); + } + printer->Print(variables, + " $clear_hasbit$\n" + " $type$* temp = $casted_member$;\n"); if (SupportsArenas(descriptor_)) { printer->Print(variables, - "$inline$" - "$type$* $classname$::mutable_$name$() {\n" - " $set_hasbit$\n" - " if ($name$_ == NULL) {\n"); - if (implicit_weak_field_) { - printer->Print(variables, - " _internal_mutable_$name$();\n"); - } else { - printer->Print(variables, - " _slow_mutable_$name$();\n"); - } - printer->Print(variables, - " }\n" - " // @@protoc_insertion_point(field_mutable:$full_name$)\n" - " return $casted_member$;\n" - "}\n" - "$inline$" - "$type$* $classname$::$release_name$() {\n" - " // @@protoc_insertion_point(field_release:$full_name$)\n" - " $clear_hasbit$\n" " if (GetArenaNoVirtual() != NULL) {\n" - " return _slow_$release_name$();\n" - " } else {\n" - " $type$* temp = $casted_member$;\n" - " $name$_ = NULL;\n" - " return temp;\n" - " }\n" - "}\n" - "$inline$ " - "void $classname$::set_allocated_$name$($type$* $name$) {\n" - " ::google::protobuf::Arena* message_arena = GetArenaNoVirtual();\n" - " if (message_arena == NULL) {\n" - " delete $name$_;\n" - " }\n" - " if ($name$ != NULL) {\n"); - if (SupportsArenas(descriptor_->message_type())) { - // If we're on an arena and the incoming message is not, simply Own() it - // rather than copy to the arena -- either way we need a heap dealloc, - // so we might as well defer it. Otherwise, if incoming message is on a - // different ownership domain (specific arena, or the heap) than we are, - // copy to our arena (or heap, as the case may be). - printer->Print(variables, - " _slow_set_allocated_$name$(message_arena, &$name$);\n"); - } else { - printer->Print(variables, - " if (message_arena != NULL) {\n" - " message_arena->Own($name$);\n" - " }\n"); - } + " temp = ::google::protobuf::internal::DuplicateIfNonNull(temp, NULL);\n" + " }\n"); + } + printer->Print(variables, + " $name$_ = NULL;\n" + " return temp;\n" + "}\n"); + + if (SupportsArenas(descriptor_)) { printer->Print(variables, - " }\n" - " $name$_ = $name$;\n" - " if ($name$) {\n" - " $set_hasbit$\n" - " } else {\n" - " $clear_hasbit$\n" - " }\n" - " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" - "}\n" - "$inline$" - "$type$* $classname$::unsafe_arena_release_$name$() {\n" + "inline $type$* $classname$::unsafe_arena_release_$name$() {\n" " // @@protoc_insertion_point(" "field_unsafe_arena_release:$full_name$)\n"); if (implicit_weak_field_) { @@ -616,68 +385,106 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " $name$_ = NULL;\n" " return temp;\n" "}\n"); - } else { - printer->Print(variables, - "$inline$" - "$type$* $classname$::mutable_$name$() {\n" - " $set_hasbit$\n" - " if ($name$_ == NULL) {\n" - " $name$_ = new $type$;\n" - " }\n" - " // @@protoc_insertion_point(field_mutable:$full_name$)\n" - " return $casted_member$;\n" - "}\n" - "$inline$" - "$type$* $classname$::$release_name$() {\n" - " // @@protoc_insertion_point(field_release:$full_name$)\n" - " $clear_hasbit$\n" - " $type$* temp = $casted_member$;\n" - " $name$_ = NULL;\n" - " return temp;\n" - "}\n" - "$inline$" - "void $classname$::set_allocated_$name$($type$* $name$) {\n" - " delete $name$_;\n"); + } - if (SupportsArenas(descriptor_->message_type())) { + if (!dependent_field_) { + if (SupportsArenas(descriptor_)) { printer->Print(variables, - " if ($name$ != NULL && $name$->GetArena() != NULL) {\n" - " $type$* new_$name$ = new $type$;\n" - " new_$name$->CopyFrom(*$name$);\n" - " $name$ = new_$name$;\n" - " }\n"); + "inline $type$* $classname$::mutable_$name$() {\n" + " $set_hasbit$\n" + " if ($name$_ == NULL) {\n"); + if (implicit_weak_field_) { + printer->Print(variables, + " _internal_mutable_$name$();\n"); + } else { + printer->Print(variables, + " _slow_mutable_$name$();\n"); + } + printer->Print(variables, + " }\n" + " // @@protoc_insertion_point(field_mutable:$full_name$)\n" + " return $casted_member$;\n" + "}\n"); + } else { + printer->Print(variables, + "inline $type$* $classname$::mutable_$name$() {\n" + " $set_hasbit$\n" + " if ($name$_ == NULL) {\n" + " $name$_ = new $type$;\n" + " }\n" + " // @@protoc_insertion_point(field_mutable:$full_name$)\n" + " return $casted_member$;\n" + "}\n"); } + } + + // We handle the most common case inline, and delegate less common cases to + // the slow fallback function. + printer->Print(variables, + "inline void $classname$::set_allocated_$name$($type$* $name$) {\n" + " ::google::protobuf::Arena* message_arena = GetArenaNoVirtual();\n"); + printer->Print(variables, + " if (message_arena == NULL) {\n"); + if (IsCrossFileMessage(descriptor_)) { printer->Print(variables, - " $name$_ = $name$;\n" - " if ($name$) {\n" - " $set_hasbit$\n" - " } else {\n" - " $clear_hasbit$\n" - " }\n" - " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" - "}\n"); + " delete reinterpret_cast< ::google::protobuf::MessageLite*>($name$_);\n"); + } else { + printer->Print(variables, + " delete $name$_;\n"); + } + printer->Print(variables, + " }\n" + " if ($name$) {\n"); + if (SupportsArenas(descriptor_->message_type()) && + IsCrossFileMessage(descriptor_)) { + // We have to read the arena through the virtual method, because the type + // isn't defined in this file. + printer->Print(variables, + " ::google::protobuf::Arena* submessage_arena =\n" + " reinterpret_cast< ::google::protobuf::MessageLite*>($name$)->GetArena();\n"); + } else if (!SupportsArenas(descriptor_->message_type())) { + printer->Print(variables, + " ::google::protobuf::Arena* submessage_arena = NULL;\n"); + } else { + printer->Print(variables, + " ::google::protobuf::Arena* submessage_arena =\n" + " ::google::protobuf::Arena::GetArena($name$);\n"); } + printer->Print(variables, + " if (message_arena != submessage_arena) {\n" + " $name$ = ::google::protobuf::internal::GetOwnedMessage(\n" + " message_arena, $name$, submessage_arena);\n" + " }\n" + " $set_hasbit$\n" + " } else {\n" + " $clear_hasbit$\n" + " }\n"); + if (implicit_weak_field_) { + printer->Print(variables, + " $name$_ = reinterpret_cast<MessageLite*>($name$);\n"); + } else { + printer->Print(variables, + " $name$_ = $name$;\n"); + } + printer->Print(variables, + " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" + "}\n"); } void MessageFieldGenerator:: GenerateClearingCode(io::Printer* printer) const { - std::map<string, string> variables(variables_); - variables["this_message"] = dependent_field_ ? DependentBaseDownCast() : ""; if (!HasFieldPresence(descriptor_->file())) { // If we don't have has-bits, message presence is indicated only by ptr != // NULL. Thus on clear, we need to delete the object. - printer->Print(variables, - "if ($this_message$GetArenaNoVirtual() == NULL && " - "$this_message$$name$_ != NULL) delete $this_message$$name$_;\n" - "$this_message$$name$_ = NULL;\n"); - } else if (implicit_weak_field_) { - printer->Print(variables, - "if ($this_message$$name$_ != NULL) $this_message$$name$_->Clear();\n"); + printer->Print(variables_, + "if (GetArenaNoVirtual() == NULL && $name$_ != NULL) {\n" + " delete $name$_;\n" + "}\n" + "$name$_ = NULL;\n"); } else { - printer->Print(variables, - "if ($this_message$$name$_ != NULL) $this_message$$name$_->" - "$dependent_type$::Clear();\n"); + printer->Print(variables_, + "if ($name$_ != NULL) $name$_->Clear();\n"); } } @@ -691,14 +498,10 @@ GenerateMessageClearingCode(io::Printer* printer) const { " delete $name$_;\n" "}\n" "$name$_ = NULL;\n"); - } else if (implicit_weak_field_) { - printer->Print(variables_, - "GOOGLE_DCHECK($name$_ != NULL);\n" - "$name$_->Clear();\n"); } else { printer->Print(variables_, "GOOGLE_DCHECK($name$_ != NULL);\n" - "$name$_->$type$::Clear();\n"); + "$name$_->Clear();\n"); } } @@ -775,11 +578,11 @@ GenerateMergeFromCodedStream(io::Printer* printer) const { " input, _internal_mutable_$name$()));\n"); } else if (descriptor_->type() == FieldDescriptor::TYPE_MESSAGE) { printer->Print(variables_, - "DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(\n" + "DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(\n" " input, mutable_$name$()));\n"); } else { printer->Print(variables_, - "DO_(::google::protobuf::internal::WireFormatLite::ReadGroupNoVirtual(\n" + "DO_(::google::protobuf::internal::WireFormatLite::ReadGroup(\n" " $number$, input, mutable_$name$()));\n"); } } @@ -795,17 +598,15 @@ void MessageFieldGenerator:: GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { printer->Print(variables_, "target = ::google::protobuf::internal::WireFormatLite::\n" - " InternalWrite$declared_type$NoVirtualToArray(\n" + " InternalWrite$declared_type$ToArray(\n" " $number$, *$non_null_ptr_to_name$, deterministic, target);\n"); } void MessageFieldGenerator:: GenerateByteSize(io::Printer* printer) const { - std::map<string, string> variables = variables_; - variables["no_virtual"] = (implicit_weak_field_ ? "" : "NoVirtual"); - printer->Print(variables, + printer->Print(variables_, "total_size += $tag_size$ +\n" - " ::google::protobuf::internal::WireFormatLite::$declared_type$Size$no_virtual$(\n" + " ::google::protobuf::internal::WireFormatLite::$declared_type$Size(\n" " *$non_null_ptr_to_name$);\n"); } @@ -821,29 +622,38 @@ MessageOneofFieldGenerator(const FieldDescriptor* descriptor, MessageOneofFieldGenerator::~MessageOneofFieldGenerator() {} - -void MessageOneofFieldGenerator:: -GenerateDependentAccessorDeclarations(io::Printer* printer) const { - // Oneof field getters must be dependent as they call default_instance(). - // Otherwise, the logic is the same as MessageFields. - if (!dependent_field_) { - return; - } +void MessageOneofFieldGenerator::GenerateNonInlineAccessorDefinitions( + io::Printer* printer) const { printer->Print(variables_, - "$deprecated_attr$const $type$& $name$() const;\n"); - MessageFieldGenerator::GenerateDependentAccessorDeclarations(printer); -} - -void MessageOneofFieldGenerator:: -GenerateGetterDeclaration(io::Printer* printer) const { - // Oneof field getters must be dependent as they call default_instance(). - // Unlike MessageField, this means there is no (non-dependent) getter to - // generate. - if (dependent_field_) { - return; + "void $classname$::set_allocated_$name$($type$* $name$) {\n" + " ::google::protobuf::Arena* message_arena = GetArenaNoVirtual();\n" + " clear_$oneof_name$();\n" + " if ($name$) {\n"); + if (SupportsArenas(descriptor_->message_type()) && + descriptor_->file() != descriptor_->message_type()->file()) { + // We have to read the arena through the virtual method, because the type + // isn't defined in this file. + printer->Print(variables_, + " ::google::protobuf::Arena* submessage_arena =\n" + " reinterpret_cast< ::google::protobuf::MessageLite*>($name$)->GetArena();\n"); + } else if (!SupportsArenas(descriptor_->message_type())) { + printer->Print(variables_, + " ::google::protobuf::Arena* submessage_arena = NULL;\n"); + } else { + printer->Print(variables_, + " ::google::protobuf::Arena* submessage_arena =\n" + " ::google::protobuf::Arena::GetArena($name$);\n"); } printer->Print(variables_, - "$deprecated_attr$const $type$& $name$() const;\n"); + " if (message_arena != submessage_arena) {\n" + " $name$ = ::google::protobuf::internal::GetOwnedMessage(\n" + " message_arena, $name$, submessage_arena);\n" + " }\n" + " set_has_$name$();\n" + " $oneof_prefix$$name$_ = $name$;\n" + " }\n" + " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" + "}\n"); } void MessageOneofFieldGenerator:: @@ -854,7 +664,6 @@ GenerateDependentInlineAccessorDefinitions(io::Printer* printer) const { return; } std::map<string, string> variables(variables_); - variables["inline"] = "inline "; variables["dependent_classname"] = DependentBaseClassTemplateName(descriptor_->containing_type()) + "<T>"; variables["this_message"] = "reinterpret_cast<T*>(this)->"; @@ -868,13 +677,9 @@ GenerateDependentInlineAccessorDefinitions(io::Printer* printer) const { } void MessageOneofFieldGenerator:: -GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const { - if (dependent_base_) { - return; - } +GenerateInlineAccessorDefinitions(io::Printer* printer) const { + std::map<string, string> variables(variables_); - variables["inline"] = is_inline ? "inline " : ""; variables["dependent_classname"] = variables["classname"]; variables["this_message"] = ""; variables["this_const_message"] = ""; @@ -882,118 +687,50 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, variables["field_member"] = variables["oneof_prefix"] + variables["name"] + "_"; variables["dependent_type"] = variables["type"]; - InternalGenerateInlineAccessorDefinitions(variables, printer); -} -void MessageOneofFieldGenerator::InternalGenerateInlineAccessorDefinitions( - const std::map<string, string>& variables, io::Printer* printer) const { printer->Print(variables, - "$tmpl$" - "$inline$ " - "const $type$& $dependent_classname$::$name$() const {\n" + "inline $type$* $classname$::$release_name$() {\n" + " // @@protoc_insertion_point(field_release:$full_name$)\n" + " if ($this_message$has_$name$()) {\n" + " $this_message$clear_has_$oneof_name$();\n" + " $type$* temp = $field_member$;\n"); + if (SupportsArenas(descriptor_)) { + printer->Print(variables, + " if ($this_message$GetArenaNoVirtual() != NULL) {\n" + " temp = ::google::protobuf::internal::DuplicateIfNonNull(temp, NULL);\n" + " }\n"); + } + printer->Print(variables, + " $field_member$ = NULL;\n" + " return temp;\n" + " } else {\n" + " return NULL;\n" + " }\n" + "}\n"); + + printer->Print(variables, + "inline const $type$& $classname$::$name$() const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " return $this_const_message$has_$name$()\n" " ? *$this_const_message$$oneof_prefix$$name$_\n" - " : $dependent_type$::default_instance();\n" + " : *reinterpret_cast< $type$*>(&$type_default_instance$);\n" "}\n"); if (SupportsArenas(descriptor_)) { printer->Print(variables, - "$tmpl$" - "$inline$" - "$type$* $dependent_classname$::mutable_$name$() {\n" - " if (!$this_message$has_$name$()) {\n" - " $this_message$clear_$oneof_name$();\n" - " $this_message$set_has_$name$();\n"); - if (SupportsArenas(descriptor_->message_type())) { - printer->Print(variables, - " $field_member$ = \n" - " ::google::protobuf::Arena::CreateMessage< $dependent_typename$ >(\n" - " $this_message$GetArenaNoVirtual());\n"); - } else { - printer->Print(variables, - " $this_message$$oneof_prefix$$name$_ = \n" - " ::google::protobuf::Arena::Create< $dependent_typename$ >(\n" - " $this_message$GetArenaNoVirtual());\n"); - } - printer->Print(variables, - " }\n" - " // @@protoc_insertion_point(field_mutable:$full_name$)\n" - " return $field_member$;\n" - "}\n" - "$tmpl$" - "$inline$" - "$type$* $dependent_classname$::$release_name$() {\n" - " // @@protoc_insertion_point(field_release:$full_name$)\n" - " if ($this_message$has_$name$()) {\n" - " $this_message$clear_has_$oneof_name$();\n" - " if ($this_message$GetArenaNoVirtual() != NULL) {\n" - // N.B.: safe to use the underlying field pointer here because we are sure - // that it is non-NULL (because has_$name$() returned true). - " $dependent_typename$* temp = " - "new $dependent_typename$(*$field_member$);\n" - " $field_member$ = NULL;\n" - " return temp;\n" - " } else {\n" - " $dependent_typename$* temp = $field_member$;\n" - " $field_member$ = NULL;\n" - " return temp;\n" - " }\n" - " } else {\n" - " return NULL;\n" - " }\n" - "}\n" - "$tmpl$" - "$inline$" - "void $dependent_classname$::" - "set_allocated_$name$($type$* $name$) {\n" - " $this_message$clear_$oneof_name$();\n" - " if ($name$) {\n"); - - if (SupportsArenas(descriptor_->message_type())) { - printer->Print(variables, - // If incoming message is on the heap and we are on an arena, just Own() - // it (see above). If it's on a different arena than we are or one of us - // is on the heap, we make a copy to our arena/heap. - " if ($this_message$GetArenaNoVirtual() != NULL &&\n" - " ::google::protobuf::Arena::GetArena($name$) == NULL) {\n" - " $this_message$GetArenaNoVirtual()->Own($name$);\n" - " } else if ($this_message$GetArenaNoVirtual() !=\n" - " ::google::protobuf::Arena::GetArena($name$)) {\n" - " $dependent_typename$* new_$name$ = \n" - " ::google::protobuf::Arena::CreateMessage< $dependent_typename$ >(\n" - " $this_message$GetArenaNoVirtual());\n" - " new_$name$->CopyFrom(*$name$);\n" - " $name$ = new_$name$;\n" - " }\n"); - } else { - printer->Print(variables, - " if ($this_message$GetArenaNoVirtual() != NULL) {\n" - " $this_message$GetArenaNoVirtual()->Own($name$);\n" - " }\n"); - } - - printer->Print(variables, - " $this_message$set_has_$name$();\n" - " $field_member$ = $name$;\n" - " }\n" - " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" - "}\n" - "$tmpl$" - "$inline$" - "$type$* $dependent_classname$::unsafe_arena_release_$name$() {\n" + "inline $type$* $dependent_classname$::unsafe_arena_release_$name$() {\n" " // @@protoc_insertion_point(field_unsafe_arena_release" ":$full_name$)\n" " if ($this_message$has_$name$()) {\n" " $this_message$clear_has_$oneof_name$();\n" - " $dependent_typename$* temp = $this_message$$oneof_prefix$$name$_;\n" + " $type$* temp = $this_message$$oneof_prefix$$name$_;\n" " $this_message$$oneof_prefix$$name$_ = NULL;\n" " return temp;\n" " } else {\n" " return NULL;\n" " }\n" "}\n" - "$inline$ void $classname$::unsafe_arena_set_allocated_$name$" + "inline void $classname$::unsafe_arena_set_allocated_$name$" "($type$* $name$) {\n" // We rely on the oneof clear method to free the earlier contents of this // oneof. We can directly use the pointer we're given to set the new @@ -1006,68 +743,65 @@ void MessageOneofFieldGenerator::InternalGenerateInlineAccessorDefinitions( " // @@protoc_insertion_point(field_unsafe_arena_set_allocated:" "$full_name$)\n" "}\n"); - } else { + } + + if (dependent_base_) { + return; + } + + InternalGenerateInlineAccessorDefinitions(variables, printer); +} + +void MessageOneofFieldGenerator::InternalGenerateInlineAccessorDefinitions( + const std::map<string, string>& variables, io::Printer* printer) const { + if (SupportsArenas(descriptor_)) { printer->Print(variables, "$tmpl$" - "$inline$" - "$type$* $dependent_classname$::mutable_$name$() {\n" + "inline $type$* $dependent_classname$::mutable_$name$() {\n" " if (!$this_message$has_$name$()) {\n" " $this_message$clear_$oneof_name$();\n" - " $this_message$set_has_$name$();\n" - " $field_member$ = new $dependent_typename$;\n" - " }\n" - " // @@protoc_insertion_point(field_mutable:$full_name$)\n" - " return $field_member$;\n" - "}\n" - "$tmpl$" - "$inline$" - "$type$* $dependent_classname$::$release_name$() {\n" - " // @@protoc_insertion_point(field_release:$full_name$)\n" - " if ($this_message$has_$name$()) {\n" - " $this_message$clear_has_$oneof_name$();\n" - " $dependent_typename$* temp = $field_member$;\n" - " $field_member$ = NULL;\n" - " return temp;\n" - " } else {\n" - " return NULL;\n" - " }\n" - "}\n" - "$tmpl$" - "$inline$" - "void $dependent_classname$::" - "set_allocated_$name$($type$* $name$) {\n" - " $this_message$clear_$oneof_name$();\n" - " if ($name$) {\n"); + " $this_message$set_has_$name$();\n"); if (SupportsArenas(descriptor_->message_type())) { printer->Print(variables, - " if (static_cast< $dependent_typename$*>($name$)->" - "GetArena() != NULL) {\n" - " $dependent_typename$* new_$name$ = new $dependent_typename$;\n" - " new_$name$->CopyFrom(*$name$);\n" - " $name$ = new_$name$;\n" - " }\n"); + " $field_member$ = \n" + " ::google::protobuf::Arena::CreateMessage< $dependent_typename$ >(\n" + " $this_message$GetArenaNoVirtual());\n"); + } else { + printer->Print(variables, + " $this_message$$oneof_prefix$$name$_ = \n" + " ::google::protobuf::Arena::Create< $dependent_typename$ >(\n" + " $this_message$GetArenaNoVirtual());\n"); } printer->Print(variables, + " }\n" + " // @@protoc_insertion_point(field_mutable:$full_name$)\n" + " return $field_member$;\n" + "}\n"); + } else { + printer->Print(variables, + "$tmpl$" + "inline $type$* $dependent_classname$::mutable_$name$() {\n" + " if (!$this_message$has_$name$()) {\n" + " $this_message$clear_$oneof_name$();\n" " $this_message$set_has_$name$();\n" - " $field_member$ = $name$;\n" + " $field_member$ = new $dependent_typename$;\n" " }\n" - " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" + " // @@protoc_insertion_point(field_mutable:$full_name$)\n" + " return $field_member$;\n" "}\n"); } } void MessageOneofFieldGenerator:: GenerateClearingCode(io::Printer* printer) const { - std::map<string, string> variables(variables_); - variables["this_message"] = dependent_field_ ? DependentBaseDownCast() : ""; if (SupportsArenas(descriptor_)) { - printer->Print(variables, - "if ($this_message$GetArenaNoVirtual() == NULL) {\n" - " delete $this_message$$oneof_prefix$$name$_;\n" + printer->Print(variables_, + "if (GetArenaNoVirtual() == NULL) {\n" + " delete $oneof_prefix$$name$_;\n" "}\n"); } else { - printer->Print(variables, - "delete $this_message$$oneof_prefix$$name$_;\n"); + printer->Print(variables_, + "delete $oneof_prefix$$name$_;\n"); } } @@ -1218,48 +952,39 @@ GenerateDependentInlineAccessorDefinitions(io::Printer* printer) const { } void RepeatedMessageFieldGenerator:: -GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const { - std::map<string, string> variables(variables_); - variables["inline"] = is_inline ? "inline " : ""; - +GenerateInlineAccessorDefinitions(io::Printer* printer) const { if (!dependent_getter_) { - printer->Print(variables, - "$inline$" - "const $type$& $classname$::$name$(int index) const {\n" + printer->Print(variables_, + "inline const $type$& $classname$::$name$(int index) const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " return $name$_.$cppget$(index);\n" "}\n"); } if (!dependent_field_) { - printer->Print(variables, - "$inline$" - "$type$* $classname$::mutable_$name$(int index) {\n" + printer->Print(variables_, + "inline $type$* $classname$::mutable_$name$(int index) {\n" // TODO(dlj): move insertion points " // @@protoc_insertion_point(field_mutable:$full_name$)\n" " return $name$_.Mutable(index);\n" "}\n" - "$inline$" - "$type$* $classname$::add_$name$() {\n" + "inline $type$* $classname$::add_$name$() {\n" " // @@protoc_insertion_point(field_add:$full_name$)\n" " return $name$_.Add();\n" "}\n"); } if (!dependent_field_) { - printer->Print(variables, - "$inline$" - "::google::protobuf::RepeatedPtrField< $type$ >*\n" + printer->Print(variables_, + "inline ::google::protobuf::RepeatedPtrField< $type$ >*\n" "$classname$::mutable_$name$() {\n" " // @@protoc_insertion_point(field_mutable_list:$full_name$)\n" " return &$name$_;\n" "}\n"); } if (!dependent_getter_) { - printer->Print(variables, - "$inline$" - "const ::google::protobuf::RepeatedPtrField< $type$ >&\n" + printer->Print(variables_, + "inline const ::google::protobuf::RepeatedPtrField< $type$ >&\n" "$classname$::$name$() const {\n" " // @@protoc_insertion_point(field_list:$full_name$)\n" " return $name$_;\n" @@ -1269,9 +994,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, void RepeatedMessageFieldGenerator:: GenerateClearingCode(io::Printer* printer) const { - std::map<string, string> variables(variables_); - variables["this_message"] = dependent_field_ ? DependentBaseDownCast() : ""; - printer->Print(variables, "$this_message$$name$_.Clear();\n"); + printer->Print(variables_, "$name$_.Clear();\n"); } void RepeatedMessageFieldGenerator:: @@ -1294,13 +1017,11 @@ GenerateMergeFromCodedStream(io::Printer* printer) const { if (descriptor_->type() == FieldDescriptor::TYPE_MESSAGE) { printer->Print(variables_, "DO_(::google::protobuf::internal::WireFormatLite::" - "ReadMessageNoVirtual(\n" - " input, add_$name$()));\n"); + "ReadMessage(input, add_$name$()));\n"); } else { printer->Print(variables_, "DO_(::google::protobuf::internal::WireFormatLite::" - "ReadGroupNoVirtual(\n" - " $number$, input, add_$name$()));\n"); + "ReadGroup($number$, input, add_$name$()));\n"); } } @@ -1320,7 +1041,7 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { "for (unsigned int i = 0,\n" " n = static_cast<unsigned int>(this->$name$_size()); i < n; i++) {\n" " target = ::google::protobuf::internal::WireFormatLite::\n" - " InternalWrite$declared_type$NoVirtualToArray(\n" + " InternalWrite$declared_type$ToArray(\n" " $number$, this->$name$(static_cast<int>(i)), deterministic, target);\n" "}\n"); } @@ -1335,7 +1056,7 @@ GenerateByteSize(io::Printer* printer) const { "total_size += $tag_size$UL * count;\n" "for (unsigned int i = 0; i < count; i++) {\n" " total_size +=\n" - " ::google::protobuf::internal::WireFormatLite::$declared_type$SizeNoVirtual(\n" + " ::google::protobuf::internal::WireFormatLite::$declared_type$Size(\n" " this->$name$(static_cast<int>(i)));\n" "}\n"); printer->Outdent(); diff --git a/src/google/protobuf/compiler/cpp/cpp_message_field.h b/src/google/protobuf/compiler/cpp/cpp_message_field.h index 14698992..3be505e3 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message_field.h +++ b/src/google/protobuf/compiler/cpp/cpp_message_field.h @@ -57,8 +57,7 @@ class MessageFieldGenerator : public FieldGenerator { void GenerateDependentAccessorDeclarations(io::Printer* printer) const; void GenerateAccessorDeclarations(io::Printer* printer) const; void GenerateDependentInlineAccessorDefinitions(io::Printer* printer) const; - void GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const; + void GenerateInlineAccessorDefinitions(io::Printer* printer) const; void GenerateNonInlineAccessorDefinitions(io::Printer* printer) const; void GenerateClearingCode(io::Printer* printer) const; void GenerateMessageClearingCode(io::Printer* printer) const; @@ -73,11 +72,6 @@ class MessageFieldGenerator : public FieldGenerator { void GenerateByteSize(io::Printer* printer) const; protected: - void GenerateArenaManipulationCode(const std::map<string, string>& variables, - io::Printer* printer) const; - - virtual void GenerateGetterDeclaration(io::Printer* printer) const; - const FieldDescriptor* descriptor_; const bool dependent_field_; const bool implicit_weak_field_; @@ -94,11 +88,9 @@ class MessageOneofFieldGenerator : public MessageFieldGenerator { ~MessageOneofFieldGenerator(); // implements FieldGenerator --------------------------------------- - void GenerateDependentAccessorDeclarations(io::Printer* printer) const; void GenerateDependentInlineAccessorDefinitions(io::Printer* printer) const; - void GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const; - void GenerateNonInlineAccessorDefinitions(io::Printer* printer) const { } + void GenerateInlineAccessorDefinitions(io::Printer* printer) const; + void GenerateNonInlineAccessorDefinitions(io::Printer* printer) const; void GenerateClearingCode(io::Printer* printer) const; // MessageFieldGenerator, from which we inherit, overrides this so we need to @@ -108,9 +100,6 @@ class MessageOneofFieldGenerator : public MessageFieldGenerator { void GenerateDestructorCode(io::Printer* printer) const; void GenerateConstructorCode(io::Printer* printer) const; - protected: - void GenerateGetterDeclaration(io::Printer* printer) const; - private: void InternalGenerateInlineAccessorDefinitions( const std::map<string, string>& variables, io::Printer* printer) const; @@ -130,8 +119,7 @@ class RepeatedMessageFieldGenerator : public FieldGenerator { void GenerateDependentAccessorDeclarations(io::Printer* printer) const; void GenerateAccessorDeclarations(io::Printer* printer) const; void GenerateDependentInlineAccessorDefinitions(io::Printer* printer) const; - void GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const; + void GenerateInlineAccessorDefinitions(io::Printer* printer) const; void GenerateClearingCode(io::Printer* printer) const; void GenerateMergingCode(io::Printer* printer) const; void GenerateSwappingCode(io::Printer* printer) const; diff --git a/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc b/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc index 34a41d82..ceb2270e 100644 --- a/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc +++ b/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc @@ -132,7 +132,7 @@ class TestGenerator : public CodeGenerator { // Check field accessors for a message inside oneof{}: TryInsert("test.pb.h", "field_get:foo.Bar.oneOfMessage", context); TryInsert("test.pb.h", "field_mutable:foo.Bar.oneOfMessage", context); - TryInsert("test.pb.h", "field_set_allocated:foo.Bar.oneOfMessage", context); + TryInsert("test.pb.cc", "field_set_allocated:foo.Bar.oneOfMessage", context); // Check field accessors for an optional enum: TryInsert("test.pb.h", "field_get:foo.Bar.optEnum", context); diff --git a/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc b/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc index 67cfc405..bc2d02ea 100644 --- a/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc @@ -123,15 +123,13 @@ GenerateAccessorDeclarations(io::Printer* printer) const { } void PrimitiveFieldGenerator:: -GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { - std::map<string, string> variables(variables_); - variables["inline"] = is_inline ? "inline " : ""; - printer->Print(variables, - "$inline$$type$ $classname$::$name$() const {\n" +GenerateInlineAccessorDefinitions(io::Printer* printer) const { + printer->Print(variables_, + "inline $type$ $classname$::$name$() const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " return $name$_;\n" "}\n" - "$inline$void $classname$::set_$name$($type$ value) {\n" + "inline void $classname$::set_$name$($type$ value) {\n" " $set_hasbit$\n" " $name$_ = value;\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" @@ -212,18 +210,16 @@ PrimitiveOneofFieldGenerator(const FieldDescriptor* descriptor, PrimitiveOneofFieldGenerator::~PrimitiveOneofFieldGenerator() {} void PrimitiveOneofFieldGenerator:: -GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { - std::map<string, string> variables(variables_); - variables["inline"] = is_inline ? "inline " : ""; - printer->Print(variables, - "$inline$$type$ $classname$::$name$() const {\n" +GenerateInlineAccessorDefinitions(io::Printer* printer) const { + printer->Print(variables_, + "inline $type$ $classname$::$name$() const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " if (has_$name$()) {\n" " return $oneof_prefix$$name$_;\n" " }\n" " return $default$;\n" "}\n" - "$inline$void $classname$::set_$name$($type$ value) {\n" + "inline void $classname$::set_$name$($type$ value) {\n" " if (!has_$name$()) {\n" " clear_$oneof_name$();\n" " set_has_$name$();\n" @@ -311,28 +307,26 @@ GenerateAccessorDeclarations(io::Printer* printer) const { } void RepeatedPrimitiveFieldGenerator:: -GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { - std::map<string, string> variables(variables_); - variables["inline"] = is_inline ? "inline " : ""; - printer->Print(variables, - "$inline$$type$ $classname$::$name$(int index) const {\n" +GenerateInlineAccessorDefinitions(io::Printer* printer) const { + printer->Print(variables_, + "inline $type$ $classname$::$name$(int index) const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " return $name$_.Get(index);\n" "}\n" - "$inline$void $classname$::set_$name$(int index, $type$ value) {\n" + "inline void $classname$::set_$name$(int index, $type$ value) {\n" " $name$_.Set(index, value);\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" "}\n" - "$inline$void $classname$::add_$name$($type$ value) {\n" + "inline void $classname$::add_$name$($type$ value) {\n" " $name$_.Add(value);\n" " // @@protoc_insertion_point(field_add:$full_name$)\n" "}\n" - "$inline$const ::google::protobuf::RepeatedField< $type$ >&\n" + "inline const ::google::protobuf::RepeatedField< $type$ >&\n" "$classname$::$name$() const {\n" " // @@protoc_insertion_point(field_list:$full_name$)\n" " return $name$_;\n" "}\n" - "$inline$::google::protobuf::RepeatedField< $type$ >*\n" + "inline ::google::protobuf::RepeatedField< $type$ >*\n" "$classname$::mutable_$name$() {\n" " // @@protoc_insertion_point(field_mutable_list:$full_name$)\n" " return &$name$_;\n" diff --git a/src/google/protobuf/compiler/cpp/cpp_primitive_field.h b/src/google/protobuf/compiler/cpp/cpp_primitive_field.h index 44c9ff3e..d52228e9 100644 --- a/src/google/protobuf/compiler/cpp/cpp_primitive_field.h +++ b/src/google/protobuf/compiler/cpp/cpp_primitive_field.h @@ -53,8 +53,7 @@ class PrimitiveFieldGenerator : public FieldGenerator { // implements FieldGenerator --------------------------------------- void GeneratePrivateMembers(io::Printer* printer) const; void GenerateAccessorDeclarations(io::Printer* printer) const; - void GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const; + void GenerateInlineAccessorDefinitions(io::Printer* printer) const; void GenerateClearingCode(io::Printer* printer) const; void GenerateMergingCode(io::Printer* printer) const; void GenerateSwappingCode(io::Printer* printer) const; @@ -80,8 +79,7 @@ class PrimitiveOneofFieldGenerator : public PrimitiveFieldGenerator { ~PrimitiveOneofFieldGenerator(); // implements FieldGenerator --------------------------------------- - void GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const; + void GenerateInlineAccessorDefinitions(io::Printer* printer) const; void GenerateClearingCode(io::Printer* printer) const; void GenerateSwappingCode(io::Printer* printer) const; void GenerateConstructorCode(io::Printer* printer) const; @@ -100,8 +98,7 @@ class RepeatedPrimitiveFieldGenerator : public FieldGenerator { // implements FieldGenerator --------------------------------------- void GeneratePrivateMembers(io::Printer* printer) const; void GenerateAccessorDeclarations(io::Printer* printer) const; - void GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const; + void GenerateInlineAccessorDefinitions(io::Printer* printer) const; void GenerateClearingCode(io::Printer* printer) const; void GenerateMergingCode(io::Printer* printer) const; void GenerateSwappingCode(io::Printer* printer) const; diff --git a/src/google/protobuf/compiler/cpp/cpp_string_field.cc b/src/google/protobuf/compiler/cpp/cpp_string_field.cc index 8e675751..264f6124 100644 --- a/src/google/protobuf/compiler/cpp/cpp_string_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_string_field.cc @@ -180,16 +180,21 @@ GenerateAccessorDeclarations(io::Printer* printer) const { if (SupportsArenas(descriptor_)) { printer->Print( variables_, - "$deprecated_attr$::std::string* ${$unsafe_arena_release_$name$$}$();\n"); + "PROTOBUF_RUNTIME_DEPRECATED(\"The unsafe_arena_ accessors for\"\n" + "\" string fields are deprecated and will be removed in a\"\n" + "\" future release.\")\n" + "::std::string* ${$unsafe_arena_release_$name$$}$();\n"); printer->Annotate("{", "}", descriptor_); printer->Print( variables_, - "$deprecated_attr$void ${$unsafe_arena_set_allocated_$name$$}$(\n" + "PROTOBUF_RUNTIME_DEPRECATED(\"The unsafe_arena_ accessors for\"\n" + "\" string fields are deprecated and will be removed in a\"\n" + "\" future release.\")\n" + "void ${$unsafe_arena_set_allocated_$name$$}$(\n" " ::std::string* $name$);\n"); printer->Annotate("{", "}", descriptor_); } - if (unknown_ctype) { printer->Outdent(); printer->Print(" public:\n"); @@ -198,38 +203,35 @@ GenerateAccessorDeclarations(io::Printer* printer) const { } void StringFieldGenerator:: -GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const { - std::map<string, string> variables(variables_); - variables["inline"] = is_inline ? "inline " : ""; +GenerateInlineAccessorDefinitions(io::Printer* printer) const { if (SupportsArenas(descriptor_)) { printer->Print( - variables, - "$inline$const ::std::string& $classname$::$name$() const {\n" + variables_, + "inline const ::std::string& $classname$::$name$() const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " return $name$_.Get();\n" "}\n" - "$inline$void $classname$::set_$name$(const ::std::string& value) {\n" + "inline void $classname$::set_$name$(const ::std::string& value) {\n" " $set_hasbit$\n" " $name$_.Set$lite$($default_variable$, value, GetArenaNoVirtual());\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" "}\n" "#if LANG_CXX11\n" - "$inline$void $classname$::set_$name$(::std::string&& value) {\n" + "inline void $classname$::set_$name$(::std::string&& value) {\n" " $set_hasbit$\n" " $name$_.Set$lite$(\n" " $default_variable$, ::std::move(value), GetArenaNoVirtual());\n" " // @@protoc_insertion_point(field_set_rvalue:$full_name$)\n" "}\n" "#endif\n" - "$inline$void $classname$::set_$name$(const char* value) {\n" + "inline void $classname$::set_$name$(const char* value) {\n" " $null_check$" " $set_hasbit$\n" " $name$_.Set$lite$($default_variable$, $string_piece$(value),\n" " GetArenaNoVirtual());\n" " // @@protoc_insertion_point(field_set_char:$full_name$)\n" "}\n" - "$inline$" + "inline " "void $classname$::set_$name$(const $pointer_type$* value,\n" " size_t size) {\n" " $set_hasbit$\n" @@ -238,25 +240,17 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, "GetArenaNoVirtual());\n" " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" "}\n" - "$inline$::std::string* $classname$::mutable_$name$() {\n" + "inline ::std::string* $classname$::mutable_$name$() {\n" " $set_hasbit$\n" " // @@protoc_insertion_point(field_mutable:$full_name$)\n" " return $name$_.Mutable($default_variable$, GetArenaNoVirtual());\n" "}\n" - "$inline$::std::string* $classname$::$release_name$() {\n" + "inline ::std::string* $classname$::$release_name$() {\n" " // @@protoc_insertion_point(field_release:$full_name$)\n" " $clear_hasbit$\n" " return $name$_.Release($default_variable$, GetArenaNoVirtual());\n" "}\n" - "$inline$::std::string* $classname$::unsafe_arena_release_$name$() {\n" - " // " - "@@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n" - " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" - " $clear_hasbit$\n" - " return $name$_.UnsafeArenaRelease($default_variable$,\n" - " GetArenaNoVirtual());\n" - "}\n" - "$inline$void $classname$::set_allocated_$name$(::std::string* $name$) {\n" + "inline void $classname$::set_allocated_$name$(::std::string* $name$) {\n" " if ($name$ != NULL) {\n" " $set_hasbit$\n" " } else {\n" @@ -266,7 +260,15 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " GetArenaNoVirtual());\n" " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" "}\n" - "$inline$void $classname$::unsafe_arena_set_allocated_$name$(\n" + "inline ::std::string* $classname$::unsafe_arena_release_$name$() {\n" + " // " + "@@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n" + " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" + " $clear_hasbit$\n" + " return $name$_.UnsafeArenaRelease($default_variable$,\n" + " GetArenaNoVirtual());\n" + "}\n" + "inline void $classname$::unsafe_arena_set_allocated_$name$(\n" " ::std::string* $name$) {\n" " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" " if ($name$ != NULL) {\n" @@ -282,31 +284,31 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, } else { // No-arena case. printer->Print( - variables, - "$inline$const ::std::string& $classname$::$name$() const {\n" + variables_, + "inline const ::std::string& $classname$::$name$() const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " return $name$_.GetNoArena();\n" "}\n" - "$inline$void $classname$::set_$name$(const ::std::string& value) {\n" + "inline void $classname$::set_$name$(const ::std::string& value) {\n" " $set_hasbit$\n" " $name$_.SetNoArena($default_variable$, value);\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" "}\n" "#if LANG_CXX11\n" - "$inline$void $classname$::set_$name$(::std::string&& value) {\n" + "inline void $classname$::set_$name$(::std::string&& value) {\n" " $set_hasbit$\n" " $name$_.SetNoArena(\n" " $default_variable$, ::std::move(value));\n" " // @@protoc_insertion_point(field_set_rvalue:$full_name$)\n" "}\n" "#endif\n" - "$inline$void $classname$::set_$name$(const char* value) {\n" + "inline void $classname$::set_$name$(const char* value) {\n" " $null_check$" " $set_hasbit$\n" " $name$_.SetNoArena($default_variable$, $string_piece$(value));\n" " // @@protoc_insertion_point(field_set_char:$full_name$)\n" "}\n" - "$inline$" + "inline " "void $classname$::set_$name$(const $pointer_type$* value, " "size_t size) {\n" " $set_hasbit$\n" @@ -314,17 +316,17 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " $string_piece$(reinterpret_cast<const char*>(value), size));\n" " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" "}\n" - "$inline$::std::string* $classname$::mutable_$name$() {\n" + "inline ::std::string* $classname$::mutable_$name$() {\n" " $set_hasbit$\n" " // @@protoc_insertion_point(field_mutable:$full_name$)\n" " return $name$_.MutableNoArena($default_variable$);\n" "}\n" - "$inline$::std::string* $classname$::$release_name$() {\n" + "inline ::std::string* $classname$::$release_name$() {\n" " // @@protoc_insertion_point(field_release:$full_name$)\n" " $clear_hasbit$\n" " return $name$_.ReleaseNoArena($default_variable$);\n" "}\n" - "$inline$void $classname$::set_allocated_$name$(::std::string* $name$) {\n" + "inline void $classname$::set_allocated_$name$(::std::string* $name$) {\n" " if ($name$ != NULL) {\n" " $set_hasbit$\n" " } else {\n" @@ -470,15 +472,8 @@ GenerateCopyConstructorCode(io::Printer* printer) const { void StringFieldGenerator:: GenerateDestructorCode(io::Printer* printer) const { - if (SupportsArenas(descriptor_)) { - // The variable |arena| is defined by the enclosing code. - // See MessageGenerator::GenerateSharedDestructorCode. - printer->Print(variables_, - "$name$_.Destroy($default_variable$, arena);\n"); - } else { - printer->Print(variables_, - "$name$_.DestroyNoArena($default_variable$);\n"); - } + printer->Print(variables_, + "$name$_.DestroyNoArena($default_variable$);\n"); } void StringFieldGenerator:: @@ -557,21 +552,18 @@ StringOneofFieldGenerator(const FieldDescriptor* descriptor, StringOneofFieldGenerator::~StringOneofFieldGenerator() {} void StringOneofFieldGenerator:: -GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const { - std::map<string, string> variables(variables_); - variables["inline"] = is_inline ? "inline " : ""; +GenerateInlineAccessorDefinitions(io::Printer* printer) const { if (SupportsArenas(descriptor_)) { printer->Print( - variables, - "$inline$const ::std::string& $classname$::$name$() const {\n" + variables_, + "inline const ::std::string& $classname$::$name$() const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " if (has_$name$()) {\n" " return $oneof_prefix$$name$_.Get();\n" " }\n" " return *$default_variable$;\n" "}\n" - "$inline$void $classname$::set_$name$(const ::std::string& value) {\n" + "inline void $classname$::set_$name$(const ::std::string& value) {\n" " if (!has_$name$()) {\n" " clear_$oneof_name$();\n" " set_has_$name$();\n" @@ -582,7 +574,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " // @@protoc_insertion_point(field_set:$full_name$)\n" "}\n" "#if LANG_CXX11\n" - "$inline$void $classname$::set_$name$(::std::string&& value) {\n" + "inline void $classname$::set_$name$(::std::string&& value) {\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" " if (!has_$name$()) {\n" " clear_$oneof_name$();\n" @@ -594,7 +586,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " // @@protoc_insertion_point(field_set_rvalue:$full_name$)\n" "}\n" "#endif\n" - "$inline$void $classname$::set_$name$(const char* value) {\n" + "inline void $classname$::set_$name$(const char* value) {\n" " $null_check$" " if (!has_$name$()) {\n" " clear_$oneof_name$();\n" @@ -605,7 +597,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " $string_piece$(value), GetArenaNoVirtual());\n" " // @@protoc_insertion_point(field_set_char:$full_name$)\n" "}\n" - "$inline$" + "inline " "void $classname$::set_$name$(const $pointer_type$* value,\n" " size_t size) {\n" " if (!has_$name$()) {\n" @@ -619,7 +611,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " GetArenaNoVirtual());\n" " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" "}\n" - "$inline$::std::string* $classname$::mutable_$name$() {\n" + "inline ::std::string* $classname$::mutable_$name$() {\n" " if (!has_$name$()) {\n" " clear_$oneof_name$();\n" " set_has_$name$();\n" @@ -629,7 +621,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " GetArenaNoVirtual());\n" " // @@protoc_insertion_point(field_mutable:$full_name$)\n" "}\n" - "$inline$::std::string* $classname$::$release_name$() {\n" + "inline ::std::string* $classname$::$release_name$() {\n" " // @@protoc_insertion_point(field_release:$full_name$)\n" " if (has_$name$()) {\n" " clear_has_$oneof_name$();\n" @@ -639,19 +631,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " return NULL;\n" " }\n" "}\n" - "$inline$::std::string* $classname$::unsafe_arena_release_$name$() {\n" - " // " - "@@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n" - " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" - " if (has_$name$()) {\n" - " clear_has_$oneof_name$();\n" - " return $oneof_prefix$$name$_.UnsafeArenaRelease(\n" - " $default_variable$, GetArenaNoVirtual());\n" - " } else {\n" - " return NULL;\n" - " }\n" - "}\n" - "$inline$void $classname$::set_allocated_$name$(::std::string* $name$) {\n" + "inline void $classname$::set_allocated_$name$(::std::string* $name$) {\n" " if (!has_$name$()) {\n" " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" " }\n" @@ -663,7 +643,19 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " }\n" " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" "}\n" - "$inline$void $classname$::unsafe_arena_set_allocated_$name$(" + "inline ::std::string* $classname$::unsafe_arena_release_$name$() {\n" + " // " + "@@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n" + " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" + " if (has_$name$()) {\n" + " clear_has_$oneof_name$();\n" + " return $oneof_prefix$$name$_.UnsafeArenaRelease(\n" + " $default_variable$, GetArenaNoVirtual());\n" + " } else {\n" + " return NULL;\n" + " }\n" + "}\n" + "inline void $classname$::unsafe_arena_set_allocated_$name$(" "::std::string* $name$) {\n" " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" " if (!has_$name$()) {\n" @@ -681,15 +673,15 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, } else { // No-arena case. printer->Print( - variables, - "$inline$const ::std::string& $classname$::$name$() const {\n" + variables_, + "inline const ::std::string& $classname$::$name$() const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " if (has_$name$()) {\n" " return $oneof_prefix$$name$_.GetNoArena();\n" " }\n" " return *$default_variable$;\n" "}\n" - "$inline$void $classname$::set_$name$(const ::std::string& value) {\n" + "inline void $classname$::set_$name$(const ::std::string& value) {\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" " if (!has_$name$()) {\n" " clear_$oneof_name$();\n" @@ -700,7 +692,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " // @@protoc_insertion_point(field_set:$full_name$)\n" "}\n" "#if LANG_CXX11\n" - "$inline$void $classname$::set_$name$(::std::string&& value) {\n" + "inline void $classname$::set_$name$(::std::string&& value) {\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" " if (!has_$name$()) {\n" " clear_$oneof_name$();\n" @@ -712,7 +704,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " // @@protoc_insertion_point(field_set_rvalue:$full_name$)\n" "}\n" "#endif\n" - "$inline$void $classname$::set_$name$(const char* value) {\n" + "inline void $classname$::set_$name$(const char* value) {\n" " $null_check$" " if (!has_$name$()) {\n" " clear_$oneof_name$();\n" @@ -723,7 +715,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " $string_piece$(value));\n" " // @@protoc_insertion_point(field_set_char:$full_name$)\n" "}\n" - "$inline$" + "inline " "void $classname$::set_$name$(const $pointer_type$* value, size_t " "size) {\n" " if (!has_$name$()) {\n" @@ -736,7 +728,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " reinterpret_cast<const char*>(value), size));\n" " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" "}\n" - "$inline$::std::string* $classname$::mutable_$name$() {\n" + "inline ::std::string* $classname$::mutable_$name$() {\n" " if (!has_$name$()) {\n" " clear_$oneof_name$();\n" " set_has_$name$();\n" @@ -745,7 +737,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " // @@protoc_insertion_point(field_mutable:$full_name$)\n" " return $oneof_prefix$$name$_.MutableNoArena($default_variable$);\n" "}\n" - "$inline$::std::string* $classname$::$release_name$() {\n" + "inline ::std::string* $classname$::$release_name$() {\n" " // @@protoc_insertion_point(field_release:$full_name$)\n" " if (has_$name$()) {\n" " clear_has_$oneof_name$();\n" @@ -754,7 +746,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " return NULL;\n" " }\n" "}\n" - "$inline$void $classname$::set_allocated_$name$(::std::string* $name$) {\n" + "inline void $classname$::set_allocated_$name$(::std::string* $name$) {\n" " if (!has_$name$()) {\n" " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" " }\n" @@ -771,29 +763,13 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, void StringOneofFieldGenerator:: GenerateClearingCode(io::Printer* printer) const { - std::map<string, string> variables(variables_); - if (dependent_field_) { - variables["this_message"] = DependentBaseDownCast(); - // This clearing code may be in the dependent base class. If the default - // value is an empty string, then the $default_variable$ is a global - // singleton. If the default is not empty, we need to down-cast to get the - // default value's global singleton instance. See SetStringVariables() for - // possible values of default_variable. - if (!descriptor_->default_value_string().empty()) { - variables["default_variable"] = "&" + DependentBaseDownCast() + - variables["default_variable_name"] + - ".get()"; - } - } else { - variables["this_message"] = ""; - } if (SupportsArenas(descriptor_)) { - printer->Print(variables, - "$this_message$$oneof_prefix$$name$_.Destroy($default_variable$,\n" - " $this_message$GetArenaNoVirtual());\n"); + printer->Print(variables_, + "$oneof_prefix$$name$_.Destroy($default_variable$,\n" + " GetArenaNoVirtual());\n"); } else { - printer->Print(variables, - "$this_message$$oneof_prefix$$name$_." + printer->Print(variables_, + "$oneof_prefix$$name$_." "DestroyNoArena($default_variable$);\n"); } } @@ -818,18 +794,10 @@ GenerateConstructorCode(io::Printer* printer) const { void StringOneofFieldGenerator:: GenerateDestructorCode(io::Printer* printer) const { - if (SupportsArenas(descriptor_)) { - printer->Print(variables_, - "if (has_$name$()) {\n" - " $oneof_prefix$$name$_.Destroy($default_variable$,\n" - " GetArenaNoVirtual());\n" - "}\n"); - } else { - printer->Print(variables_, - "if (has_$name$()) {\n" - " $oneof_prefix$$name$_.DestroyNoArena($default_variable$);\n" - "}\n"); - } + printer->Print(variables_, + "if (has_$name$()) {\n" + " $oneof_prefix$$name$_.DestroyNoArena($default_variable$);\n" + "}\n"); } void StringOneofFieldGenerator:: @@ -943,71 +911,68 @@ GenerateAccessorDeclarations(io::Printer* printer) const { } void RepeatedStringFieldGenerator:: -GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const { - std::map<string, string> variables(variables_); - variables["inline"] = is_inline ? "inline " : ""; - printer->Print(variables, - "$inline$const ::std::string& $classname$::$name$(int index) const {\n" +GenerateInlineAccessorDefinitions(io::Printer* printer) const { + printer->Print(variables_, + "inline const ::std::string& $classname$::$name$(int index) const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " return $name$_.$cppget$(index);\n" "}\n" - "$inline$::std::string* $classname$::mutable_$name$(int index) {\n" + "inline ::std::string* $classname$::mutable_$name$(int index) {\n" " // @@protoc_insertion_point(field_mutable:$full_name$)\n" " return $name$_.Mutable(index);\n" "}\n" - "$inline$void $classname$::set_$name$(int index, const ::std::string& value) {\n" + "inline void $classname$::set_$name$(int index, const ::std::string& value) {\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" " $name$_.Mutable(index)->assign(value);\n" "}\n" "#if LANG_CXX11\n" - "$inline$void $classname$::set_$name$(int index, ::std::string&& value) {\n" + "inline void $classname$::set_$name$(int index, ::std::string&& value) {\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" " $name$_.Mutable(index)->assign(std::move(value));\n" "}\n" "#endif\n" - "$inline$void $classname$::set_$name$(int index, const char* value) {\n" + "inline void $classname$::set_$name$(int index, const char* value) {\n" " $null_check$" " $name$_.Mutable(index)->assign(value);\n" " // @@protoc_insertion_point(field_set_char:$full_name$)\n" "}\n" - "$inline$void " + "inline void " "$classname$::set_$name$" "(int index, const $pointer_type$* value, size_t size) {\n" " $name$_.Mutable(index)->assign(\n" " reinterpret_cast<const char*>(value), size);\n" " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" "}\n" - "$inline$::std::string* $classname$::add_$name$() {\n" + "inline ::std::string* $classname$::add_$name$() {\n" " // @@protoc_insertion_point(field_add_mutable:$full_name$)\n" " return $name$_.Add();\n" "}\n" - "$inline$void $classname$::add_$name$(const ::std::string& value) {\n" + "inline void $classname$::add_$name$(const ::std::string& value) {\n" " $name$_.Add()->assign(value);\n" " // @@protoc_insertion_point(field_add:$full_name$)\n" "}\n" "#if LANG_CXX11\n" - "$inline$void $classname$::add_$name$(::std::string&& value) {\n" + "inline void $classname$::add_$name$(::std::string&& value) {\n" " $name$_.Add(std::move(value));\n" " // @@protoc_insertion_point(field_add:$full_name$)\n" "}\n" "#endif\n" - "$inline$void $classname$::add_$name$(const char* value) {\n" + "inline void $classname$::add_$name$(const char* value) {\n" " $null_check$" " $name$_.Add()->assign(value);\n" " // @@protoc_insertion_point(field_add_char:$full_name$)\n" "}\n" - "$inline$void " + "inline void " "$classname$::add_$name$(const $pointer_type$* value, size_t size) {\n" " $name$_.Add()->assign(reinterpret_cast<const char*>(value), size);\n" " // @@protoc_insertion_point(field_add_pointer:$full_name$)\n" "}\n" - "$inline$const ::google::protobuf::RepeatedPtrField< ::std::string>&\n" + "inline const ::google::protobuf::RepeatedPtrField< ::std::string>&\n" "$classname$::$name$() const {\n" " // @@protoc_insertion_point(field_list:$full_name$)\n" " return $name$_;\n" "}\n" - "$inline$::google::protobuf::RepeatedPtrField< ::std::string>*\n" + "inline ::google::protobuf::RepeatedPtrField< ::std::string>*\n" "$classname$::mutable_$name$() {\n" " // @@protoc_insertion_point(field_mutable_list:$full_name$)\n" " return &$name$_;\n" diff --git a/src/google/protobuf/compiler/cpp/cpp_string_field.h b/src/google/protobuf/compiler/cpp/cpp_string_field.h index 933f3c6b..f56f0721 100644 --- a/src/google/protobuf/compiler/cpp/cpp_string_field.h +++ b/src/google/protobuf/compiler/cpp/cpp_string_field.h @@ -54,8 +54,7 @@ class StringFieldGenerator : public FieldGenerator { void GeneratePrivateMembers(io::Printer* printer) const; void GenerateStaticMembers(io::Printer* printer) const; void GenerateAccessorDeclarations(io::Printer* printer) const; - void GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const; + void GenerateInlineAccessorDefinitions(io::Printer* printer) const; void GenerateNonInlineAccessorDefinitions(io::Printer* printer) const; void GenerateClearingCode(io::Printer* printer) const; void GenerateMessageClearingCode(io::Printer* printer) const; @@ -86,8 +85,7 @@ class StringOneofFieldGenerator : public StringFieldGenerator { ~StringOneofFieldGenerator(); // implements FieldGenerator --------------------------------------- - void GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const; + void GenerateInlineAccessorDefinitions(io::Printer* printer) const; void GenerateClearingCode(io::Printer* printer) const; // StringFieldGenerator, from which we inherit, overrides this so we need to @@ -112,8 +110,7 @@ class RepeatedStringFieldGenerator : public FieldGenerator { // implements FieldGenerator --------------------------------------- void GeneratePrivateMembers(io::Printer* printer) const; void GenerateAccessorDeclarations(io::Printer* printer) const; - void GenerateInlineAccessorDefinitions(io::Printer* printer, - bool is_inline) const; + void GenerateInlineAccessorDefinitions(io::Printer* printer) const; void GenerateClearingCode(io::Printer* printer) const; void GenerateMergingCode(io::Printer* printer) const; void GenerateSwappingCode(io::Printer* printer) const; diff --git a/src/google/protobuf/compiler/cpp/metadata_test.cc b/src/google/protobuf/compiler/cpp/metadata_test.cc index 03f6b12b..d1bb3194 100644 --- a/src/google/protobuf/compiler/cpp/metadata_test.cc +++ b/src/google/protobuf/compiler/cpp/metadata_test.cc @@ -35,10 +35,8 @@ #include <google/protobuf/compiler/cpp/cpp_helpers.h> #include <google/protobuf/compiler/cpp/cpp_generator.h> +#include <google/protobuf/compiler/annotation_test_util.h> #include <google/protobuf/compiler/command_line_interface.h> -#include <google/protobuf/io/zero_copy_stream.h> -#include <google/protobuf/io/zero_copy_stream_impl_lite.h> -#include <google/protobuf/io/printer.h> #include <google/protobuf/descriptor.pb.h> #include <google/protobuf/testing/file.h> @@ -47,37 +45,15 @@ #include <gtest/gtest.h> namespace google { +namespace atu = ::google::protobuf::compiler::annotation_test_util; + namespace protobuf { namespace compiler { namespace cpp { namespace { -// A CodeGenerator that captures the FileDescriptor it's passed as a -// FileDescriptorProto. -class DescriptorCapturingGenerator : public CodeGenerator { - public: - // Does not own file; file must outlive the Generator. - explicit DescriptorCapturingGenerator(FileDescriptorProto* file) - : file_(file) {} - - virtual bool Generate(const FileDescriptor* file, const string& parameter, - GeneratorContext* context, string* error) const { - file->CopyTo(file_); - return true; - } - - private: - FileDescriptorProto* file_; -}; - class CppMetadataTest : public ::testing::Test { public: - // Adds a file with name `filename` and content `data`. - void AddFile(const string& filename, const string& data) { - GOOGLE_CHECK_OK(File::SetContents(TestTempDir() + "/" + filename, data, - true)); - } - // Tries to capture a FileDescriptorProto, GeneratedCodeInfo, and output // code from the previously added file with name `filename`. Returns true on // success. If pb_h is non-null, expects a .pb.h and a .pb.h.meta (copied to @@ -87,26 +63,21 @@ class CppMetadataTest : public ::testing::Test { string* proto_h, GeneratedCodeInfo* proto_h_info, string* pb_cc) { google::protobuf::compiler::CommandLineInterface cli; - cli.SetInputsAreProtoPathRelative(true); - CppGenerator cpp_generator; - DescriptorCapturingGenerator capturing_generator(file); cli.RegisterGenerator("--cpp_out", &cpp_generator, ""); - cli.RegisterGenerator("--capture_out", &capturing_generator, ""); - - string proto_path = "-I" + TestTempDir(); string cpp_out = "--cpp_out=annotate_headers=true," "annotation_pragma_name=pragma_name," "annotation_guard_name=guard_name:" + TestTempDir(); - string capture_out = "--capture_out=" + TestTempDir(); - const char* argv[] = {"protoc", proto_path.c_str(), cpp_out.c_str(), - capture_out.c_str(), filename.c_str()}; + const bool result = + atu::CaptureMetadata(filename, cpp_out, + /* meta_file_suffix */ "", &cli, file, + /* outputs */ NULL); - if (cli.Run(5, argv) != 0) { - return false; + if (!result) { + return result; } string output_base = TestTempDir() + "/" + StripProto(filename); @@ -119,7 +90,7 @@ class CppMetadataTest : public ::testing::Test { if (pb_h != NULL && pb_h_info != NULL) { GOOGLE_CHECK_OK( File::GetContents(output_base + ".pb.h", pb_h, true)); - if (!DecodeMetadata(output_base + ".pb.h.meta", pb_h_info)) { + if (!atu::DecodeMetadata(output_base + ".pb.h.meta", pb_h_info)) { return false; } } @@ -127,23 +98,13 @@ class CppMetadataTest : public ::testing::Test { if (proto_h != NULL && proto_h_info != NULL) { GOOGLE_CHECK_OK(File::GetContents(output_base + ".proto.h", proto_h, true)); - if (!DecodeMetadata(output_base + ".proto.h.meta", proto_h_info)) { + if (!atu::DecodeMetadata(output_base + ".proto.h.meta", proto_h_info)) { return false; } } return true; } - - private: - // Decodes GeneratedCodeInfo stored in path and copies it to info. - // Returns true on success. - bool DecodeMetadata(const string& path, GeneratedCodeInfo* info) { - string data; - GOOGLE_CHECK_OK(File::GetContents(path, &data, true)); - io::ArrayInputStream input(data.data(), data.size()); - return info->ParseFromZeroCopyStream(&input); - } }; const char kSmallTestFile[] = @@ -152,48 +113,11 @@ const char kSmallTestFile[] = "enum Enum { VALUE = 0; }\n" "message Message { }\n"; -// Finds the Annotation for a given source file and path (or returns null if it -// couldn't). -const GeneratedCodeInfo::Annotation* FindAnnotationOnPath( - const GeneratedCodeInfo& info, const string& source_file, - const std::vector<int>& path) { - for (int i = 0; i < info.annotation_size(); ++i) { - const GeneratedCodeInfo::Annotation* annotation = &info.annotation(i); - if (annotation->source_file() != source_file || - annotation->path_size() != path.size()) { - continue; - } - int node = 0; - for (; node < path.size(); ++node) { - if (annotation->path(node) != path[node]) { - break; - } - } - if (node == path.size()) { - return annotation; - } - } - return NULL; -} - -// Returns true if the provided annotation covers a given substring in -// file_content. -bool AnnotationMatchesSubstring(const string& file_content, - const GeneratedCodeInfo::Annotation* annotation, - const string& expected_text) { - uint32 begin = annotation->begin(); - uint32 end = annotation->end(); - if (end < begin || end > file_content.size()) { - return false; - } - return file_content.substr(begin, end - begin) == expected_text; -} - TEST_F(CppMetadataTest, CapturesEnumNames) { FileDescriptorProto file; GeneratedCodeInfo info; string pb_h; - AddFile("test.proto", kSmallTestFile); + atu::AddFile("test.proto", kSmallTestFile); EXPECT_TRUE( CaptureMetadata("test.proto", &file, &pb_h, &info, NULL, NULL, NULL)); EXPECT_EQ("Enum", file.enum_type(0).name()); @@ -201,16 +125,16 @@ TEST_F(CppMetadataTest, CapturesEnumNames) { enum_path.push_back(FileDescriptorProto::kEnumTypeFieldNumber); enum_path.push_back(0); const GeneratedCodeInfo::Annotation* enum_annotation = - FindAnnotationOnPath(info, "test.proto", enum_path); + atu::FindAnnotationOnPath(info, "test.proto", enum_path); EXPECT_TRUE(NULL != enum_annotation); - EXPECT_TRUE(AnnotationMatchesSubstring(pb_h, enum_annotation, "Enum")); + EXPECT_TRUE(atu::AnnotationMatchesSubstring(pb_h, enum_annotation, "Enum")); } TEST_F(CppMetadataTest, AddsPragma) { FileDescriptorProto file; GeneratedCodeInfo info; string pb_h; - AddFile("test.proto", kSmallTestFile); + atu::AddFile("test.proto", kSmallTestFile); EXPECT_TRUE( CaptureMetadata("test.proto", &file, &pb_h, &info, NULL, NULL, NULL)); EXPECT_TRUE(pb_h.find("#ifdef guard_name") != string::npos); @@ -222,7 +146,7 @@ TEST_F(CppMetadataTest, CapturesMessageNames) { FileDescriptorProto file; GeneratedCodeInfo info; string pb_h; - AddFile("test.proto", kSmallTestFile); + atu::AddFile("test.proto", kSmallTestFile); EXPECT_TRUE( CaptureMetadata("test.proto", &file, &pb_h, &info, NULL, NULL, NULL)); EXPECT_EQ("Message", file.message_type(0).name()); @@ -230,9 +154,10 @@ TEST_F(CppMetadataTest, CapturesMessageNames) { message_path.push_back(FileDescriptorProto::kMessageTypeFieldNumber); message_path.push_back(0); const GeneratedCodeInfo::Annotation* message_annotation = - FindAnnotationOnPath(info, "test.proto", message_path); + atu::FindAnnotationOnPath(info, "test.proto", message_path); EXPECT_TRUE(NULL != message_annotation); - EXPECT_TRUE(AnnotationMatchesSubstring(pb_h, message_annotation, "Message")); + EXPECT_TRUE( + atu::AnnotationMatchesSubstring(pb_h, message_annotation, "Message")); } } // namespace diff --git a/src/google/protobuf/compiler/java/java_helpers.cc b/src/google/protobuf/compiler/java/java_helpers.cc index d8ac2db3..dbb86b87 100644 --- a/src/google/protobuf/compiler/java/java_helpers.cc +++ b/src/google/protobuf/compiler/java/java_helpers.cc @@ -37,6 +37,7 @@ #include <limits> #include <vector> +#include <google/protobuf/stubs/stringprintf.h> #include <google/protobuf/compiler/java/java_helpers.h> #include <google/protobuf/compiler/java/java_name_resolver.h> #include <google/protobuf/descriptor.pb.h> @@ -783,6 +784,137 @@ bool HasRepeatedFields(const Descriptor* descriptor) { return false; } +// Encode an unsigned 32-bit value into a sequence of UTF-16 characters. +// +// If the value is in [0x0000, 0xD7FF], we encode it with a single character +// with the same numeric value. +// +// If the value is larger than 0xD7FF, we encode its lowest 13 bits into a +// character in the range [0xE000, 0xFFFF] by combining these 13 bits with +// 0xE000 using logic-or. Then we shift the value to the right by 13 bits, and +// encode the remaining value by repeating this same process until we get to +// a value in [0x0000, 0xD7FF] where we will encode it using a character with +// the same numeric value. +// +// Note that we only use code points in [0x0000, 0xD7FF] and [0xE000, 0xFFFF]. +// There will be no surrogate pairs in the encoded character sequence. +void WriteUInt32ToUtf16CharSequence(uint32 number, + std::vector<uint16>* output) { + // For values in [0x0000, 0xD7FF], only use one char to encode it. + if (number < 0xD800) { + output->push_back(static_cast<uint16>(number)); + return; + } + // Encode into multiple chars. All except the last char will be in the range + // [0xE000, 0xFFFF], and the last char will be in the range [0x0000, 0xD7FF]. + // Note that we don't use any value in range [0xD800, 0xDFFF] because they + // have to come in pairs and the encoding is just more space-efficient w/o + // them. + while (number >= 0xD800) { + // [0xE000, 0xFFFF] can represent 13 bits of info. + output->push_back(static_cast<uint16>(0xE000 | (number & 0x1FFF))); + number >>= 13; + } + output->push_back(static_cast<uint16>(number)); +} + +int GetExperimentalJavaFieldTypeForSingular(const FieldDescriptor* field) { + // j/c/g/protobuf/FieldType.java lists field types in a slightly different + // order from FieldDescriptor::Type so we can't do a simple cast. + // + // TODO(xiaofeng): Make j/c/g/protobuf/FieldType.java follow the same order. + int result = field->type(); + if (result == FieldDescriptor::TYPE_GROUP) { + return 17; + } else if (result < FieldDescriptor::TYPE_GROUP) { + return result - 1; + } else { + return result - 2; + } +} + +int GetExperimentalJavaFieldTypeForRepeated(const FieldDescriptor* field) { + if (field->type() == FieldDescriptor::TYPE_GROUP) { + return 49; + } else { + return GetExperimentalJavaFieldTypeForSingular(field) + 18; + } +} + +int GetExperimentalJavaFieldTypeForPacked(const FieldDescriptor* field) { + int result = field->type(); + if (result < FieldDescriptor::TYPE_STRING) { + return result + 34; + } else if (result > FieldDescriptor::TYPE_BYTES) { + return result + 30; + } else { + GOOGLE_LOG(FATAL) << field->full_name() << " can't be packed."; + return 0; + } +} + +int GetExperimentalJavaFieldType(const FieldDescriptor* field) { + static const int kMapFieldType = 50; + static const int kOneofFieldTypeOffset = 51; + static const int kRequiredBit = 0x100; + static const int kUtf8CheckBit = 0x200; + static const int kCheckInitialized = 0x400; + static const int kMapWithProto2EnumValue = 0x800; + int extra_bits = field->is_required() ? kRequiredBit : 0; + if (field->type() == FieldDescriptor::TYPE_STRING && CheckUtf8(field)) { + extra_bits |= kUtf8CheckBit; + } + if (field->is_required() || (GetJavaType(field) == JAVATYPE_MESSAGE && + HasRequiredFields(field->message_type()))) { + extra_bits |= kCheckInitialized; + } + + if (field->is_map()) { + if (SupportFieldPresence(field->file())) { + const FieldDescriptor* value = + field->message_type()->FindFieldByName("value"); + if (GetJavaType(value) == JAVATYPE_ENUM) { + extra_bits |= kMapWithProto2EnumValue; + } + } + return kMapFieldType | extra_bits; + } else if (field->is_packed()) { + return GetExperimentalJavaFieldTypeForPacked(field); + } else if (field->is_repeated()) { + return GetExperimentalJavaFieldTypeForRepeated(field) | extra_bits; + } else if (field->containing_oneof() != NULL) { + return (GetExperimentalJavaFieldTypeForSingular(field) + + kOneofFieldTypeOffset) | + extra_bits; + } else { + return GetExperimentalJavaFieldTypeForSingular(field) | extra_bits; + } +} + +// Escape a UTF-16 character to be embedded in a Java string. +void EscapeUtf16ToString(uint16 code, string* output) { + if (code == '\t') { + output->append("\\t"); + } else if (code == '\b') { + output->append("\\b"); + } else if (code == '\n') { + output->append("\\n"); + } else if (code == '\r') { + output->append("\\r"); + } else if (code == '\f') { + output->append("\\f"); + } else if (code == '\'') { + output->append("\\'"); + } else if (code == '\"') { + output->append("\\\""); + } else if (code == '\\') { + output->append("\\\\"); + } else if (code >= 0x20 && code <= 0x7f) { + output->push_back(static_cast<char>(code)); + } else { + output->append(StringPrintf("\\u%04x", code)); + } +} } // namespace java } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/java/java_helpers.h b/src/google/protobuf/compiler/java/java_helpers.h index 1ab168c4..00d683db 100644 --- a/src/google/protobuf/compiler/java/java_helpers.h +++ b/src/google/protobuf/compiler/java/java_helpers.h @@ -394,6 +394,26 @@ inline string GeneratedCodeVersionSuffix() { inline bool EnableExperimentalRuntime(Context* context) { return false; } + +void WriteUInt32ToUtf16CharSequence(uint32 number, std::vector<uint16>* output); + +inline void WriteIntToUtf16CharSequence(int value, + std::vector<uint16>* output) { + WriteUInt32ToUtf16CharSequence(static_cast<uint32>(value), output); +} + +// Escape a UTF-16 character so it can be embedded in a Java string literal. +void EscapeUtf16ToString(uint16 code, string* output); + +// Only the lowest two bytes of the return value are used. The lowest byte +// is the integer value of a j/c/g/protobuf/FieldType enum. For the other +// byte: +// bit 0: whether the field is required. +// bit 1: whether the field requires UTF-8 validation. +// bit 2: whether the field needs isInitialized check. +// bit 3: whether the field is a map field with proto2 enum value. +// bits 4-7: unused +int GetExperimentalJavaFieldType(const FieldDescriptor* field); } // namespace java } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/java/java_message.cc b/src/google/protobuf/compiler/java/java_message.cc index df0c95c8..2486b739 100644 --- a/src/google/protobuf/compiler/java/java_message.cc +++ b/src/google/protobuf/compiler/java/java_message.cc @@ -371,6 +371,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { "}\n" "\n"); + printer->Print( "@java.lang.Override\n" "public final com.google.protobuf.UnknownFieldSet\n" diff --git a/src/google/protobuf/compiler/java/java_message_lite.cc b/src/google/protobuf/compiler/java/java_message_lite.cc index 29b4f98b..d828be43 100644 --- a/src/google/protobuf/compiler/java/java_message_lite.cc +++ b/src/google/protobuf/compiler/java/java_message_lite.cc @@ -69,6 +69,14 @@ using internal::WireFormat; using internal::WireFormatLite; namespace { +bool EnableExperimentalRuntimeForLite() { +#ifdef PROTOBUF_EXPERIMENT + return PROTOBUF_EXPERIMENT; +#else // PROTOBUF_EXPERIMENT + return false; +#endif // !PROTOBUF_EXPERIMENT +} + bool GenerateHasBits(const Descriptor* descriptor) { return SupportFieldPresence(descriptor->file()) || HasRepeatedFields(descriptor); @@ -361,14 +369,14 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { printer->Indent(); printer->Indent(); - printer->Print( - "case IS_INITIALIZED: {\n"); + printer->Print("case IS_INITIALIZED: {\n"); printer->Indent(); GenerateDynamicMethodIsInitialized(printer); printer->Outdent(); + printer->Print("}\n"); + printer->Print( - "}\n" "case MAKE_IMMUTABLE: {\n"); printer->Indent(); @@ -383,13 +391,15 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { GenerateDynamicMethodNewBuilder(printer); printer->Outdent(); - printer->Print( - "}\n" - "case VISIT: {\n"); + if (!EnableExperimentalRuntimeForLite()) { + printer->Print( + "}\n" + "case VISIT: {\n"); - printer->Indent(); - GenerateDynamicMethodVisit(printer); - printer->Outdent(); + printer->Indent(); + GenerateDynamicMethodVisit(printer); + printer->Outdent(); + } printer->Print( "}\n" @@ -470,6 +480,17 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { "}\n" "\n", "classname", descriptor_->name()); + if (EnableExperimentalRuntimeForLite()) { + // Register the default instance in a map. This map will be used by + // experimental runtime to lookup default instance given a class instance + // without using Java reflection. + printer->Print( + "static {\n" + " com.google.protobuf.GeneratedMessageLite.registerDefaultInstance(\n" + " $classname$.class, DEFAULT_INSTANCE);\n" + "}\n", + "classname", descriptor_->name()); + } printer->Print( "public static $classname$ getDefaultInstance() {\n" " return DEFAULT_INSTANCE;\n" @@ -502,6 +523,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { printer->Print("}\n\n"); } + // =================================================================== void ImmutableMessageLiteGenerator:: @@ -708,10 +730,10 @@ void ImmutableMessageLiteGenerator::GenerateSerializeOneExtensionRange( void ImmutableMessageLiteGenerator::GenerateBuilder(io::Printer* printer) { printer->Print( "public static Builder newBuilder() {\n" - " return DEFAULT_INSTANCE.toBuilder();\n" + " return (Builder) DEFAULT_INSTANCE.createBuilder();\n" "}\n" "public static Builder newBuilder($classname$ prototype) {\n" - " return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);\n" + " return (Builder) DEFAULT_INSTANCE.createBuilder(prototype);\n" "}\n" "\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index 812ca9d8..16fe19ad 100755 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -244,22 +244,35 @@ string GetPrefix(const GeneratorOptions& options, return prefix; } +// Returns the fully normalized JavaScript path prefix for the given +// message descriptor. +string GetMessagePathPrefix(const GeneratorOptions& options, + const Descriptor* descriptor) { + return GetPrefix( + options, descriptor->file(), + descriptor->containing_type()); +} + // Returns the fully normalized JavaScript path for the given // message descriptor. string GetMessagePath(const GeneratorOptions& options, const Descriptor* descriptor) { - return GetPrefix( - options, descriptor->file(), - descriptor->containing_type()) + descriptor->name(); + return GetMessagePathPrefix(options, descriptor) + descriptor->name(); +} + +// Returns the fully normalized JavaScript path prefix for the given +// enumeration descriptor. +string GetEnumPathPrefix(const GeneratorOptions& options, + const EnumDescriptor* enum_descriptor) { + return GetPrefix(options, enum_descriptor->file(), + enum_descriptor->containing_type()); } // Returns the fully normalized JavaScript path for the given // enumeration descriptor. string GetEnumPath(const GeneratorOptions& options, const EnumDescriptor* enum_descriptor) { - return GetPrefix( - options, enum_descriptor->file(), - enum_descriptor->containing_type()) + enum_descriptor->name(); + return GetEnumPathPrefix(options, enum_descriptor) + enum_descriptor->name(); } string MaybeCrossFileRef(const GeneratorOptions& options, @@ -1930,8 +1943,10 @@ void Generator::GenerateClassConstructor(const GeneratorOptions& options, " * @extends {jspb.Message}\n" " * @constructor\n" " */\n" - "$classname$ = function(opt_data) {\n", - "classname", GetMessagePath(options, desc)); + "$classprefix$$classname$ = function(opt_data) {\n", + "classprefix", GetMessagePathPrefix(options, desc), + "classname", desc->name()); + printer->Annotate("classname", desc); string message_id = GetMessageId(desc); printer->Print( " jspb.Message.initialize(this, opt_data, $messageId$, $pivot$, " @@ -2413,12 +2428,13 @@ void Generator::GenerateClassField(const GeneratorOptions& options, "keytype", key_type, "valuetype", value_type); printer->Print( - "$class$.prototype.get$name$ = function(opt_noLazyCreate) {\n" + "$class$.prototype.$gettername$ = function(opt_noLazyCreate) {\n" " return /** @type {!jspb.Map<$keytype$,$valuetype$>} */ (\n", "class", GetMessagePath(options, field->containing_type()), - "name", JSGetterName(options, field), + "gettername", "get" + JSGetterName(options, field), "keytype", key_type, "valuetype", value_type); + printer->Annotate("gettername", field); printer->Print( " jspb.Message.getMapField(this, $index$, opt_noLazyCreate", "index", JSFieldIndex(field)); @@ -2457,7 +2473,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options, /* force_present = */ false, /* singular_if_not_packed = */ false)); printer->Print( - "$class$.prototype.get$name$ = function() {\n" + "$class$.prototype.$gettername$ = function() {\n" " return /** @type{$type$} */ (\n" " jspb.Message.get$rpt$WrapperField(this, $wrapperclass$, " "$index$$required$));\n" @@ -2465,7 +2481,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options, "\n" "\n", "class", GetMessagePath(options, field->containing_type()), - "name", JSGetterName(options, field), + "gettername", "get" + JSGetterName(options, field), "type", JSFieldTypeAnnotation(options, field, /* is_setter_argument = */ false, /* force_present = */ false, @@ -2475,9 +2491,10 @@ void Generator::GenerateClassField(const GeneratorOptions& options, "wrapperclass", SubmessageTypeRef(options, field), "required", (field->label() == FieldDescriptor::LABEL_REQUIRED ? ", 1" : "")); + printer->Annotate("gettername", field); printer->Print( "/** @param {$optionaltype$} value$returndoc$ */\n" - "$class$.prototype.set$name$ = function(value) {\n" + "$class$.prototype.$settername$ = function(value) {\n" " jspb.Message.set$oneoftag$$repeatedtag$WrapperField(", "optionaltype", JSFieldTypeAnnotation(options, field, @@ -2486,9 +2503,10 @@ void Generator::GenerateClassField(const GeneratorOptions& options, /* singular_if_not_packed = */ false), "returndoc", JSReturnDoc(options, field), "class", GetMessagePath(options, field->containing_type()), - "name", JSGetterName(options, field), + "settername", "set" + JSGetterName(options, field), "oneoftag", (field->containing_oneof() ? "Oneof" : ""), "repeatedtag", (field->is_repeated() ? "Repeated" : "")); + printer->Annotate("settername", field); printer->Print( "this, $index$$oneofgroup$, value);$returnvalue$\n" @@ -2540,9 +2558,10 @@ void Generator::GenerateClassField(const GeneratorOptions& options, } printer->Print( - "$class$.prototype.get$name$ = function() {\n", + "$class$.prototype.$gettername$ = function() {\n", "class", GetMessagePath(options, field->containing_type()), - "name", JSGetterName(options, field)); + "gettername", "get" + JSGetterName(options, field)); + printer->Annotate("gettername", field); if (untyped) { printer->Print( @@ -2610,24 +2629,27 @@ void Generator::GenerateClassField(const GeneratorOptions& options, // Proto3 non-repeated and non-map fields without presence use the // setProto3*Field function. printer->Print( - "$class$.prototype.set$name$ = function(value) {\n" + "$class$.prototype.$settername$ = function(value) {\n" " jspb.Message.setProto3$typetag$Field(this, $index$, " "value);$returnvalue$\n" "};\n" "\n" "\n", - "class", GetMessagePath(options, field->containing_type()), "name", - JSGetterName(options, field), "typetag", JSTypeTag(field), "index", - JSFieldIndex(field), "returnvalue", JSReturnClause(field)); + "class", GetMessagePath(options, field->containing_type()), + "settername", "set" + JSGetterName(options, field), "typetag", + JSTypeTag(field), "index", JSFieldIndex(field), "returnvalue", + JSReturnClause(field)); + printer->Annotate("settername", field); } else { // Otherwise, use the regular setField function. printer->Print( - "$class$.prototype.set$name$ = function(value) {\n" + "$class$.prototype.$settername$ = function(value) {\n" " jspb.Message.set$oneoftag$Field(this, $index$", - "class", GetMessagePath(options, field->containing_type()), "name", - JSGetterName(options, field), "oneoftag", + "class", GetMessagePath(options, field->containing_type()), + "settername", "set" + JSGetterName(options, field), "oneoftag", (field->containing_oneof() ? "Oneof" : ""), "index", JSFieldIndex(field)); + printer->Annotate("settername", field); printer->Print( "$oneofgroup$, $type$value$rptvalueinit$$typeclose$);$returnvalue$\n" "};\n" @@ -2660,41 +2682,46 @@ void Generator::GenerateClassField(const GeneratorOptions& options, // fields with presence. if (IsMap(options, field)) { printer->Print( - "$class$.prototype.clear$name$ = function() {\n" - " this.get$name$().clear();$returnvalue$\n" + "$class$.prototype.$clearername$ = function() {\n" + " this.$gettername$().clear();$returnvalue$\n" "};\n" "\n" "\n", "class", GetMessagePath(options, field->containing_type()), - "name", JSGetterName(options, field), + "clearername", "clear" + JSGetterName(options, field), + "gettername", "get" + JSGetterName(options, field), "returnvalue", JSReturnClause(field)); + printer->Annotate("clearername", field); } else if (field->is_repeated() || (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && !field->is_required())) { // Fields where we can delegate to the regular setter. printer->Print( - "$class$.prototype.clear$name$ = function() {\n" - " this.set$name$($clearedvalue$);$returnvalue$\n" + "$class$.prototype.$clearername$ = function() {\n" + " this.$settername$($clearedvalue$);$returnvalue$\n" "};\n" "\n" "\n", "class", GetMessagePath(options, field->containing_type()), - "name", JSGetterName(options, field), + "clearername", "clear" + JSGetterName(options, field), + "settername", "set" + JSGetterName(options, field), "clearedvalue", (field->is_repeated() ? "[]" : "undefined"), "returnvalue", JSReturnClause(field)); + printer->Annotate("clearername", field); } else if (HasFieldPresence(options, field)) { // Fields where we can't delegate to the regular setter because it doesn't // accept "undefined" as an argument. printer->Print( - "$class$.prototype.clear$name$ = function() {\n" + "$class$.prototype.$clearername$ = function() {\n" " jspb.Message.set$maybeoneof$Field(this, " "$index$$maybeoneofgroup$, ", "class", GetMessagePath(options, field->containing_type()), - "name", JSGetterName(options, field), + "clearername", "clear" + JSGetterName(options, field), "maybeoneof", (field->containing_oneof() ? "Oneof" : ""), "maybeoneofgroup", (field->containing_oneof() ? (", " + JSOneofArray(options, field)) : ""), "index", JSFieldIndex(field)); + printer->Annotate("clearername", field); printer->Print( "$clearedvalue$);$returnvalue$\n" "};\n" @@ -2710,14 +2737,15 @@ void Generator::GenerateClassField(const GeneratorOptions& options, " * Returns whether this field is set.\n" " * @return {!boolean}\n" " */\n" - "$class$.prototype.has$name$ = function() {\n" + "$class$.prototype.$hasername$ = function() {\n" " return jspb.Message.getField(this, $index$) != null;\n" "};\n" "\n" "\n", "class", GetMessagePath(options, field->containing_type()), - "name", JSGetterName(options, field), + "hasername", "has" + JSGetterName(options, field), "index", JSFieldIndex(field)); + printer->Annotate("hasername", field); } } @@ -2729,13 +2757,14 @@ void Generator::GenerateRepeatedPrimitiveHelperMethods( " * @param {!$optionaltype$} value\n" " * @param {number=} opt_index\n" " */\n" - "$class$.prototype.add$name$ = function(value, opt_index) {\n" + "$class$.prototype.$addername$ = function(value, opt_index) {\n" " jspb.Message.addToRepeatedField(this, $index$", - "class", GetMessagePath(options, field->containing_type()), - "name", JSGetterName(options, field, BYTES_DEFAULT, - /* drop_list = */ true), + "class", GetMessagePath(options, field->containing_type()), "addername", + "add" + JSGetterName(options, field, BYTES_DEFAULT, + /* drop_list = */ true), "optionaltype", JSTypeName(options, field, BYTES_DEFAULT), "index", JSFieldIndex(field)); + printer->Annotate("addername", field); printer->Print( "$oneofgroup$, $type$value$rptvalueinit$$typeclose$, opt_index);\n" "};\n" @@ -3133,8 +3162,10 @@ void Generator::GenerateEnum(const GeneratorOptions& options, "/**\n" " * @enum {number}\n" " */\n" - "$name$ = {\n", - "name", GetEnumPath(options, enumdesc)); + "$enumprefix$$name$ = {\n", + "enumprefix", GetEnumPathPrefix(options, enumdesc), + "name", enumdesc->name()); + printer->Annotate("name", enumdesc); for (int i = 0; i < enumdesc->value_count(); i++) { const EnumValueDescriptor* value = enumdesc->value(i); @@ -3143,6 +3174,7 @@ void Generator::GenerateEnum(const GeneratorOptions& options, "name", ToEnumCase(value->name()), "value", SimpleItoa(value->number()), "comma", (i == enumdesc->value_count() - 1) ? "" : ","); + printer->Annotate("name", value); } printer->Print( @@ -3282,6 +3314,12 @@ bool GeneratorOptions::ParseFromOptions( return false; } one_output_file_per_input_file = true; + } else if (options[i].first == "annotate_code") { + if (!options[i].second.empty()) { + *error = "Unexpected option value for annotate_code"; + return false; + } + annotate_code = true; } else { // Assume any other option is an output directory, as long as it is a bare // `key` rather than a `key=value` option. @@ -3582,16 +3620,27 @@ bool Generator::GenerateAll(const std::vector<const FileDescriptor*>& files, options.output_dir + "/" + GetJSFilename(options, file->name()); google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> output(context->Open(filename)); GOOGLE_CHECK(output.get()); - io::Printer printer(output.get(), '$'); + GeneratedCodeInfo annotations; + io::AnnotationProtoCollector<GeneratedCodeInfo> annotation_collector( + &annotations); + io::Printer printer(output.get(), '$', + options.annotate_code ? &annotation_collector : NULL); + GenerateFile(options, &printer, file); if (printer.failed()) { return false; } + + if (options.annotate_code) { + const string meta_file = filename + ".meta"; + google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> info_output( + context->Open(meta_file)); + annotations.SerializeToZeroCopyStream(info_output.get()); + } } } - return true; } diff --git a/src/google/protobuf/compiler/js/js_generator.h b/src/google/protobuf/compiler/js/js_generator.h index 6e932d7f..3cc60e22 100755 --- a/src/google/protobuf/compiler/js/js_generator.h +++ b/src/google/protobuf/compiler/js/js_generator.h @@ -79,7 +79,8 @@ struct GeneratorOptions { library(""), error_on_name_conflict(false), extension(".js"), - one_output_file_per_input_file(false) {} + one_output_file_per_input_file(false), + annotate_code(false) {} bool ParseFromOptions( const std::vector< std::pair< string, string > >& options, @@ -118,6 +119,9 @@ struct GeneratorOptions { string extension; // Create a separate output file for each input file? bool one_output_file_per_input_file; + // If true, we should build .meta files that contain annotations for + // generated code. See GeneratedCodeInfo in descriptor.proto. + bool annotate_code; }; // CodeGenerator implementation which generates a JavaScript source file and diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index 557e2d7a..80c8c625 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -14,6 +14,10 @@ #include <google/protobuf/generated_message_reflection.h> #include <google/protobuf/reflection_ops.h> #include <google/protobuf/wire_format.h> +// This is a temporary google only hack +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS +#include "third_party/protobuf/version.h" +#endif // @@protoc_insertion_point(includes) namespace google { namespace protobuf { @@ -45,7 +49,11 @@ namespace protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto { void InitDefaultsVersionImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::compiler::_Version_default_instance_; new (ptr) ::google::protobuf::compiler::Version(); @@ -62,7 +70,11 @@ void InitDefaultsVersion() { void InitDefaultsCodeGeneratorRequestImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsFileDescriptorProto(); protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::InitDefaultsVersion(); { @@ -81,7 +93,11 @@ void InitDefaultsCodeGeneratorRequest() { void InitDefaultsCodeGeneratorResponse_FileImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::compiler::_CodeGeneratorResponse_File_default_instance_; new (ptr) ::google::protobuf::compiler::CodeGeneratorResponse_File(); @@ -98,7 +114,11 @@ void InitDefaultsCodeGeneratorResponse_File() { void InitDefaultsCodeGeneratorResponseImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::InitDefaultsCodeGeneratorResponse_File(); { void* ptr = &::google::protobuf::compiler::_CodeGeneratorResponse_default_instance_; @@ -319,11 +339,11 @@ void Version::Clear() { // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; - if (has_suffix()) { + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 0x00000001u) { GOOGLE_DCHECK(!suffix_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*suffix_.UnsafeRawStringPointer())->clear(); } - cached_has_bits = _has_bits_[0]; if (cached_has_bits & 14u) { ::memset(&major_, 0, static_cast<size_t>( reinterpret_cast<char*>(&patch_) - @@ -634,6 +654,9 @@ void CodeGeneratorRequest::InitAsDefaultInstance() { ::google::protobuf::compiler::_CodeGeneratorRequest_default_instance_._instance.get_mutable()->compiler_version_ = const_cast< ::google::protobuf::compiler::Version*>( ::google::protobuf::compiler::Version::internal_default_instance()); } +void CodeGeneratorRequest::clear_proto_file() { + proto_file_.Clear(); +} #if !defined(_MSC_VER) || _MSC_VER >= 1900 const int CodeGeneratorRequest::kFileToGenerateFieldNumber; const int CodeGeneratorRequest::kParameterFieldNumber; @@ -724,7 +747,7 @@ void CodeGeneratorRequest::Clear() { } if (cached_has_bits & 0x00000002u) { GOOGLE_DCHECK(compiler_version_ != NULL); - compiler_version_->::google::protobuf::compiler::Version::Clear(); + compiler_version_->Clear(); } } _has_bits_.Clear(); @@ -778,7 +801,7 @@ bool CodeGeneratorRequest::MergePartialFromCodedStream( case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage( input, mutable_compiler_version())); } else { goto handle_unusual; @@ -790,8 +813,7 @@ bool CodeGeneratorRequest::MergePartialFromCodedStream( case 15: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(122u /* 122 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_proto_file())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_proto_file())); } else { goto handle_unusual; } @@ -897,7 +919,7 @@ void CodeGeneratorRequest::SerializeWithCachedSizes( // optional .google.protobuf.compiler.Version compiler_version = 3; if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 3, *this->compiler_version_, deterministic, target); } @@ -905,7 +927,7 @@ void CodeGeneratorRequest::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->proto_file_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 15, this->proto_file(static_cast<int>(i)), deterministic, target); } @@ -940,7 +962,7 @@ size_t CodeGeneratorRequest::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->proto_file(static_cast<int>(i))); } } @@ -956,7 +978,7 @@ size_t CodeGeneratorRequest::ByteSizeLong() const { // optional .google.protobuf.compiler.Version compiler_version = 3; if (has_compiler_version()) { total_size += 1 + - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( *this->compiler_version_); } @@ -1511,7 +1533,8 @@ void CodeGeneratorResponse::Clear() { (void) cached_has_bits; file_.Clear(); - if (has_error()) { + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 0x00000001u) { GOOGLE_DCHECK(!error_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*error_.UnsafeRawStringPointer())->clear(); } @@ -1549,8 +1572,7 @@ bool CodeGeneratorResponse::MergePartialFromCodedStream( case 15: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(122u /* 122 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_file())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_file())); } else { goto handle_unusual; } @@ -1631,7 +1653,7 @@ void CodeGeneratorResponse::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->file_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 15, this->file(static_cast<int>(i)), deterministic, target); } @@ -1658,7 +1680,7 @@ size_t CodeGeneratorResponse::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->file(static_cast<int>(i))); } } diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 0c2ad703..8f92b6ae 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -379,8 +379,8 @@ class LIBPROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message void clear_compiler_version(); static const int kCompilerVersionFieldNumber = 3; const ::google::protobuf::compiler::Version& compiler_version() const; - ::google::protobuf::compiler::Version* mutable_compiler_version(); ::google::protobuf::compiler::Version* release_compiler_version(); + ::google::protobuf::compiler::Version* mutable_compiler_version(); void set_allocated_compiler_version(::google::protobuf::compiler::Version* compiler_version); // @@protoc_insertion_point(class_scope:google.protobuf.compiler.CodeGeneratorRequest) @@ -973,9 +973,6 @@ inline void CodeGeneratorRequest::set_allocated_parameter(::std::string* paramet inline int CodeGeneratorRequest::proto_file_size() const { return proto_file_.size(); } -inline void CodeGeneratorRequest::clear_proto_file() { - proto_file_.Clear(); -} inline const ::google::protobuf::FileDescriptorProto& CodeGeneratorRequest::proto_file(int index) const { // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorRequest.proto_file) return proto_file_.Get(index); @@ -1010,7 +1007,7 @@ inline void CodeGeneratorRequest::clear_has_compiler_version() { _has_bits_[0] &= ~0x00000002u; } inline void CodeGeneratorRequest::clear_compiler_version() { - if (compiler_version_ != NULL) compiler_version_->::google::protobuf::compiler::Version::Clear(); + if (compiler_version_ != NULL) compiler_version_->Clear(); clear_has_compiler_version(); } inline const ::google::protobuf::compiler::Version& CodeGeneratorRequest::compiler_version() const { @@ -1019,6 +1016,13 @@ inline const ::google::protobuf::compiler::Version& CodeGeneratorRequest::compil return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::compiler::Version*>( &::google::protobuf::compiler::_Version_default_instance_); } +inline ::google::protobuf::compiler::Version* CodeGeneratorRequest::release_compiler_version() { + // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorRequest.compiler_version) + clear_has_compiler_version(); + ::google::protobuf::compiler::Version* temp = compiler_version_; + compiler_version_ = NULL; + return temp; +} inline ::google::protobuf::compiler::Version* CodeGeneratorRequest::mutable_compiler_version() { set_has_compiler_version(); if (compiler_version_ == NULL) { @@ -1027,21 +1031,22 @@ inline ::google::protobuf::compiler::Version* CodeGeneratorRequest::mutable_comp // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.CodeGeneratorRequest.compiler_version) return compiler_version_; } -inline ::google::protobuf::compiler::Version* CodeGeneratorRequest::release_compiler_version() { - // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorRequest.compiler_version) - clear_has_compiler_version(); - ::google::protobuf::compiler::Version* temp = compiler_version_; - compiler_version_ = NULL; - return temp; -} inline void CodeGeneratorRequest::set_allocated_compiler_version(::google::protobuf::compiler::Version* compiler_version) { - delete compiler_version_; - compiler_version_ = compiler_version; + ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); + if (message_arena == NULL) { + delete compiler_version_; + } if (compiler_version) { + ::google::protobuf::Arena* submessage_arena = NULL; + if (message_arena != submessage_arena) { + compiler_version = ::google::protobuf::internal::GetOwnedMessage( + message_arena, compiler_version, submessage_arena); + } set_has_compiler_version(); } else { clear_has_compiler_version(); } + compiler_version_ = compiler_version; // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorRequest.compiler_version) } diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index 99f64c99..ab1b4992 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -14,6 +14,10 @@ #include <google/protobuf/generated_message_reflection.h> #include <google/protobuf/reflection_ops.h> #include <google/protobuf/wire_format.h> +// This is a temporary google only hack +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS +#include "third_party/protobuf/version.h" +#endif // @@protoc_insertion_point(includes) namespace google { namespace protobuf { @@ -158,7 +162,11 @@ namespace protobuf_google_2fprotobuf_2fdescriptor_2eproto { void InitDefaultsFileDescriptorSetImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsFileDescriptorProto(); { void* ptr = &::google::protobuf::_FileDescriptorSet_default_instance_; @@ -176,7 +184,11 @@ void InitDefaultsFileDescriptorSet() { void InitDefaultsFileDescriptorProtoImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsDescriptorProto(); protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsEnumDescriptorProto(); protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsServiceDescriptorProto(); @@ -199,7 +211,11 @@ void InitDefaultsFileDescriptorProto() { void InitDefaultsDescriptorProto_ExtensionRangeImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsExtensionRangeOptions(); { void* ptr = &::google::protobuf::_DescriptorProto_ExtensionRange_default_instance_; @@ -217,7 +233,11 @@ void InitDefaultsDescriptorProto_ExtensionRange() { void InitDefaultsDescriptorProto_ReservedRangeImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_DescriptorProto_ReservedRange_default_instance_; new (ptr) ::google::protobuf::DescriptorProto_ReservedRange(); @@ -234,7 +254,11 @@ void InitDefaultsDescriptorProto_ReservedRange() { void InitDefaultsDescriptorProtoImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsFieldDescriptorProto(); protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsEnumDescriptorProto(); protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsDescriptorProto_ExtensionRange(); @@ -257,7 +281,11 @@ void InitDefaultsDescriptorProto() { void InitDefaultsExtensionRangeOptionsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsUninterpretedOption(); { void* ptr = &::google::protobuf::_ExtensionRangeOptions_default_instance_; @@ -275,7 +303,11 @@ void InitDefaultsExtensionRangeOptions() { void InitDefaultsFieldDescriptorProtoImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsFieldOptions(); { void* ptr = &::google::protobuf::_FieldDescriptorProto_default_instance_; @@ -293,7 +325,11 @@ void InitDefaultsFieldDescriptorProto() { void InitDefaultsOneofDescriptorProtoImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsOneofOptions(); { void* ptr = &::google::protobuf::_OneofDescriptorProto_default_instance_; @@ -311,7 +347,11 @@ void InitDefaultsOneofDescriptorProto() { void InitDefaultsEnumDescriptorProto_EnumReservedRangeImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_EnumDescriptorProto_EnumReservedRange_default_instance_; new (ptr) ::google::protobuf::EnumDescriptorProto_EnumReservedRange(); @@ -328,7 +368,11 @@ void InitDefaultsEnumDescriptorProto_EnumReservedRange() { void InitDefaultsEnumDescriptorProtoImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsEnumValueDescriptorProto(); protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsEnumOptions(); protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsEnumDescriptorProto_EnumReservedRange(); @@ -348,7 +392,11 @@ void InitDefaultsEnumDescriptorProto() { void InitDefaultsEnumValueDescriptorProtoImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsEnumValueOptions(); { void* ptr = &::google::protobuf::_EnumValueDescriptorProto_default_instance_; @@ -366,7 +414,11 @@ void InitDefaultsEnumValueDescriptorProto() { void InitDefaultsServiceDescriptorProtoImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsMethodDescriptorProto(); protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsServiceOptions(); { @@ -385,7 +437,11 @@ void InitDefaultsServiceDescriptorProto() { void InitDefaultsMethodDescriptorProtoImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsMethodOptions(); { void* ptr = &::google::protobuf::_MethodDescriptorProto_default_instance_; @@ -403,7 +459,11 @@ void InitDefaultsMethodDescriptorProto() { void InitDefaultsFileOptionsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsUninterpretedOption(); { void* ptr = &::google::protobuf::_FileOptions_default_instance_; @@ -421,7 +481,11 @@ void InitDefaultsFileOptions() { void InitDefaultsMessageOptionsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsUninterpretedOption(); { void* ptr = &::google::protobuf::_MessageOptions_default_instance_; @@ -439,7 +503,11 @@ void InitDefaultsMessageOptions() { void InitDefaultsFieldOptionsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsUninterpretedOption(); { void* ptr = &::google::protobuf::_FieldOptions_default_instance_; @@ -457,7 +525,11 @@ void InitDefaultsFieldOptions() { void InitDefaultsOneofOptionsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsUninterpretedOption(); { void* ptr = &::google::protobuf::_OneofOptions_default_instance_; @@ -475,7 +547,11 @@ void InitDefaultsOneofOptions() { void InitDefaultsEnumOptionsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsUninterpretedOption(); { void* ptr = &::google::protobuf::_EnumOptions_default_instance_; @@ -493,7 +569,11 @@ void InitDefaultsEnumOptions() { void InitDefaultsEnumValueOptionsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsUninterpretedOption(); { void* ptr = &::google::protobuf::_EnumValueOptions_default_instance_; @@ -511,7 +591,11 @@ void InitDefaultsEnumValueOptions() { void InitDefaultsServiceOptionsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsUninterpretedOption(); { void* ptr = &::google::protobuf::_ServiceOptions_default_instance_; @@ -529,7 +613,11 @@ void InitDefaultsServiceOptions() { void InitDefaultsMethodOptionsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsUninterpretedOption(); { void* ptr = &::google::protobuf::_MethodOptions_default_instance_; @@ -547,7 +635,11 @@ void InitDefaultsMethodOptions() { void InitDefaultsUninterpretedOption_NamePartImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_UninterpretedOption_NamePart_default_instance_; new (ptr) ::google::protobuf::UninterpretedOption_NamePart(); @@ -564,7 +656,11 @@ void InitDefaultsUninterpretedOption_NamePart() { void InitDefaultsUninterpretedOptionImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsUninterpretedOption_NamePart(); { void* ptr = &::google::protobuf::_UninterpretedOption_default_instance_; @@ -582,7 +678,11 @@ void InitDefaultsUninterpretedOption() { void InitDefaultsSourceCodeInfo_LocationImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_SourceCodeInfo_Location_default_instance_; new (ptr) ::google::protobuf::SourceCodeInfo_Location(); @@ -599,7 +699,11 @@ void InitDefaultsSourceCodeInfo_Location() { void InitDefaultsSourceCodeInfoImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsSourceCodeInfo_Location(); { void* ptr = &::google::protobuf::_SourceCodeInfo_default_instance_; @@ -617,7 +721,11 @@ void InitDefaultsSourceCodeInfo() { void InitDefaultsGeneratedCodeInfo_AnnotationImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_GeneratedCodeInfo_Annotation_default_instance_; new (ptr) ::google::protobuf::GeneratedCodeInfo_Annotation(); @@ -634,7 +742,11 @@ void InitDefaultsGeneratedCodeInfo_Annotation() { void InitDefaultsGeneratedCodeInfoImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaultsGeneratedCodeInfo_Annotation(); { void* ptr = &::google::protobuf::_GeneratedCodeInfo_default_instance_; @@ -1499,12 +1611,7 @@ FileDescriptorSet::~FileDescriptorSet() { } void FileDescriptorSet::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void FileDescriptorSet::ArenaDtor(void* object) { @@ -1557,8 +1664,7 @@ bool FileDescriptorSet::MergePartialFromCodedStream( case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_file())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_file())); } else { goto handle_unusual; } @@ -1616,7 +1722,7 @@ void FileDescriptorSet::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->file_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 1, this->file(static_cast<int>(i)), deterministic, target); } @@ -1643,7 +1749,7 @@ size_t FileDescriptorSet::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->file(static_cast<int>(i))); } } @@ -1744,29 +1850,6 @@ void FileDescriptorProto::_slow_mutable_options() { options_ = ::google::protobuf::Arena::CreateMessage< ::google::protobuf::FileOptions >( GetArenaNoVirtual()); } -::google::protobuf::FileOptions* FileDescriptorProto::_slow_release_options() { - if (options_ == NULL) { - return NULL; - } else { - ::google::protobuf::FileOptions* temp = new ::google::protobuf::FileOptions(*options_); - options_ = NULL; - return temp; - } -} -void FileDescriptorProto::_slow_set_allocated_options( - ::google::protobuf::Arena* message_arena, ::google::protobuf::FileOptions** options) { - if (message_arena != NULL && - ::google::protobuf::Arena::GetArena(*options) == NULL) { - message_arena->Own(*options); - } else if (message_arena != - ::google::protobuf::Arena::GetArena(*options)) { - ::google::protobuf::FileOptions* new_options = - ::google::protobuf::Arena::CreateMessage< ::google::protobuf::FileOptions >( - message_arena); - new_options->CopyFrom(**options); - *options = new_options; - } -} void FileDescriptorProto::unsafe_arena_set_allocated_options( ::google::protobuf::FileOptions* options) { if (GetArenaNoVirtual() == NULL) { @@ -1784,29 +1867,6 @@ void FileDescriptorProto::_slow_mutable_source_code_info() { source_code_info_ = ::google::protobuf::Arena::CreateMessage< ::google::protobuf::SourceCodeInfo >( GetArenaNoVirtual()); } -::google::protobuf::SourceCodeInfo* FileDescriptorProto::_slow_release_source_code_info() { - if (source_code_info_ == NULL) { - return NULL; - } else { - ::google::protobuf::SourceCodeInfo* temp = new ::google::protobuf::SourceCodeInfo(*source_code_info_); - source_code_info_ = NULL; - return temp; - } -} -void FileDescriptorProto::_slow_set_allocated_source_code_info( - ::google::protobuf::Arena* message_arena, ::google::protobuf::SourceCodeInfo** source_code_info) { - if (message_arena != NULL && - ::google::protobuf::Arena::GetArena(*source_code_info) == NULL) { - message_arena->Own(*source_code_info); - } else if (message_arena != - ::google::protobuf::Arena::GetArena(*source_code_info)) { - ::google::protobuf::SourceCodeInfo* new_source_code_info = - ::google::protobuf::Arena::CreateMessage< ::google::protobuf::SourceCodeInfo >( - message_arena); - new_source_code_info->CopyFrom(**source_code_info); - *source_code_info = new_source_code_info; - } -} void FileDescriptorProto::unsafe_arena_set_allocated_source_code_info( ::google::protobuf::SourceCodeInfo* source_code_info) { if (GetArenaNoVirtual() == NULL) { @@ -1915,15 +1975,10 @@ FileDescriptorProto::~FileDescriptorProto() { } void FileDescriptorProto::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - - name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - package_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - syntax_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); + name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + package_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + syntax_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); if (this != internal_default_instance()) delete options_; if (this != internal_default_instance()) delete source_code_info_; } @@ -1982,11 +2037,11 @@ void FileDescriptorProto::Clear() { } if (cached_has_bits & 0x00000008u) { GOOGLE_DCHECK(options_ != NULL); - options_->::google::protobuf::FileOptions::Clear(); + options_->Clear(); } if (cached_has_bits & 0x00000010u) { GOOGLE_DCHECK(source_code_info_ != NULL); - source_code_info_->::google::protobuf::SourceCodeInfo::Clear(); + source_code_info_->Clear(); } } _has_bits_.Clear(); @@ -2056,8 +2111,7 @@ bool FileDescriptorProto::MergePartialFromCodedStream( case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(34u /* 34 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_message_type())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_message_type())); } else { goto handle_unusual; } @@ -2068,8 +2122,7 @@ bool FileDescriptorProto::MergePartialFromCodedStream( case 5: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(42u /* 42 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_enum_type())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_enum_type())); } else { goto handle_unusual; } @@ -2080,8 +2133,7 @@ bool FileDescriptorProto::MergePartialFromCodedStream( case 6: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(50u /* 50 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_service())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_service())); } else { goto handle_unusual; } @@ -2092,8 +2144,7 @@ bool FileDescriptorProto::MergePartialFromCodedStream( case 7: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(58u /* 58 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_extension())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_extension())); } else { goto handle_unusual; } @@ -2104,7 +2155,7 @@ bool FileDescriptorProto::MergePartialFromCodedStream( case 8: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(66u /* 66 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage( input, mutable_options())); } else { goto handle_unusual; @@ -2116,7 +2167,7 @@ bool FileDescriptorProto::MergePartialFromCodedStream( case 9: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(74u /* 74 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage( input, mutable_source_code_info())); } else { goto handle_unusual; @@ -2348,7 +2399,7 @@ void FileDescriptorProto::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->message_type_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 4, this->message_type(static_cast<int>(i)), deterministic, target); } @@ -2356,7 +2407,7 @@ void FileDescriptorProto::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->enum_type_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 5, this->enum_type(static_cast<int>(i)), deterministic, target); } @@ -2364,7 +2415,7 @@ void FileDescriptorProto::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->service_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 6, this->service(static_cast<int>(i)), deterministic, target); } @@ -2372,21 +2423,21 @@ void FileDescriptorProto::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->extension_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 7, this->extension(static_cast<int>(i)), deterministic, target); } // optional .google.protobuf.FileOptions options = 8; if (cached_has_bits & 0x00000008u) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 8, *this->options_, deterministic, target); } // optional .google.protobuf.SourceCodeInfo source_code_info = 9; if (cached_has_bits & 0x00000010u) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 9, *this->source_code_info_, deterministic, target); } @@ -2440,7 +2491,7 @@ size_t FileDescriptorProto::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->message_type(static_cast<int>(i))); } } @@ -2451,7 +2502,7 @@ size_t FileDescriptorProto::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->enum_type(static_cast<int>(i))); } } @@ -2462,7 +2513,7 @@ size_t FileDescriptorProto::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->service(static_cast<int>(i))); } } @@ -2473,7 +2524,7 @@ size_t FileDescriptorProto::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->extension(static_cast<int>(i))); } } @@ -2521,14 +2572,14 @@ size_t FileDescriptorProto::ByteSizeLong() const { // optional .google.protobuf.FileOptions options = 8; if (has_options()) { total_size += 1 + - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( *this->options_); } // optional .google.protobuf.SourceCodeInfo source_code_info = 9; if (has_source_code_info()) { total_size += 1 + - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( *this->source_code_info_); } @@ -2668,29 +2719,6 @@ void DescriptorProto_ExtensionRange::_slow_mutable_options() { options_ = ::google::protobuf::Arena::CreateMessage< ::google::protobuf::ExtensionRangeOptions >( GetArenaNoVirtual()); } -::google::protobuf::ExtensionRangeOptions* DescriptorProto_ExtensionRange::_slow_release_options() { - if (options_ == NULL) { - return NULL; - } else { - ::google::protobuf::ExtensionRangeOptions* temp = new ::google::protobuf::ExtensionRangeOptions(*options_); - options_ = NULL; - return temp; - } -} -void DescriptorProto_ExtensionRange::_slow_set_allocated_options( - ::google::protobuf::Arena* message_arena, ::google::protobuf::ExtensionRangeOptions** options) { - if (message_arena != NULL && - ::google::protobuf::Arena::GetArena(*options) == NULL) { - message_arena->Own(*options); - } else if (message_arena != - ::google::protobuf::Arena::GetArena(*options)) { - ::google::protobuf::ExtensionRangeOptions* new_options = - ::google::protobuf::Arena::CreateMessage< ::google::protobuf::ExtensionRangeOptions >( - message_arena); - new_options->CopyFrom(**options); - *options = new_options; - } -} void DescriptorProto_ExtensionRange::unsafe_arena_set_allocated_options( ::google::protobuf::ExtensionRangeOptions* options) { if (GetArenaNoVirtual() == NULL) { @@ -2756,12 +2784,7 @@ DescriptorProto_ExtensionRange::~DescriptorProto_ExtensionRange() { } void DescriptorProto_ExtensionRange::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); if (this != internal_default_instance()) delete options_; } @@ -2796,11 +2819,11 @@ void DescriptorProto_ExtensionRange::Clear() { // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; - if (has_options()) { + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 0x00000001u) { GOOGLE_DCHECK(options_ != NULL); - options_->::google::protobuf::ExtensionRangeOptions::Clear(); + options_->Clear(); } - cached_has_bits = _has_bits_[0]; if (cached_has_bits & 6u) { ::memset(&start_, 0, static_cast<size_t>( reinterpret_cast<char*>(&end_) - @@ -2852,7 +2875,7 @@ bool DescriptorProto_ExtensionRange::MergePartialFromCodedStream( case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage( input, mutable_options())); } else { goto handle_unusual; @@ -2931,7 +2954,7 @@ void DescriptorProto_ExtensionRange::SerializeWithCachedSizes( // optional .google.protobuf.ExtensionRangeOptions options = 3; if (cached_has_bits & 0x00000001u) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 3, *this->options_, deterministic, target); } @@ -2956,7 +2979,7 @@ size_t DescriptorProto_ExtensionRange::ByteSizeLong() const { // optional .google.protobuf.ExtensionRangeOptions options = 3; if (has_options()) { total_size += 1 + - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( *this->options_); } @@ -3125,12 +3148,7 @@ DescriptorProto_ReservedRange::~DescriptorProto_ReservedRange() { } void DescriptorProto_ReservedRange::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void DescriptorProto_ReservedRange::ArenaDtor(void* object) { @@ -3410,29 +3428,6 @@ void DescriptorProto::_slow_mutable_options() { options_ = ::google::protobuf::Arena::CreateMessage< ::google::protobuf::MessageOptions >( GetArenaNoVirtual()); } -::google::protobuf::MessageOptions* DescriptorProto::_slow_release_options() { - if (options_ == NULL) { - return NULL; - } else { - ::google::protobuf::MessageOptions* temp = new ::google::protobuf::MessageOptions(*options_); - options_ = NULL; - return temp; - } -} -void DescriptorProto::_slow_set_allocated_options( - ::google::protobuf::Arena* message_arena, ::google::protobuf::MessageOptions** options) { - if (message_arena != NULL && - ::google::protobuf::Arena::GetArena(*options) == NULL) { - message_arena->Own(*options); - } else if (message_arena != - ::google::protobuf::Arena::GetArena(*options)) { - ::google::protobuf::MessageOptions* new_options = - ::google::protobuf::Arena::CreateMessage< ::google::protobuf::MessageOptions >( - message_arena); - new_options->CopyFrom(**options); - *options = new_options; - } -} void DescriptorProto::unsafe_arena_set_allocated_options( ::google::protobuf::MessageOptions* options) { if (GetArenaNoVirtual() == NULL) { @@ -3522,13 +3517,8 @@ DescriptorProto::~DescriptorProto() { } void DescriptorProto::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - - name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); + name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); if (this != internal_default_instance()) delete options_; } @@ -3579,7 +3569,7 @@ void DescriptorProto::Clear() { } if (cached_has_bits & 0x00000002u) { GOOGLE_DCHECK(options_ != NULL); - options_->::google::protobuf::MessageOptions::Clear(); + options_->Clear(); } } _has_bits_.Clear(); @@ -3616,8 +3606,7 @@ bool DescriptorProto::MergePartialFromCodedStream( case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_field())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_field())); } else { goto handle_unusual; } @@ -3628,8 +3617,7 @@ bool DescriptorProto::MergePartialFromCodedStream( case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_nested_type())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_nested_type())); } else { goto handle_unusual; } @@ -3640,8 +3628,7 @@ bool DescriptorProto::MergePartialFromCodedStream( case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(34u /* 34 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_enum_type())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_enum_type())); } else { goto handle_unusual; } @@ -3652,8 +3639,7 @@ bool DescriptorProto::MergePartialFromCodedStream( case 5: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(42u /* 42 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_extension_range())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_extension_range())); } else { goto handle_unusual; } @@ -3664,8 +3650,7 @@ bool DescriptorProto::MergePartialFromCodedStream( case 6: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(50u /* 50 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_extension())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_extension())); } else { goto handle_unusual; } @@ -3676,7 +3661,7 @@ bool DescriptorProto::MergePartialFromCodedStream( case 7: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(58u /* 58 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage( input, mutable_options())); } else { goto handle_unusual; @@ -3688,8 +3673,7 @@ bool DescriptorProto::MergePartialFromCodedStream( case 8: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(66u /* 66 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_oneof_decl())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_oneof_decl())); } else { goto handle_unusual; } @@ -3700,8 +3684,7 @@ bool DescriptorProto::MergePartialFromCodedStream( case 9: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(74u /* 74 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_reserved_range())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_reserved_range())); } else { goto handle_unusual; } @@ -3857,7 +3840,7 @@ void DescriptorProto::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->field_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 2, this->field(static_cast<int>(i)), deterministic, target); } @@ -3865,7 +3848,7 @@ void DescriptorProto::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->nested_type_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 3, this->nested_type(static_cast<int>(i)), deterministic, target); } @@ -3873,7 +3856,7 @@ void DescriptorProto::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->enum_type_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 4, this->enum_type(static_cast<int>(i)), deterministic, target); } @@ -3881,7 +3864,7 @@ void DescriptorProto::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->extension_range_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 5, this->extension_range(static_cast<int>(i)), deterministic, target); } @@ -3889,14 +3872,14 @@ void DescriptorProto::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->extension_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 6, this->extension(static_cast<int>(i)), deterministic, target); } // optional .google.protobuf.MessageOptions options = 7; if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 7, *this->options_, deterministic, target); } @@ -3904,7 +3887,7 @@ void DescriptorProto::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->oneof_decl_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 8, this->oneof_decl(static_cast<int>(i)), deterministic, target); } @@ -3912,7 +3895,7 @@ void DescriptorProto::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->reserved_range_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 9, this->reserved_range(static_cast<int>(i)), deterministic, target); } @@ -3949,7 +3932,7 @@ size_t DescriptorProto::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->field(static_cast<int>(i))); } } @@ -3960,7 +3943,7 @@ size_t DescriptorProto::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->nested_type(static_cast<int>(i))); } } @@ -3971,7 +3954,7 @@ size_t DescriptorProto::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->enum_type(static_cast<int>(i))); } } @@ -3982,7 +3965,7 @@ size_t DescriptorProto::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->extension_range(static_cast<int>(i))); } } @@ -3993,7 +3976,7 @@ size_t DescriptorProto::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->extension(static_cast<int>(i))); } } @@ -4004,7 +3987,7 @@ size_t DescriptorProto::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->oneof_decl(static_cast<int>(i))); } } @@ -4015,7 +3998,7 @@ size_t DescriptorProto::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->reserved_range(static_cast<int>(i))); } } @@ -4039,7 +4022,7 @@ size_t DescriptorProto::ByteSizeLong() const { // optional .google.protobuf.MessageOptions options = 7; if (has_options()) { total_size += 1 + - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( *this->options_); } @@ -4208,12 +4191,7 @@ ExtensionRangeOptions::~ExtensionRangeOptions() { } void ExtensionRangeOptions::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void ExtensionRangeOptions::ArenaDtor(void* object) { @@ -4267,8 +4245,7 @@ bool ExtensionRangeOptions::MergePartialFromCodedStream( case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(58u /* 7994 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_uninterpreted_option())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_uninterpreted_option())); } else { goto handle_unusual; } @@ -4336,7 +4313,7 @@ void ExtensionRangeOptions::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->uninterpreted_option_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 999, this->uninterpreted_option(static_cast<int>(i)), deterministic, target); } @@ -4369,7 +4346,7 @@ size_t ExtensionRangeOptions::ByteSizeLong() const { total_size += 2UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->uninterpreted_option(static_cast<int>(i))); } } @@ -4474,29 +4451,6 @@ void FieldDescriptorProto::_slow_mutable_options() { options_ = ::google::protobuf::Arena::CreateMessage< ::google::protobuf::FieldOptions >( GetArenaNoVirtual()); } -::google::protobuf::FieldOptions* FieldDescriptorProto::_slow_release_options() { - if (options_ == NULL) { - return NULL; - } else { - ::google::protobuf::FieldOptions* temp = new ::google::protobuf::FieldOptions(*options_); - options_ = NULL; - return temp; - } -} -void FieldDescriptorProto::_slow_set_allocated_options( - ::google::protobuf::Arena* message_arena, ::google::protobuf::FieldOptions** options) { - if (message_arena != NULL && - ::google::protobuf::Arena::GetArena(*options) == NULL) { - message_arena->Own(*options); - } else if (message_arena != - ::google::protobuf::Arena::GetArena(*options)) { - ::google::protobuf::FieldOptions* new_options = - ::google::protobuf::Arena::CreateMessage< ::google::protobuf::FieldOptions >( - message_arena); - new_options->CopyFrom(**options); - *options = new_options; - } -} void FieldDescriptorProto::unsafe_arena_set_allocated_options( ::google::protobuf::FieldOptions* options) { if (GetArenaNoVirtual() == NULL) { @@ -4601,17 +4555,12 @@ FieldDescriptorProto::~FieldDescriptorProto() { } void FieldDescriptorProto::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - - name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - extendee_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - type_name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - default_value_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - json_name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); + name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + extendee_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + type_name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + default_value_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + json_name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); if (this != internal_default_instance()) delete options_; } @@ -4670,7 +4619,7 @@ void FieldDescriptorProto::Clear() { } if (cached_has_bits & 0x00000020u) { GOOGLE_DCHECK(options_ != NULL); - options_->::google::protobuf::FieldOptions::Clear(); + options_->Clear(); } } if (cached_has_bits & 192u) { @@ -4818,7 +4767,7 @@ bool FieldDescriptorProto::MergePartialFromCodedStream( case 8: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(66u /* 66 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage( input, mutable_options())); } else { goto handle_unusual; @@ -5040,7 +4989,7 @@ void FieldDescriptorProto::SerializeWithCachedSizes( // optional .google.protobuf.FieldOptions options = 8; if (cached_has_bits & 0x00000020u) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 8, *this->options_, deterministic, target); } @@ -5116,7 +5065,7 @@ size_t FieldDescriptorProto::ByteSizeLong() const { // optional .google.protobuf.FieldOptions options = 8; if (has_options()) { total_size += 1 + - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( *this->options_); } @@ -5290,29 +5239,6 @@ void OneofDescriptorProto::_slow_mutable_options() { options_ = ::google::protobuf::Arena::CreateMessage< ::google::protobuf::OneofOptions >( GetArenaNoVirtual()); } -::google::protobuf::OneofOptions* OneofDescriptorProto::_slow_release_options() { - if (options_ == NULL) { - return NULL; - } else { - ::google::protobuf::OneofOptions* temp = new ::google::protobuf::OneofOptions(*options_); - options_ = NULL; - return temp; - } -} -void OneofDescriptorProto::_slow_set_allocated_options( - ::google::protobuf::Arena* message_arena, ::google::protobuf::OneofOptions** options) { - if (message_arena != NULL && - ::google::protobuf::Arena::GetArena(*options) == NULL) { - message_arena->Own(*options); - } else if (message_arena != - ::google::protobuf::Arena::GetArena(*options)) { - ::google::protobuf::OneofOptions* new_options = - ::google::protobuf::Arena::CreateMessage< ::google::protobuf::OneofOptions >( - message_arena); - new_options->CopyFrom(**options); - *options = new_options; - } -} void OneofDescriptorProto::unsafe_arena_set_allocated_options( ::google::protobuf::OneofOptions* options) { if (GetArenaNoVirtual() == NULL) { @@ -5378,13 +5304,8 @@ OneofDescriptorProto::~OneofDescriptorProto() { } void OneofDescriptorProto::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - - name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); + name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); if (this != internal_default_instance()) delete options_; } @@ -5427,7 +5348,7 @@ void OneofDescriptorProto::Clear() { } if (cached_has_bits & 0x00000002u) { GOOGLE_DCHECK(options_ != NULL); - options_->::google::protobuf::OneofOptions::Clear(); + options_->Clear(); } } _has_bits_.Clear(); @@ -5464,7 +5385,7 @@ bool OneofDescriptorProto::MergePartialFromCodedStream( case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage( input, mutable_options())); } else { goto handle_unusual; @@ -5544,7 +5465,7 @@ void OneofDescriptorProto::SerializeWithCachedSizes( // optional .google.protobuf.OneofOptions options = 2; if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 2, *this->options_, deterministic, target); } @@ -5576,7 +5497,7 @@ size_t OneofDescriptorProto::ByteSizeLong() const { // optional .google.protobuf.OneofOptions options = 2; if (has_options()) { total_size += 1 + - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( *this->options_); } @@ -5726,12 +5647,7 @@ EnumDescriptorProto_EnumReservedRange::~EnumDescriptorProto_EnumReservedRange() } void EnumDescriptorProto_EnumReservedRange::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void EnumDescriptorProto_EnumReservedRange::ArenaDtor(void* object) { @@ -6011,29 +5927,6 @@ void EnumDescriptorProto::_slow_mutable_options() { options_ = ::google::protobuf::Arena::CreateMessage< ::google::protobuf::EnumOptions >( GetArenaNoVirtual()); } -::google::protobuf::EnumOptions* EnumDescriptorProto::_slow_release_options() { - if (options_ == NULL) { - return NULL; - } else { - ::google::protobuf::EnumOptions* temp = new ::google::protobuf::EnumOptions(*options_); - options_ = NULL; - return temp; - } -} -void EnumDescriptorProto::_slow_set_allocated_options( - ::google::protobuf::Arena* message_arena, ::google::protobuf::EnumOptions** options) { - if (message_arena != NULL && - ::google::protobuf::Arena::GetArena(*options) == NULL) { - message_arena->Own(*options); - } else if (message_arena != - ::google::protobuf::Arena::GetArena(*options)) { - ::google::protobuf::EnumOptions* new_options = - ::google::protobuf::Arena::CreateMessage< ::google::protobuf::EnumOptions >( - message_arena); - new_options->CopyFrom(**options); - *options = new_options; - } -} void EnumDescriptorProto::unsafe_arena_set_allocated_options( ::google::protobuf::EnumOptions* options) { if (GetArenaNoVirtual() == NULL) { @@ -6108,13 +6001,8 @@ EnumDescriptorProto::~EnumDescriptorProto() { } void EnumDescriptorProto::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - - name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); + name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); if (this != internal_default_instance()) delete options_; } @@ -6160,7 +6048,7 @@ void EnumDescriptorProto::Clear() { } if (cached_has_bits & 0x00000002u) { GOOGLE_DCHECK(options_ != NULL); - options_->::google::protobuf::EnumOptions::Clear(); + options_->Clear(); } } _has_bits_.Clear(); @@ -6197,8 +6085,7 @@ bool EnumDescriptorProto::MergePartialFromCodedStream( case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_value())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_value())); } else { goto handle_unusual; } @@ -6209,7 +6096,7 @@ bool EnumDescriptorProto::MergePartialFromCodedStream( case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage( input, mutable_options())); } else { goto handle_unusual; @@ -6221,8 +6108,7 @@ bool EnumDescriptorProto::MergePartialFromCodedStream( case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(34u /* 34 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_reserved_range())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_reserved_range())); } else { goto handle_unusual; } @@ -6343,14 +6229,14 @@ void EnumDescriptorProto::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->value_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 2, this->value(static_cast<int>(i)), deterministic, target); } // optional .google.protobuf.EnumOptions options = 3; if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 3, *this->options_, deterministic, target); } @@ -6358,7 +6244,7 @@ void EnumDescriptorProto::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->reserved_range_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 4, this->reserved_range(static_cast<int>(i)), deterministic, target); } @@ -6395,7 +6281,7 @@ size_t EnumDescriptorProto::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->value(static_cast<int>(i))); } } @@ -6406,7 +6292,7 @@ size_t EnumDescriptorProto::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->reserved_range(static_cast<int>(i))); } } @@ -6430,7 +6316,7 @@ size_t EnumDescriptorProto::ByteSizeLong() const { // optional .google.protobuf.EnumOptions options = 3; if (has_options()) { total_size += 1 + - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( *this->options_); } @@ -6547,29 +6433,6 @@ void EnumValueDescriptorProto::_slow_mutable_options() { options_ = ::google::protobuf::Arena::CreateMessage< ::google::protobuf::EnumValueOptions >( GetArenaNoVirtual()); } -::google::protobuf::EnumValueOptions* EnumValueDescriptorProto::_slow_release_options() { - if (options_ == NULL) { - return NULL; - } else { - ::google::protobuf::EnumValueOptions* temp = new ::google::protobuf::EnumValueOptions(*options_); - options_ = NULL; - return temp; - } -} -void EnumValueDescriptorProto::_slow_set_allocated_options( - ::google::protobuf::Arena* message_arena, ::google::protobuf::EnumValueOptions** options) { - if (message_arena != NULL && - ::google::protobuf::Arena::GetArena(*options) == NULL) { - message_arena->Own(*options); - } else if (message_arena != - ::google::protobuf::Arena::GetArena(*options)) { - ::google::protobuf::EnumValueOptions* new_options = - ::google::protobuf::Arena::CreateMessage< ::google::protobuf::EnumValueOptions >( - message_arena); - new_options->CopyFrom(**options); - *options = new_options; - } -} void EnumValueDescriptorProto::unsafe_arena_set_allocated_options( ::google::protobuf::EnumValueOptions* options) { if (GetArenaNoVirtual() == NULL) { @@ -6639,13 +6502,8 @@ EnumValueDescriptorProto::~EnumValueDescriptorProto() { } void EnumValueDescriptorProto::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - - name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); + name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); if (this != internal_default_instance()) delete options_; } @@ -6688,7 +6546,7 @@ void EnumValueDescriptorProto::Clear() { } if (cached_has_bits & 0x00000002u) { GOOGLE_DCHECK(options_ != NULL); - options_->::google::protobuf::EnumValueOptions::Clear(); + options_->Clear(); } } number_ = 0; @@ -6740,7 +6598,7 @@ bool EnumValueDescriptorProto::MergePartialFromCodedStream( case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage( input, mutable_options())); } else { goto handle_unusual; @@ -6830,7 +6688,7 @@ void EnumValueDescriptorProto::SerializeWithCachedSizes( // optional .google.protobuf.EnumValueOptions options = 3; if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 3, *this->options_, deterministic, target); } @@ -6862,7 +6720,7 @@ size_t EnumValueDescriptorProto::ByteSizeLong() const { // optional .google.protobuf.EnumValueOptions options = 3; if (has_options()) { total_size += 1 + - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( *this->options_); } @@ -6984,29 +6842,6 @@ void ServiceDescriptorProto::_slow_mutable_options() { options_ = ::google::protobuf::Arena::CreateMessage< ::google::protobuf::ServiceOptions >( GetArenaNoVirtual()); } -::google::protobuf::ServiceOptions* ServiceDescriptorProto::_slow_release_options() { - if (options_ == NULL) { - return NULL; - } else { - ::google::protobuf::ServiceOptions* temp = new ::google::protobuf::ServiceOptions(*options_); - options_ = NULL; - return temp; - } -} -void ServiceDescriptorProto::_slow_set_allocated_options( - ::google::protobuf::Arena* message_arena, ::google::protobuf::ServiceOptions** options) { - if (message_arena != NULL && - ::google::protobuf::Arena::GetArena(*options) == NULL) { - message_arena->Own(*options); - } else if (message_arena != - ::google::protobuf::Arena::GetArena(*options)) { - ::google::protobuf::ServiceOptions* new_options = - ::google::protobuf::Arena::CreateMessage< ::google::protobuf::ServiceOptions >( - message_arena); - new_options->CopyFrom(**options); - *options = new_options; - } -} void ServiceDescriptorProto::unsafe_arena_set_allocated_options( ::google::protobuf::ServiceOptions* options) { if (GetArenaNoVirtual() == NULL) { @@ -7075,13 +6910,8 @@ ServiceDescriptorProto::~ServiceDescriptorProto() { } void ServiceDescriptorProto::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - - name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); + name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); if (this != internal_default_instance()) delete options_; } @@ -7125,7 +6955,7 @@ void ServiceDescriptorProto::Clear() { } if (cached_has_bits & 0x00000002u) { GOOGLE_DCHECK(options_ != NULL); - options_->::google::protobuf::ServiceOptions::Clear(); + options_->Clear(); } } _has_bits_.Clear(); @@ -7162,8 +6992,7 @@ bool ServiceDescriptorProto::MergePartialFromCodedStream( case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_method())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_method())); } else { goto handle_unusual; } @@ -7174,7 +7003,7 @@ bool ServiceDescriptorProto::MergePartialFromCodedStream( case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage( input, mutable_options())); } else { goto handle_unusual; @@ -7262,14 +7091,14 @@ void ServiceDescriptorProto::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->method_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 2, this->method(static_cast<int>(i)), deterministic, target); } // optional .google.protobuf.ServiceOptions options = 3; if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 3, *this->options_, deterministic, target); } @@ -7296,7 +7125,7 @@ size_t ServiceDescriptorProto::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->method(static_cast<int>(i))); } } @@ -7312,7 +7141,7 @@ size_t ServiceDescriptorProto::ByteSizeLong() const { // optional .google.protobuf.ServiceOptions options = 3; if (has_options()) { total_size += 1 + - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( *this->options_); } @@ -7425,29 +7254,6 @@ void MethodDescriptorProto::_slow_mutable_options() { options_ = ::google::protobuf::Arena::CreateMessage< ::google::protobuf::MethodOptions >( GetArenaNoVirtual()); } -::google::protobuf::MethodOptions* MethodDescriptorProto::_slow_release_options() { - if (options_ == NULL) { - return NULL; - } else { - ::google::protobuf::MethodOptions* temp = new ::google::protobuf::MethodOptions(*options_); - options_ = NULL; - return temp; - } -} -void MethodDescriptorProto::_slow_set_allocated_options( - ::google::protobuf::Arena* message_arena, ::google::protobuf::MethodOptions** options) { - if (message_arena != NULL && - ::google::protobuf::Arena::GetArena(*options) == NULL) { - message_arena->Own(*options); - } else if (message_arena != - ::google::protobuf::Arena::GetArena(*options)) { - ::google::protobuf::MethodOptions* new_options = - ::google::protobuf::Arena::CreateMessage< ::google::protobuf::MethodOptions >( - message_arena); - new_options->CopyFrom(**options); - *options = new_options; - } -} void MethodDescriptorProto::unsafe_arena_set_allocated_options( ::google::protobuf::MethodOptions* options) { if (GetArenaNoVirtual() == NULL) { @@ -7534,15 +7340,10 @@ MethodDescriptorProto::~MethodDescriptorProto() { } void MethodDescriptorProto::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - - name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - input_type_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - output_type_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); + name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + input_type_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + output_type_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); if (this != internal_default_instance()) delete options_; } @@ -7593,7 +7394,7 @@ void MethodDescriptorProto::Clear() { } if (cached_has_bits & 0x00000008u) { GOOGLE_DCHECK(options_ != NULL); - options_->::google::protobuf::MethodOptions::Clear(); + options_->Clear(); } } ::memset(&client_streaming_, 0, static_cast<size_t>( @@ -7665,7 +7466,7 @@ bool MethodDescriptorProto::MergePartialFromCodedStream( case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(34u /* 34 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage( input, mutable_options())); } else { goto handle_unusual; @@ -7825,7 +7626,7 @@ void MethodDescriptorProto::SerializeWithCachedSizes( // optional .google.protobuf.MethodOptions options = 4; if (cached_has_bits & 0x00000008u) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 4, *this->options_, deterministic, target); } @@ -7881,7 +7682,7 @@ size_t MethodDescriptorProto::ByteSizeLong() const { // optional .google.protobuf.MethodOptions options = 4; if (has_options()) { total_size += 1 + - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( *this->options_); } @@ -8128,20 +7929,15 @@ FileOptions::~FileOptions() { } void FileOptions::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - - java_package_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - java_outer_classname_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - go_package_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - objc_class_prefix_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - csharp_namespace_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - swift_prefix_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - php_class_prefix_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - php_namespace_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); + java_package_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + java_outer_classname_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + go_package_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + objc_class_prefix_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + csharp_namespace_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + swift_prefix_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + php_class_prefix_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + php_namespace_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } void FileOptions::ArenaDtor(void* object) { @@ -8513,8 +8309,7 @@ bool FileOptions::MergePartialFromCodedStream( case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(58u /* 7994 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_uninterpreted_option())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_uninterpreted_option())); } else { goto handle_unusual; } @@ -8854,7 +8649,7 @@ void FileOptions::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->uninterpreted_option_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 999, this->uninterpreted_option(static_cast<int>(i)), deterministic, target); } @@ -8887,7 +8682,7 @@ size_t FileOptions::ByteSizeLong() const { total_size += 2UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->uninterpreted_option(static_cast<int>(i))); } } @@ -9233,12 +9028,7 @@ MessageOptions::~MessageOptions() { } void MessageOptions::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void MessageOptions::ArenaDtor(void* object) { @@ -9351,8 +9141,7 @@ bool MessageOptions::MergePartialFromCodedStream( case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(58u /* 7994 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_uninterpreted_option())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_uninterpreted_option())); } else { goto handle_unusual; } @@ -9462,7 +9251,7 @@ void MessageOptions::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->uninterpreted_option_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 999, this->uninterpreted_option(static_cast<int>(i)), deterministic, target); } @@ -9495,7 +9284,7 @@ size_t MessageOptions::ByteSizeLong() const { total_size += 2UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->uninterpreted_option(static_cast<int>(i))); } } @@ -9691,12 +9480,7 @@ FieldOptions::~FieldOptions() { } void FieldOptions::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void FieldOptions::ArenaDtor(void* object) { @@ -9852,8 +9636,7 @@ bool FieldOptions::MergePartialFromCodedStream( case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(58u /* 7994 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_uninterpreted_option())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_uninterpreted_option())); } else { goto handle_unusual; } @@ -9987,7 +9770,7 @@ void FieldOptions::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->uninterpreted_option_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 999, this->uninterpreted_option(static_cast<int>(i)), deterministic, target); } @@ -10020,7 +9803,7 @@ size_t FieldOptions::ByteSizeLong() const { total_size += 2UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->uninterpreted_option(static_cast<int>(i))); } } @@ -10224,12 +10007,7 @@ OneofOptions::~OneofOptions() { } void OneofOptions::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void OneofOptions::ArenaDtor(void* object) { @@ -10283,8 +10061,7 @@ bool OneofOptions::MergePartialFromCodedStream( case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(58u /* 7994 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_uninterpreted_option())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_uninterpreted_option())); } else { goto handle_unusual; } @@ -10352,7 +10129,7 @@ void OneofOptions::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->uninterpreted_option_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 999, this->uninterpreted_option(static_cast<int>(i)), deterministic, target); } @@ -10385,7 +10162,7 @@ size_t OneofOptions::ByteSizeLong() const { total_size += 2UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->uninterpreted_option(static_cast<int>(i))); } } @@ -10535,12 +10312,7 @@ EnumOptions::~EnumOptions() { } void EnumOptions::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void EnumOptions::ArenaDtor(void* object) { @@ -10625,8 +10397,7 @@ bool EnumOptions::MergePartialFromCodedStream( case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(58u /* 7994 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_uninterpreted_option())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_uninterpreted_option())); } else { goto handle_unusual; } @@ -10716,7 +10487,7 @@ void EnumOptions::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->uninterpreted_option_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 999, this->uninterpreted_option(static_cast<int>(i)), deterministic, target); } @@ -10749,7 +10520,7 @@ size_t EnumOptions::ByteSizeLong() const { total_size += 2UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->uninterpreted_option(static_cast<int>(i))); } } @@ -10918,12 +10689,7 @@ EnumValueOptions::~EnumValueOptions() { } void EnumValueOptions::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void EnumValueOptions::ArenaDtor(void* object) { @@ -10992,8 +10758,7 @@ bool EnumValueOptions::MergePartialFromCodedStream( case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(58u /* 7994 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_uninterpreted_option())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_uninterpreted_option())); } else { goto handle_unusual; } @@ -11073,7 +10838,7 @@ void EnumValueOptions::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->uninterpreted_option_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 999, this->uninterpreted_option(static_cast<int>(i)), deterministic, target); } @@ -11106,7 +10871,7 @@ size_t EnumValueOptions::ByteSizeLong() const { total_size += 2UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->uninterpreted_option(static_cast<int>(i))); } } @@ -11260,12 +11025,7 @@ ServiceOptions::~ServiceOptions() { } void ServiceOptions::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void ServiceOptions::ArenaDtor(void* object) { @@ -11334,8 +11094,7 @@ bool ServiceOptions::MergePartialFromCodedStream( case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(58u /* 7994 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_uninterpreted_option())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_uninterpreted_option())); } else { goto handle_unusual; } @@ -11415,7 +11174,7 @@ void ServiceOptions::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->uninterpreted_option_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 999, this->uninterpreted_option(static_cast<int>(i)), deterministic, target); } @@ -11448,7 +11207,7 @@ size_t ServiceOptions::ByteSizeLong() const { total_size += 2UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->uninterpreted_option(static_cast<int>(i))); } } @@ -11607,12 +11366,7 @@ MethodOptions::~MethodOptions() { } void MethodOptions::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void MethodOptions::ArenaDtor(void* object) { @@ -11706,8 +11460,7 @@ bool MethodOptions::MergePartialFromCodedStream( case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(58u /* 7994 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_uninterpreted_option())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_uninterpreted_option())); } else { goto handle_unusual; } @@ -11799,7 +11552,7 @@ void MethodOptions::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->uninterpreted_option_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 999, this->uninterpreted_option(static_cast<int>(i)), deterministic, target); } @@ -11832,7 +11585,7 @@ size_t MethodOptions::ByteSizeLong() const { total_size += 2UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->uninterpreted_option(static_cast<int>(i))); } } @@ -12004,13 +11757,8 @@ UninterpretedOption_NamePart::~UninterpretedOption_NamePart() { } void UninterpretedOption_NamePart::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - - name_part_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); + name_part_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } void UninterpretedOption_NamePart::ArenaDtor(void* object) { @@ -12044,7 +11792,8 @@ void UninterpretedOption_NamePart::Clear() { // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; - if (has_name_part()) { + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 0x00000001u) { GOOGLE_DCHECK(!name_part_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); name_part_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } @@ -12382,15 +12131,10 @@ UninterpretedOption::~UninterpretedOption() { } void UninterpretedOption::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - - identifier_value_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - string_value_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - aggregate_value_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); + identifier_value_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + string_value_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + aggregate_value_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } void UninterpretedOption::ArenaDtor(void* object) { @@ -12463,8 +12207,7 @@ bool UninterpretedOption::MergePartialFromCodedStream( case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_name())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_name())); } else { goto handle_unusual; } @@ -12650,7 +12393,7 @@ void UninterpretedOption::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->name_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 2, this->name(static_cast<int>(i)), deterministic, target); } @@ -12722,7 +12465,7 @@ size_t UninterpretedOption::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->name(static_cast<int>(i))); } } @@ -12946,14 +12689,9 @@ SourceCodeInfo_Location::~SourceCodeInfo_Location() { } void SourceCodeInfo_Location::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - - leading_comments_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - trailing_comments_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); + leading_comments_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + trailing_comments_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } void SourceCodeInfo_Location::ArenaDtor(void* object) { @@ -13470,12 +13208,7 @@ SourceCodeInfo::~SourceCodeInfo() { } void SourceCodeInfo::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void SourceCodeInfo::ArenaDtor(void* object) { @@ -13528,8 +13261,7 @@ bool SourceCodeInfo::MergePartialFromCodedStream( case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_location())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_location())); } else { goto handle_unusual; } @@ -13587,7 +13319,7 @@ void SourceCodeInfo::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->location_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 1, this->location(static_cast<int>(i)), deterministic, target); } @@ -13614,7 +13346,7 @@ size_t SourceCodeInfo::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->location(static_cast<int>(i))); } } @@ -13762,13 +13494,8 @@ GeneratedCodeInfo_Annotation::~GeneratedCodeInfo_Annotation() { } void GeneratedCodeInfo_Annotation::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - - source_file_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); + source_file_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } void GeneratedCodeInfo_Annotation::ArenaDtor(void* object) { @@ -13803,11 +13530,11 @@ void GeneratedCodeInfo_Annotation::Clear() { (void) cached_has_bits; path_.Clear(); - if (has_source_file()) { + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 0x00000001u) { GOOGLE_DCHECK(!source_file_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); source_file_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } - cached_has_bits = _has_bits_[0]; if (cached_has_bits & 6u) { ::memset(&begin_, 0, static_cast<size_t>( reinterpret_cast<char*>(&end_) - @@ -14197,12 +13924,7 @@ GeneratedCodeInfo::~GeneratedCodeInfo() { } void GeneratedCodeInfo::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void GeneratedCodeInfo::ArenaDtor(void* object) { @@ -14255,8 +13977,7 @@ bool GeneratedCodeInfo::MergePartialFromCodedStream( case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_annotation())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_annotation())); } else { goto handle_unusual; } @@ -14314,7 +14035,7 @@ void GeneratedCodeInfo::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->annotation_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 1, this->annotation(static_cast<int>(i)), deterministic, target); } @@ -14341,7 +14062,7 @@ size_t GeneratedCodeInfo::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->annotation(static_cast<int>(i))); } } diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 2b6ba505..ee3ad7d7 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -689,7 +689,13 @@ class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Messag ::std::string* mutable_name(); ::std::string* release_name(); void set_allocated_name(::std::string* name); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_name(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_name( ::std::string* name); @@ -707,7 +713,13 @@ class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Messag ::std::string* mutable_package(); ::std::string* release_package(); void set_allocated_package(::std::string* package); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_package(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_package( ::std::string* package); @@ -725,7 +737,13 @@ class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Messag ::std::string* mutable_syntax(); ::std::string* release_syntax(); void set_allocated_syntax(::std::string* syntax); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_syntax(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_syntax( ::std::string* syntax); @@ -735,17 +753,14 @@ class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Messag static const int kOptionsFieldNumber = 8; private: void _slow_mutable_options(); - void _slow_set_allocated_options( - ::google::protobuf::Arena* message_arena, ::google::protobuf::FileOptions** options); - ::google::protobuf::FileOptions* _slow_release_options(); public: const ::google::protobuf::FileOptions& options() const; - ::google::protobuf::FileOptions* mutable_options(); ::google::protobuf::FileOptions* release_options(); + ::google::protobuf::FileOptions* mutable_options(); void set_allocated_options(::google::protobuf::FileOptions* options); - ::google::protobuf::FileOptions* unsafe_arena_release_options(); void unsafe_arena_set_allocated_options( ::google::protobuf::FileOptions* options); + ::google::protobuf::FileOptions* unsafe_arena_release_options(); // optional .google.protobuf.SourceCodeInfo source_code_info = 9; bool has_source_code_info() const; @@ -753,17 +768,14 @@ class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Messag static const int kSourceCodeInfoFieldNumber = 9; private: void _slow_mutable_source_code_info(); - void _slow_set_allocated_source_code_info( - ::google::protobuf::Arena* message_arena, ::google::protobuf::SourceCodeInfo** source_code_info); - ::google::protobuf::SourceCodeInfo* _slow_release_source_code_info(); public: const ::google::protobuf::SourceCodeInfo& source_code_info() const; - ::google::protobuf::SourceCodeInfo* mutable_source_code_info(); ::google::protobuf::SourceCodeInfo* release_source_code_info(); + ::google::protobuf::SourceCodeInfo* mutable_source_code_info(); void set_allocated_source_code_info(::google::protobuf::SourceCodeInfo* source_code_info); - ::google::protobuf::SourceCodeInfo* unsafe_arena_release_source_code_info(); void unsafe_arena_set_allocated_source_code_info( ::google::protobuf::SourceCodeInfo* source_code_info); + ::google::protobuf::SourceCodeInfo* unsafe_arena_release_source_code_info(); // @@protoc_insertion_point(class_scope:google.protobuf.FileDescriptorProto) private: @@ -908,17 +920,14 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ExtensionRange : public ::google::proto static const int kOptionsFieldNumber = 3; private: void _slow_mutable_options(); - void _slow_set_allocated_options( - ::google::protobuf::Arena* message_arena, ::google::protobuf::ExtensionRangeOptions** options); - ::google::protobuf::ExtensionRangeOptions* _slow_release_options(); public: const ::google::protobuf::ExtensionRangeOptions& options() const; - ::google::protobuf::ExtensionRangeOptions* mutable_options(); ::google::protobuf::ExtensionRangeOptions* release_options(); + ::google::protobuf::ExtensionRangeOptions* mutable_options(); void set_allocated_options(::google::protobuf::ExtensionRangeOptions* options); - ::google::protobuf::ExtensionRangeOptions* unsafe_arena_release_options(); void unsafe_arena_set_allocated_options( ::google::protobuf::ExtensionRangeOptions* options); + ::google::protobuf::ExtensionRangeOptions* unsafe_arena_release_options(); // optional int32 start = 1; bool has_start() const; @@ -1316,7 +1325,13 @@ class LIBPROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message /* ::std::string* mutable_name(); ::std::string* release_name(); void set_allocated_name(::std::string* name); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_name(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_name( ::std::string* name); @@ -1326,17 +1341,14 @@ class LIBPROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message /* static const int kOptionsFieldNumber = 7; private: void _slow_mutable_options(); - void _slow_set_allocated_options( - ::google::protobuf::Arena* message_arena, ::google::protobuf::MessageOptions** options); - ::google::protobuf::MessageOptions* _slow_release_options(); public: const ::google::protobuf::MessageOptions& options() const; - ::google::protobuf::MessageOptions* mutable_options(); ::google::protobuf::MessageOptions* release_options(); + ::google::protobuf::MessageOptions* mutable_options(); void set_allocated_options(::google::protobuf::MessageOptions* options); - ::google::protobuf::MessageOptions* unsafe_arena_release_options(); void unsafe_arena_set_allocated_options( ::google::protobuf::MessageOptions* options); + ::google::protobuf::MessageOptions* unsafe_arena_release_options(); // @@protoc_insertion_point(class_scope:google.protobuf.DescriptorProto) private: @@ -1698,7 +1710,13 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa ::std::string* mutable_name(); ::std::string* release_name(); void set_allocated_name(::std::string* name); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_name(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_name( ::std::string* name); @@ -1716,7 +1734,13 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa ::std::string* mutable_extendee(); ::std::string* release_extendee(); void set_allocated_extendee(::std::string* extendee); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_extendee(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_extendee( ::std::string* extendee); @@ -1734,7 +1758,13 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa ::std::string* mutable_type_name(); ::std::string* release_type_name(); void set_allocated_type_name(::std::string* type_name); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_type_name(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_type_name( ::std::string* type_name); @@ -1752,7 +1782,13 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa ::std::string* mutable_default_value(); ::std::string* release_default_value(); void set_allocated_default_value(::std::string* default_value); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_default_value(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_default_value( ::std::string* default_value); @@ -1770,7 +1806,13 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa ::std::string* mutable_json_name(); ::std::string* release_json_name(); void set_allocated_json_name(::std::string* json_name); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_json_name(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_json_name( ::std::string* json_name); @@ -1780,17 +1822,14 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa static const int kOptionsFieldNumber = 8; private: void _slow_mutable_options(); - void _slow_set_allocated_options( - ::google::protobuf::Arena* message_arena, ::google::protobuf::FieldOptions** options); - ::google::protobuf::FieldOptions* _slow_release_options(); public: const ::google::protobuf::FieldOptions& options() const; - ::google::protobuf::FieldOptions* mutable_options(); ::google::protobuf::FieldOptions* release_options(); + ::google::protobuf::FieldOptions* mutable_options(); void set_allocated_options(::google::protobuf::FieldOptions* options); - ::google::protobuf::FieldOptions* unsafe_arena_release_options(); void unsafe_arena_set_allocated_options( ::google::protobuf::FieldOptions* options); + ::google::protobuf::FieldOptions* unsafe_arena_release_options(); // optional int32 number = 3; bool has_number() const; @@ -1979,7 +2018,13 @@ class LIBPROTOBUF_EXPORT OneofDescriptorProto : public ::google::protobuf::Messa ::std::string* mutable_name(); ::std::string* release_name(); void set_allocated_name(::std::string* name); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_name(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_name( ::std::string* name); @@ -1989,17 +2034,14 @@ class LIBPROTOBUF_EXPORT OneofDescriptorProto : public ::google::protobuf::Messa static const int kOptionsFieldNumber = 2; private: void _slow_mutable_options(); - void _slow_set_allocated_options( - ::google::protobuf::Arena* message_arena, ::google::protobuf::OneofOptions** options); - ::google::protobuf::OneofOptions* _slow_release_options(); public: const ::google::protobuf::OneofOptions& options() const; - ::google::protobuf::OneofOptions* mutable_options(); ::google::protobuf::OneofOptions* release_options(); + ::google::protobuf::OneofOptions* mutable_options(); void set_allocated_options(::google::protobuf::OneofOptions* options); - ::google::protobuf::OneofOptions* unsafe_arena_release_options(); void unsafe_arena_set_allocated_options( ::google::protobuf::OneofOptions* options); + ::google::protobuf::OneofOptions* unsafe_arena_release_options(); // @@protoc_insertion_point(class_scope:google.protobuf.OneofDescriptorProto) private: @@ -2319,7 +2361,13 @@ class LIBPROTOBUF_EXPORT EnumDescriptorProto : public ::google::protobuf::Messag ::std::string* mutable_name(); ::std::string* release_name(); void set_allocated_name(::std::string* name); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_name(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_name( ::std::string* name); @@ -2329,17 +2377,14 @@ class LIBPROTOBUF_EXPORT EnumDescriptorProto : public ::google::protobuf::Messag static const int kOptionsFieldNumber = 3; private: void _slow_mutable_options(); - void _slow_set_allocated_options( - ::google::protobuf::Arena* message_arena, ::google::protobuf::EnumOptions** options); - ::google::protobuf::EnumOptions* _slow_release_options(); public: const ::google::protobuf::EnumOptions& options() const; - ::google::protobuf::EnumOptions* mutable_options(); ::google::protobuf::EnumOptions* release_options(); + ::google::protobuf::EnumOptions* mutable_options(); void set_allocated_options(::google::protobuf::EnumOptions* options); - ::google::protobuf::EnumOptions* unsafe_arena_release_options(); void unsafe_arena_set_allocated_options( ::google::protobuf::EnumOptions* options); + ::google::protobuf::EnumOptions* unsafe_arena_release_options(); // @@protoc_insertion_point(class_scope:google.protobuf.EnumDescriptorProto) private: @@ -2479,7 +2524,13 @@ class LIBPROTOBUF_EXPORT EnumValueDescriptorProto : public ::google::protobuf::M ::std::string* mutable_name(); ::std::string* release_name(); void set_allocated_name(::std::string* name); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_name(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_name( ::std::string* name); @@ -2489,17 +2540,14 @@ class LIBPROTOBUF_EXPORT EnumValueDescriptorProto : public ::google::protobuf::M static const int kOptionsFieldNumber = 3; private: void _slow_mutable_options(); - void _slow_set_allocated_options( - ::google::protobuf::Arena* message_arena, ::google::protobuf::EnumValueOptions** options); - ::google::protobuf::EnumValueOptions* _slow_release_options(); public: const ::google::protobuf::EnumValueOptions& options() const; - ::google::protobuf::EnumValueOptions* mutable_options(); ::google::protobuf::EnumValueOptions* release_options(); + ::google::protobuf::EnumValueOptions* mutable_options(); void set_allocated_options(::google::protobuf::EnumValueOptions* options); - ::google::protobuf::EnumValueOptions* unsafe_arena_release_options(); void unsafe_arena_set_allocated_options( ::google::protobuf::EnumValueOptions* options); + ::google::protobuf::EnumValueOptions* unsafe_arena_release_options(); // optional int32 number = 2; bool has_number() const; @@ -2658,7 +2706,13 @@ class LIBPROTOBUF_EXPORT ServiceDescriptorProto : public ::google::protobuf::Mes ::std::string* mutable_name(); ::std::string* release_name(); void set_allocated_name(::std::string* name); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_name(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_name( ::std::string* name); @@ -2668,17 +2722,14 @@ class LIBPROTOBUF_EXPORT ServiceDescriptorProto : public ::google::protobuf::Mes static const int kOptionsFieldNumber = 3; private: void _slow_mutable_options(); - void _slow_set_allocated_options( - ::google::protobuf::Arena* message_arena, ::google::protobuf::ServiceOptions** options); - ::google::protobuf::ServiceOptions* _slow_release_options(); public: const ::google::protobuf::ServiceOptions& options() const; - ::google::protobuf::ServiceOptions* mutable_options(); ::google::protobuf::ServiceOptions* release_options(); + ::google::protobuf::ServiceOptions* mutable_options(); void set_allocated_options(::google::protobuf::ServiceOptions* options); - ::google::protobuf::ServiceOptions* unsafe_arena_release_options(); void unsafe_arena_set_allocated_options( ::google::protobuf::ServiceOptions* options); + ::google::protobuf::ServiceOptions* unsafe_arena_release_options(); // @@protoc_insertion_point(class_scope:google.protobuf.ServiceDescriptorProto) private: @@ -2816,7 +2867,13 @@ class LIBPROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Mess ::std::string* mutable_name(); ::std::string* release_name(); void set_allocated_name(::std::string* name); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_name(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_name( ::std::string* name); @@ -2834,7 +2891,13 @@ class LIBPROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Mess ::std::string* mutable_input_type(); ::std::string* release_input_type(); void set_allocated_input_type(::std::string* input_type); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_input_type(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_input_type( ::std::string* input_type); @@ -2852,7 +2915,13 @@ class LIBPROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Mess ::std::string* mutable_output_type(); ::std::string* release_output_type(); void set_allocated_output_type(::std::string* output_type); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_output_type(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_output_type( ::std::string* output_type); @@ -2862,17 +2931,14 @@ class LIBPROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Mess static const int kOptionsFieldNumber = 4; private: void _slow_mutable_options(); - void _slow_set_allocated_options( - ::google::protobuf::Arena* message_arena, ::google::protobuf::MethodOptions** options); - ::google::protobuf::MethodOptions* _slow_release_options(); public: const ::google::protobuf::MethodOptions& options() const; - ::google::protobuf::MethodOptions* mutable_options(); ::google::protobuf::MethodOptions* release_options(); + ::google::protobuf::MethodOptions* mutable_options(); void set_allocated_options(::google::protobuf::MethodOptions* options); - ::google::protobuf::MethodOptions* unsafe_arena_release_options(); void unsafe_arena_set_allocated_options( ::google::protobuf::MethodOptions* options); + ::google::protobuf::MethodOptions* unsafe_arena_release_options(); // optional bool client_streaming = 5 [default = false]; bool has_client_streaming() const; @@ -3075,7 +3141,13 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p ::std::string* mutable_java_package(); ::std::string* release_java_package(); void set_allocated_java_package(::std::string* java_package); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_java_package(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_java_package( ::std::string* java_package); @@ -3093,7 +3165,13 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p ::std::string* mutable_java_outer_classname(); ::std::string* release_java_outer_classname(); void set_allocated_java_outer_classname(::std::string* java_outer_classname); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_java_outer_classname(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_java_outer_classname( ::std::string* java_outer_classname); @@ -3111,7 +3189,13 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p ::std::string* mutable_go_package(); ::std::string* release_go_package(); void set_allocated_go_package(::std::string* go_package); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_go_package(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_go_package( ::std::string* go_package); @@ -3129,7 +3213,13 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p ::std::string* mutable_objc_class_prefix(); ::std::string* release_objc_class_prefix(); void set_allocated_objc_class_prefix(::std::string* objc_class_prefix); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_objc_class_prefix(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_objc_class_prefix( ::std::string* objc_class_prefix); @@ -3147,7 +3237,13 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p ::std::string* mutable_csharp_namespace(); ::std::string* release_csharp_namespace(); void set_allocated_csharp_namespace(::std::string* csharp_namespace); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_csharp_namespace(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_csharp_namespace( ::std::string* csharp_namespace); @@ -3165,7 +3261,13 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p ::std::string* mutable_swift_prefix(); ::std::string* release_swift_prefix(); void set_allocated_swift_prefix(::std::string* swift_prefix); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_swift_prefix(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_swift_prefix( ::std::string* swift_prefix); @@ -3183,7 +3285,13 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p ::std::string* mutable_php_class_prefix(); ::std::string* release_php_class_prefix(); void set_allocated_php_class_prefix(::std::string* php_class_prefix); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_php_class_prefix(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_php_class_prefix( ::std::string* php_class_prefix); @@ -3201,7 +3309,13 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p ::std::string* mutable_php_namespace(); ::std::string* release_php_namespace(); void set_allocated_php_namespace(::std::string* php_namespace); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_php_namespace(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_php_namespace( ::std::string* php_namespace); @@ -4623,7 +4737,13 @@ class LIBPROTOBUF_EXPORT UninterpretedOption_NamePart : public ::google::protobu ::std::string* mutable_name_part(); ::std::string* release_name_part(); void set_allocated_name_part(::std::string* name_part); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_name_part(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_name_part( ::std::string* name_part); @@ -4786,7 +4906,13 @@ class LIBPROTOBUF_EXPORT UninterpretedOption : public ::google::protobuf::Messag ::std::string* mutable_identifier_value(); ::std::string* release_identifier_value(); void set_allocated_identifier_value(::std::string* identifier_value); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_identifier_value(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_identifier_value( ::std::string* identifier_value); @@ -4804,7 +4930,13 @@ class LIBPROTOBUF_EXPORT UninterpretedOption : public ::google::protobuf::Messag ::std::string* mutable_string_value(); ::std::string* release_string_value(); void set_allocated_string_value(::std::string* string_value); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_string_value(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_string_value( ::std::string* string_value); @@ -4822,7 +4954,13 @@ class LIBPROTOBUF_EXPORT UninterpretedOption : public ::google::protobuf::Messag ::std::string* mutable_aggregate_value(); ::std::string* release_aggregate_value(); void set_allocated_aggregate_value(::std::string* aggregate_value); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_aggregate_value(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_aggregate_value( ::std::string* aggregate_value); @@ -5041,7 +5179,13 @@ class LIBPROTOBUF_EXPORT SourceCodeInfo_Location : public ::google::protobuf::Me ::std::string* mutable_leading_comments(); ::std::string* release_leading_comments(); void set_allocated_leading_comments(::std::string* leading_comments); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_leading_comments(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_leading_comments( ::std::string* leading_comments); @@ -5059,7 +5203,13 @@ class LIBPROTOBUF_EXPORT SourceCodeInfo_Location : public ::google::protobuf::Me ::std::string* mutable_trailing_comments(); ::std::string* release_trailing_comments(); void set_allocated_trailing_comments(::std::string* trailing_comments); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_trailing_comments(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_trailing_comments( ::std::string* trailing_comments); @@ -5345,7 +5495,13 @@ class LIBPROTOBUF_EXPORT GeneratedCodeInfo_Annotation : public ::google::protobu ::std::string* mutable_source_file(); ::std::string* release_source_file(); void set_allocated_source_file(::std::string* source_file); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_source_file(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_source_file( ::std::string* source_file); @@ -5616,13 +5772,6 @@ inline ::std::string* FileDescriptorProto::release_name() { clear_has_name(); return name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* FileDescriptorProto::unsafe_arena_release_name() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileDescriptorProto.name) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_name(); - return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void FileDescriptorProto::set_allocated_name(::std::string* name) { if (name != NULL) { set_has_name(); @@ -5633,6 +5782,13 @@ inline void FileDescriptorProto::set_allocated_name(::std::string* name) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileDescriptorProto.name) } +inline ::std::string* FileDescriptorProto::unsafe_arena_release_name() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileDescriptorProto.name) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_name(); + return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void FileDescriptorProto::unsafe_arena_set_allocated_name( ::std::string* name) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -5701,13 +5857,6 @@ inline ::std::string* FileDescriptorProto::release_package() { clear_has_package(); return package_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* FileDescriptorProto::unsafe_arena_release_package() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileDescriptorProto.package) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_package(); - return package_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void FileDescriptorProto::set_allocated_package(::std::string* package) { if (package != NULL) { set_has_package(); @@ -5718,6 +5867,13 @@ inline void FileDescriptorProto::set_allocated_package(::std::string* package) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileDescriptorProto.package) } +inline ::std::string* FileDescriptorProto::unsafe_arena_release_package() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileDescriptorProto.package) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_package(); + return package_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void FileDescriptorProto::unsafe_arena_set_allocated_package( ::std::string* package) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -5991,7 +6147,7 @@ inline void FileDescriptorProto::clear_has_options() { _has_bits_[0] &= ~0x00000008u; } inline void FileDescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::FileOptions::Clear(); + if (options_ != NULL) options_->Clear(); clear_has_options(); } inline const ::google::protobuf::FileOptions& FileDescriptorProto::options() const { @@ -6000,6 +6156,23 @@ inline const ::google::protobuf::FileOptions& FileDescriptorProto::options() con return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::FileOptions*>( &::google::protobuf::_FileOptions_default_instance_); } +inline ::google::protobuf::FileOptions* FileDescriptorProto::release_options() { + // @@protoc_insertion_point(field_release:google.protobuf.FileDescriptorProto.options) + clear_has_options(); + ::google::protobuf::FileOptions* temp = options_; + if (GetArenaNoVirtual() != NULL) { + temp = ::google::protobuf::internal::DuplicateIfNonNull(temp, NULL); + } + options_ = NULL; + return temp; +} +inline ::google::protobuf::FileOptions* FileDescriptorProto::unsafe_arena_release_options() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileDescriptorProto.options) + clear_has_options(); + ::google::protobuf::FileOptions* temp = options_; + options_ = NULL; + return temp; +} inline ::google::protobuf::FileOptions* FileDescriptorProto::mutable_options() { set_has_options(); if (options_ == NULL) { @@ -6008,40 +6181,25 @@ inline ::google::protobuf::FileOptions* FileDescriptorProto::mutable_options() { // @@protoc_insertion_point(field_mutable:google.protobuf.FileDescriptorProto.options) return options_; } -inline ::google::protobuf::FileOptions* FileDescriptorProto::release_options() { - // @@protoc_insertion_point(field_release:google.protobuf.FileDescriptorProto.options) - clear_has_options(); - if (GetArenaNoVirtual() != NULL) { - return _slow_release_options(); - } else { - ::google::protobuf::FileOptions* temp = options_; - options_ = NULL; - return temp; - } -} -inline void FileDescriptorProto::set_allocated_options(::google::protobuf::FileOptions* options) { +inline void FileDescriptorProto::set_allocated_options(::google::protobuf::FileOptions* options) { ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); if (message_arena == NULL) { delete options_; } - if (options != NULL) { - _slow_set_allocated_options(message_arena, &options); - } - options_ = options; if (options) { + ::google::protobuf::Arena* submessage_arena = + ::google::protobuf::Arena::GetArena(options); + if (message_arena != submessage_arena) { + options = ::google::protobuf::internal::GetOwnedMessage( + message_arena, options, submessage_arena); + } set_has_options(); } else { clear_has_options(); } + options_ = options; // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileDescriptorProto.options) } -inline ::google::protobuf::FileOptions* FileDescriptorProto::unsafe_arena_release_options() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileDescriptorProto.options) - clear_has_options(); - ::google::protobuf::FileOptions* temp = options_; - options_ = NULL; - return temp; -} // optional .google.protobuf.SourceCodeInfo source_code_info = 9; inline bool FileDescriptorProto::has_source_code_info() const { @@ -6054,7 +6212,7 @@ inline void FileDescriptorProto::clear_has_source_code_info() { _has_bits_[0] &= ~0x00000010u; } inline void FileDescriptorProto::clear_source_code_info() { - if (source_code_info_ != NULL) source_code_info_->::google::protobuf::SourceCodeInfo::Clear(); + if (source_code_info_ != NULL) source_code_info_->Clear(); clear_has_source_code_info(); } inline const ::google::protobuf::SourceCodeInfo& FileDescriptorProto::source_code_info() const { @@ -6063,6 +6221,23 @@ inline const ::google::protobuf::SourceCodeInfo& FileDescriptorProto::source_cod return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::SourceCodeInfo*>( &::google::protobuf::_SourceCodeInfo_default_instance_); } +inline ::google::protobuf::SourceCodeInfo* FileDescriptorProto::release_source_code_info() { + // @@protoc_insertion_point(field_release:google.protobuf.FileDescriptorProto.source_code_info) + clear_has_source_code_info(); + ::google::protobuf::SourceCodeInfo* temp = source_code_info_; + if (GetArenaNoVirtual() != NULL) { + temp = ::google::protobuf::internal::DuplicateIfNonNull(temp, NULL); + } + source_code_info_ = NULL; + return temp; +} +inline ::google::protobuf::SourceCodeInfo* FileDescriptorProto::unsafe_arena_release_source_code_info() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileDescriptorProto.source_code_info) + clear_has_source_code_info(); + ::google::protobuf::SourceCodeInfo* temp = source_code_info_; + source_code_info_ = NULL; + return temp; +} inline ::google::protobuf::SourceCodeInfo* FileDescriptorProto::mutable_source_code_info() { set_has_source_code_info(); if (source_code_info_ == NULL) { @@ -6071,40 +6246,25 @@ inline ::google::protobuf::SourceCodeInfo* FileDescriptorProto::mutable_source_c // @@protoc_insertion_point(field_mutable:google.protobuf.FileDescriptorProto.source_code_info) return source_code_info_; } -inline ::google::protobuf::SourceCodeInfo* FileDescriptorProto::release_source_code_info() { - // @@protoc_insertion_point(field_release:google.protobuf.FileDescriptorProto.source_code_info) - clear_has_source_code_info(); - if (GetArenaNoVirtual() != NULL) { - return _slow_release_source_code_info(); - } else { - ::google::protobuf::SourceCodeInfo* temp = source_code_info_; - source_code_info_ = NULL; - return temp; - } -} -inline void FileDescriptorProto::set_allocated_source_code_info(::google::protobuf::SourceCodeInfo* source_code_info) { +inline void FileDescriptorProto::set_allocated_source_code_info(::google::protobuf::SourceCodeInfo* source_code_info) { ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); if (message_arena == NULL) { delete source_code_info_; } - if (source_code_info != NULL) { - _slow_set_allocated_source_code_info(message_arena, &source_code_info); - } - source_code_info_ = source_code_info; if (source_code_info) { + ::google::protobuf::Arena* submessage_arena = + ::google::protobuf::Arena::GetArena(source_code_info); + if (message_arena != submessage_arena) { + source_code_info = ::google::protobuf::internal::GetOwnedMessage( + message_arena, source_code_info, submessage_arena); + } set_has_source_code_info(); } else { clear_has_source_code_info(); } + source_code_info_ = source_code_info; // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileDescriptorProto.source_code_info) } -inline ::google::protobuf::SourceCodeInfo* FileDescriptorProto::unsafe_arena_release_source_code_info() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileDescriptorProto.source_code_info) - clear_has_source_code_info(); - ::google::protobuf::SourceCodeInfo* temp = source_code_info_; - source_code_info_ = NULL; - return temp; -} // optional string syntax = 12; inline bool FileDescriptorProto::has_syntax() const { @@ -6161,13 +6321,6 @@ inline ::std::string* FileDescriptorProto::release_syntax() { clear_has_syntax(); return syntax_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* FileDescriptorProto::unsafe_arena_release_syntax() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileDescriptorProto.syntax) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_syntax(); - return syntax_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void FileDescriptorProto::set_allocated_syntax(::std::string* syntax) { if (syntax != NULL) { set_has_syntax(); @@ -6178,6 +6331,13 @@ inline void FileDescriptorProto::set_allocated_syntax(::std::string* syntax) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileDescriptorProto.syntax) } +inline ::std::string* FileDescriptorProto::unsafe_arena_release_syntax() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileDescriptorProto.syntax) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_syntax(); + return syntax_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void FileDescriptorProto::unsafe_arena_set_allocated_syntax( ::std::string* syntax) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -6254,7 +6414,7 @@ inline void DescriptorProto_ExtensionRange::clear_has_options() { _has_bits_[0] &= ~0x00000001u; } inline void DescriptorProto_ExtensionRange::clear_options() { - if (options_ != NULL) options_->::google::protobuf::ExtensionRangeOptions::Clear(); + if (options_ != NULL) options_->Clear(); clear_has_options(); } inline const ::google::protobuf::ExtensionRangeOptions& DescriptorProto_ExtensionRange::options() const { @@ -6263,6 +6423,23 @@ inline const ::google::protobuf::ExtensionRangeOptions& DescriptorProto_Extensio return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::ExtensionRangeOptions*>( &::google::protobuf::_ExtensionRangeOptions_default_instance_); } +inline ::google::protobuf::ExtensionRangeOptions* DescriptorProto_ExtensionRange::release_options() { + // @@protoc_insertion_point(field_release:google.protobuf.DescriptorProto.ExtensionRange.options) + clear_has_options(); + ::google::protobuf::ExtensionRangeOptions* temp = options_; + if (GetArenaNoVirtual() != NULL) { + temp = ::google::protobuf::internal::DuplicateIfNonNull(temp, NULL); + } + options_ = NULL; + return temp; +} +inline ::google::protobuf::ExtensionRangeOptions* DescriptorProto_ExtensionRange::unsafe_arena_release_options() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.DescriptorProto.ExtensionRange.options) + clear_has_options(); + ::google::protobuf::ExtensionRangeOptions* temp = options_; + options_ = NULL; + return temp; +} inline ::google::protobuf::ExtensionRangeOptions* DescriptorProto_ExtensionRange::mutable_options() { set_has_options(); if (options_ == NULL) { @@ -6271,40 +6448,25 @@ inline ::google::protobuf::ExtensionRangeOptions* DescriptorProto_ExtensionRange // @@protoc_insertion_point(field_mutable:google.protobuf.DescriptorProto.ExtensionRange.options) return options_; } -inline ::google::protobuf::ExtensionRangeOptions* DescriptorProto_ExtensionRange::release_options() { - // @@protoc_insertion_point(field_release:google.protobuf.DescriptorProto.ExtensionRange.options) - clear_has_options(); - if (GetArenaNoVirtual() != NULL) { - return _slow_release_options(); - } else { - ::google::protobuf::ExtensionRangeOptions* temp = options_; - options_ = NULL; - return temp; - } -} -inline void DescriptorProto_ExtensionRange::set_allocated_options(::google::protobuf::ExtensionRangeOptions* options) { +inline void DescriptorProto_ExtensionRange::set_allocated_options(::google::protobuf::ExtensionRangeOptions* options) { ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); if (message_arena == NULL) { delete options_; } - if (options != NULL) { - _slow_set_allocated_options(message_arena, &options); - } - options_ = options; if (options) { + ::google::protobuf::Arena* submessage_arena = + ::google::protobuf::Arena::GetArena(options); + if (message_arena != submessage_arena) { + options = ::google::protobuf::internal::GetOwnedMessage( + message_arena, options, submessage_arena); + } set_has_options(); } else { clear_has_options(); } + options_ = options; // @@protoc_insertion_point(field_set_allocated:google.protobuf.DescriptorProto.ExtensionRange.options) } -inline ::google::protobuf::ExtensionRangeOptions* DescriptorProto_ExtensionRange::unsafe_arena_release_options() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.DescriptorProto.ExtensionRange.options) - clear_has_options(); - ::google::protobuf::ExtensionRangeOptions* temp = options_; - options_ = NULL; - return temp; -} // ------------------------------------------------------------------- @@ -6417,13 +6579,6 @@ inline ::std::string* DescriptorProto::release_name() { clear_has_name(); return name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* DescriptorProto::unsafe_arena_release_name() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.DescriptorProto.name) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_name(); - return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void DescriptorProto::set_allocated_name(::std::string* name) { if (name != NULL) { set_has_name(); @@ -6434,6 +6589,13 @@ inline void DescriptorProto::set_allocated_name(::std::string* name) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.DescriptorProto.name) } +inline ::std::string* DescriptorProto::unsafe_arena_release_name() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.DescriptorProto.name) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_name(); + return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void DescriptorProto::unsafe_arena_set_allocated_name( ::std::string* name) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -6638,7 +6800,7 @@ inline void DescriptorProto::clear_has_options() { _has_bits_[0] &= ~0x00000002u; } inline void DescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::MessageOptions::Clear(); + if (options_ != NULL) options_->Clear(); clear_has_options(); } inline const ::google::protobuf::MessageOptions& DescriptorProto::options() const { @@ -6647,6 +6809,23 @@ inline const ::google::protobuf::MessageOptions& DescriptorProto::options() cons return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::MessageOptions*>( &::google::protobuf::_MessageOptions_default_instance_); } +inline ::google::protobuf::MessageOptions* DescriptorProto::release_options() { + // @@protoc_insertion_point(field_release:google.protobuf.DescriptorProto.options) + clear_has_options(); + ::google::protobuf::MessageOptions* temp = options_; + if (GetArenaNoVirtual() != NULL) { + temp = ::google::protobuf::internal::DuplicateIfNonNull(temp, NULL); + } + options_ = NULL; + return temp; +} +inline ::google::protobuf::MessageOptions* DescriptorProto::unsafe_arena_release_options() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.DescriptorProto.options) + clear_has_options(); + ::google::protobuf::MessageOptions* temp = options_; + options_ = NULL; + return temp; +} inline ::google::protobuf::MessageOptions* DescriptorProto::mutable_options() { set_has_options(); if (options_ == NULL) { @@ -6655,40 +6834,25 @@ inline ::google::protobuf::MessageOptions* DescriptorProto::mutable_options() { // @@protoc_insertion_point(field_mutable:google.protobuf.DescriptorProto.options) return options_; } -inline ::google::protobuf::MessageOptions* DescriptorProto::release_options() { - // @@protoc_insertion_point(field_release:google.protobuf.DescriptorProto.options) - clear_has_options(); - if (GetArenaNoVirtual() != NULL) { - return _slow_release_options(); - } else { - ::google::protobuf::MessageOptions* temp = options_; - options_ = NULL; - return temp; - } -} -inline void DescriptorProto::set_allocated_options(::google::protobuf::MessageOptions* options) { +inline void DescriptorProto::set_allocated_options(::google::protobuf::MessageOptions* options) { ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); if (message_arena == NULL) { delete options_; } - if (options != NULL) { - _slow_set_allocated_options(message_arena, &options); - } - options_ = options; if (options) { + ::google::protobuf::Arena* submessage_arena = + ::google::protobuf::Arena::GetArena(options); + if (message_arena != submessage_arena) { + options = ::google::protobuf::internal::GetOwnedMessage( + message_arena, options, submessage_arena); + } set_has_options(); } else { clear_has_options(); } + options_ = options; // @@protoc_insertion_point(field_set_allocated:google.protobuf.DescriptorProto.options) } -inline ::google::protobuf::MessageOptions* DescriptorProto::unsafe_arena_release_options() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.DescriptorProto.options) - clear_has_options(); - ::google::protobuf::MessageOptions* temp = options_; - options_ = NULL; - return temp; -} // repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9; inline int DescriptorProto::reserved_range_size() const { @@ -6882,13 +7046,6 @@ inline ::std::string* FieldDescriptorProto::release_name() { clear_has_name(); return name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* FieldDescriptorProto::unsafe_arena_release_name() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FieldDescriptorProto.name) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_name(); - return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void FieldDescriptorProto::set_allocated_name(::std::string* name) { if (name != NULL) { set_has_name(); @@ -6899,6 +7056,13 @@ inline void FieldDescriptorProto::set_allocated_name(::std::string* name) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.FieldDescriptorProto.name) } +inline ::std::string* FieldDescriptorProto::unsafe_arena_release_name() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FieldDescriptorProto.name) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_name(); + return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void FieldDescriptorProto::unsafe_arena_set_allocated_name( ::std::string* name) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -7041,13 +7205,6 @@ inline ::std::string* FieldDescriptorProto::release_type_name() { clear_has_type_name(); return type_name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* FieldDescriptorProto::unsafe_arena_release_type_name() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FieldDescriptorProto.type_name) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_type_name(); - return type_name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void FieldDescriptorProto::set_allocated_type_name(::std::string* type_name) { if (type_name != NULL) { set_has_type_name(); @@ -7058,6 +7215,13 @@ inline void FieldDescriptorProto::set_allocated_type_name(::std::string* type_na GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.FieldDescriptorProto.type_name) } +inline ::std::string* FieldDescriptorProto::unsafe_arena_release_type_name() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FieldDescriptorProto.type_name) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_type_name(); + return type_name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void FieldDescriptorProto::unsafe_arena_set_allocated_type_name( ::std::string* type_name) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -7126,13 +7290,6 @@ inline ::std::string* FieldDescriptorProto::release_extendee() { clear_has_extendee(); return extendee_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* FieldDescriptorProto::unsafe_arena_release_extendee() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FieldDescriptorProto.extendee) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_extendee(); - return extendee_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void FieldDescriptorProto::set_allocated_extendee(::std::string* extendee) { if (extendee != NULL) { set_has_extendee(); @@ -7143,6 +7300,13 @@ inline void FieldDescriptorProto::set_allocated_extendee(::std::string* extendee GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.FieldDescriptorProto.extendee) } +inline ::std::string* FieldDescriptorProto::unsafe_arena_release_extendee() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FieldDescriptorProto.extendee) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_extendee(); + return extendee_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void FieldDescriptorProto::unsafe_arena_set_allocated_extendee( ::std::string* extendee) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -7211,13 +7375,6 @@ inline ::std::string* FieldDescriptorProto::release_default_value() { clear_has_default_value(); return default_value_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* FieldDescriptorProto::unsafe_arena_release_default_value() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FieldDescriptorProto.default_value) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_default_value(); - return default_value_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void FieldDescriptorProto::set_allocated_default_value(::std::string* default_value) { if (default_value != NULL) { set_has_default_value(); @@ -7228,6 +7385,13 @@ inline void FieldDescriptorProto::set_allocated_default_value(::std::string* def GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.FieldDescriptorProto.default_value) } +inline ::std::string* FieldDescriptorProto::unsafe_arena_release_default_value() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FieldDescriptorProto.default_value) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_default_value(); + return default_value_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void FieldDescriptorProto::unsafe_arena_set_allocated_default_value( ::std::string* default_value) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -7320,13 +7484,6 @@ inline ::std::string* FieldDescriptorProto::release_json_name() { clear_has_json_name(); return json_name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* FieldDescriptorProto::unsafe_arena_release_json_name() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FieldDescriptorProto.json_name) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_json_name(); - return json_name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void FieldDescriptorProto::set_allocated_json_name(::std::string* json_name) { if (json_name != NULL) { set_has_json_name(); @@ -7337,6 +7494,13 @@ inline void FieldDescriptorProto::set_allocated_json_name(::std::string* json_na GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.FieldDescriptorProto.json_name) } +inline ::std::string* FieldDescriptorProto::unsafe_arena_release_json_name() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FieldDescriptorProto.json_name) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_json_name(); + return json_name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void FieldDescriptorProto::unsafe_arena_set_allocated_json_name( ::std::string* json_name) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -7361,7 +7525,7 @@ inline void FieldDescriptorProto::clear_has_options() { _has_bits_[0] &= ~0x00000020u; } inline void FieldDescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::FieldOptions::Clear(); + if (options_ != NULL) options_->Clear(); clear_has_options(); } inline const ::google::protobuf::FieldOptions& FieldDescriptorProto::options() const { @@ -7370,6 +7534,23 @@ inline const ::google::protobuf::FieldOptions& FieldDescriptorProto::options() c return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::FieldOptions*>( &::google::protobuf::_FieldOptions_default_instance_); } +inline ::google::protobuf::FieldOptions* FieldDescriptorProto::release_options() { + // @@protoc_insertion_point(field_release:google.protobuf.FieldDescriptorProto.options) + clear_has_options(); + ::google::protobuf::FieldOptions* temp = options_; + if (GetArenaNoVirtual() != NULL) { + temp = ::google::protobuf::internal::DuplicateIfNonNull(temp, NULL); + } + options_ = NULL; + return temp; +} +inline ::google::protobuf::FieldOptions* FieldDescriptorProto::unsafe_arena_release_options() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FieldDescriptorProto.options) + clear_has_options(); + ::google::protobuf::FieldOptions* temp = options_; + options_ = NULL; + return temp; +} inline ::google::protobuf::FieldOptions* FieldDescriptorProto::mutable_options() { set_has_options(); if (options_ == NULL) { @@ -7378,40 +7559,25 @@ inline ::google::protobuf::FieldOptions* FieldDescriptorProto::mutable_options() // @@protoc_insertion_point(field_mutable:google.protobuf.FieldDescriptorProto.options) return options_; } -inline ::google::protobuf::FieldOptions* FieldDescriptorProto::release_options() { - // @@protoc_insertion_point(field_release:google.protobuf.FieldDescriptorProto.options) - clear_has_options(); - if (GetArenaNoVirtual() != NULL) { - return _slow_release_options(); - } else { - ::google::protobuf::FieldOptions* temp = options_; - options_ = NULL; - return temp; - } -} -inline void FieldDescriptorProto::set_allocated_options(::google::protobuf::FieldOptions* options) { +inline void FieldDescriptorProto::set_allocated_options(::google::protobuf::FieldOptions* options) { ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); if (message_arena == NULL) { delete options_; } - if (options != NULL) { - _slow_set_allocated_options(message_arena, &options); - } - options_ = options; if (options) { + ::google::protobuf::Arena* submessage_arena = + ::google::protobuf::Arena::GetArena(options); + if (message_arena != submessage_arena) { + options = ::google::protobuf::internal::GetOwnedMessage( + message_arena, options, submessage_arena); + } set_has_options(); } else { clear_has_options(); } + options_ = options; // @@protoc_insertion_point(field_set_allocated:google.protobuf.FieldDescriptorProto.options) } -inline ::google::protobuf::FieldOptions* FieldDescriptorProto::unsafe_arena_release_options() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FieldDescriptorProto.options) - clear_has_options(); - ::google::protobuf::FieldOptions* temp = options_; - options_ = NULL; - return temp; -} // ------------------------------------------------------------------- @@ -7472,13 +7638,6 @@ inline ::std::string* OneofDescriptorProto::release_name() { clear_has_name(); return name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* OneofDescriptorProto::unsafe_arena_release_name() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.OneofDescriptorProto.name) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_name(); - return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void OneofDescriptorProto::set_allocated_name(::std::string* name) { if (name != NULL) { set_has_name(); @@ -7489,6 +7648,13 @@ inline void OneofDescriptorProto::set_allocated_name(::std::string* name) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.OneofDescriptorProto.name) } +inline ::std::string* OneofDescriptorProto::unsafe_arena_release_name() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.OneofDescriptorProto.name) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_name(); + return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void OneofDescriptorProto::unsafe_arena_set_allocated_name( ::std::string* name) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -7513,7 +7679,7 @@ inline void OneofDescriptorProto::clear_has_options() { _has_bits_[0] &= ~0x00000002u; } inline void OneofDescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::OneofOptions::Clear(); + if (options_ != NULL) options_->Clear(); clear_has_options(); } inline const ::google::protobuf::OneofOptions& OneofDescriptorProto::options() const { @@ -7522,6 +7688,23 @@ inline const ::google::protobuf::OneofOptions& OneofDescriptorProto::options() c return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::OneofOptions*>( &::google::protobuf::_OneofOptions_default_instance_); } +inline ::google::protobuf::OneofOptions* OneofDescriptorProto::release_options() { + // @@protoc_insertion_point(field_release:google.protobuf.OneofDescriptorProto.options) + clear_has_options(); + ::google::protobuf::OneofOptions* temp = options_; + if (GetArenaNoVirtual() != NULL) { + temp = ::google::protobuf::internal::DuplicateIfNonNull(temp, NULL); + } + options_ = NULL; + return temp; +} +inline ::google::protobuf::OneofOptions* OneofDescriptorProto::unsafe_arena_release_options() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.OneofDescriptorProto.options) + clear_has_options(); + ::google::protobuf::OneofOptions* temp = options_; + options_ = NULL; + return temp; +} inline ::google::protobuf::OneofOptions* OneofDescriptorProto::mutable_options() { set_has_options(); if (options_ == NULL) { @@ -7530,40 +7713,25 @@ inline ::google::protobuf::OneofOptions* OneofDescriptorProto::mutable_options() // @@protoc_insertion_point(field_mutable:google.protobuf.OneofDescriptorProto.options) return options_; } -inline ::google::protobuf::OneofOptions* OneofDescriptorProto::release_options() { - // @@protoc_insertion_point(field_release:google.protobuf.OneofDescriptorProto.options) - clear_has_options(); - if (GetArenaNoVirtual() != NULL) { - return _slow_release_options(); - } else { - ::google::protobuf::OneofOptions* temp = options_; - options_ = NULL; - return temp; - } -} -inline void OneofDescriptorProto::set_allocated_options(::google::protobuf::OneofOptions* options) { +inline void OneofDescriptorProto::set_allocated_options(::google::protobuf::OneofOptions* options) { ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); if (message_arena == NULL) { delete options_; } - if (options != NULL) { - _slow_set_allocated_options(message_arena, &options); - } - options_ = options; if (options) { + ::google::protobuf::Arena* submessage_arena = + ::google::protobuf::Arena::GetArena(options); + if (message_arena != submessage_arena) { + options = ::google::protobuf::internal::GetOwnedMessage( + message_arena, options, submessage_arena); + } set_has_options(); } else { clear_has_options(); } + options_ = options; // @@protoc_insertion_point(field_set_allocated:google.protobuf.OneofDescriptorProto.options) } -inline ::google::protobuf::OneofOptions* OneofDescriptorProto::unsafe_arena_release_options() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.OneofDescriptorProto.options) - clear_has_options(); - ::google::protobuf::OneofOptions* temp = options_; - options_ = NULL; - return temp; -} // ------------------------------------------------------------------- @@ -7676,13 +7844,6 @@ inline ::std::string* EnumDescriptorProto::release_name() { clear_has_name(); return name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* EnumDescriptorProto::unsafe_arena_release_name() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.EnumDescriptorProto.name) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_name(); - return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void EnumDescriptorProto::set_allocated_name(::std::string* name) { if (name != NULL) { set_has_name(); @@ -7693,6 +7854,13 @@ inline void EnumDescriptorProto::set_allocated_name(::std::string* name) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.EnumDescriptorProto.name) } +inline ::std::string* EnumDescriptorProto::unsafe_arena_release_name() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.EnumDescriptorProto.name) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_name(); + return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void EnumDescriptorProto::unsafe_arena_set_allocated_name( ::std::string* name) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -7747,7 +7915,7 @@ inline void EnumDescriptorProto::clear_has_options() { _has_bits_[0] &= ~0x00000002u; } inline void EnumDescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::EnumOptions::Clear(); + if (options_ != NULL) options_->Clear(); clear_has_options(); } inline const ::google::protobuf::EnumOptions& EnumDescriptorProto::options() const { @@ -7756,6 +7924,23 @@ inline const ::google::protobuf::EnumOptions& EnumDescriptorProto::options() con return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::EnumOptions*>( &::google::protobuf::_EnumOptions_default_instance_); } +inline ::google::protobuf::EnumOptions* EnumDescriptorProto::release_options() { + // @@protoc_insertion_point(field_release:google.protobuf.EnumDescriptorProto.options) + clear_has_options(); + ::google::protobuf::EnumOptions* temp = options_; + if (GetArenaNoVirtual() != NULL) { + temp = ::google::protobuf::internal::DuplicateIfNonNull(temp, NULL); + } + options_ = NULL; + return temp; +} +inline ::google::protobuf::EnumOptions* EnumDescriptorProto::unsafe_arena_release_options() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.EnumDescriptorProto.options) + clear_has_options(); + ::google::protobuf::EnumOptions* temp = options_; + options_ = NULL; + return temp; +} inline ::google::protobuf::EnumOptions* EnumDescriptorProto::mutable_options() { set_has_options(); if (options_ == NULL) { @@ -7764,40 +7949,25 @@ inline ::google::protobuf::EnumOptions* EnumDescriptorProto::mutable_options() { // @@protoc_insertion_point(field_mutable:google.protobuf.EnumDescriptorProto.options) return options_; } -inline ::google::protobuf::EnumOptions* EnumDescriptorProto::release_options() { - // @@protoc_insertion_point(field_release:google.protobuf.EnumDescriptorProto.options) - clear_has_options(); - if (GetArenaNoVirtual() != NULL) { - return _slow_release_options(); - } else { - ::google::protobuf::EnumOptions* temp = options_; - options_ = NULL; - return temp; - } -} -inline void EnumDescriptorProto::set_allocated_options(::google::protobuf::EnumOptions* options) { +inline void EnumDescriptorProto::set_allocated_options(::google::protobuf::EnumOptions* options) { ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); if (message_arena == NULL) { delete options_; } - if (options != NULL) { - _slow_set_allocated_options(message_arena, &options); - } - options_ = options; if (options) { + ::google::protobuf::Arena* submessage_arena = + ::google::protobuf::Arena::GetArena(options); + if (message_arena != submessage_arena) { + options = ::google::protobuf::internal::GetOwnedMessage( + message_arena, options, submessage_arena); + } set_has_options(); } else { clear_has_options(); } + options_ = options; // @@protoc_insertion_point(field_set_allocated:google.protobuf.EnumDescriptorProto.options) } -inline ::google::protobuf::EnumOptions* EnumDescriptorProto::unsafe_arena_release_options() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.EnumDescriptorProto.options) - clear_has_options(); - ::google::protobuf::EnumOptions* temp = options_; - options_ = NULL; - return temp; -} // repeated .google.protobuf.EnumDescriptorProto.EnumReservedRange reserved_range = 4; inline int EnumDescriptorProto::reserved_range_size() const { @@ -7957,13 +8127,6 @@ inline ::std::string* EnumValueDescriptorProto::release_name() { clear_has_name(); return name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* EnumValueDescriptorProto::unsafe_arena_release_name() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.EnumValueDescriptorProto.name) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_name(); - return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void EnumValueDescriptorProto::set_allocated_name(::std::string* name) { if (name != NULL) { set_has_name(); @@ -7974,6 +8137,13 @@ inline void EnumValueDescriptorProto::set_allocated_name(::std::string* name) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.EnumValueDescriptorProto.name) } +inline ::std::string* EnumValueDescriptorProto::unsafe_arena_release_name() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.EnumValueDescriptorProto.name) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_name(); + return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void EnumValueDescriptorProto::unsafe_arena_set_allocated_name( ::std::string* name) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -8022,7 +8192,7 @@ inline void EnumValueDescriptorProto::clear_has_options() { _has_bits_[0] &= ~0x00000002u; } inline void EnumValueDescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::EnumValueOptions::Clear(); + if (options_ != NULL) options_->Clear(); clear_has_options(); } inline const ::google::protobuf::EnumValueOptions& EnumValueDescriptorProto::options() const { @@ -8031,6 +8201,23 @@ inline const ::google::protobuf::EnumValueOptions& EnumValueDescriptorProto::opt return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::EnumValueOptions*>( &::google::protobuf::_EnumValueOptions_default_instance_); } +inline ::google::protobuf::EnumValueOptions* EnumValueDescriptorProto::release_options() { + // @@protoc_insertion_point(field_release:google.protobuf.EnumValueDescriptorProto.options) + clear_has_options(); + ::google::protobuf::EnumValueOptions* temp = options_; + if (GetArenaNoVirtual() != NULL) { + temp = ::google::protobuf::internal::DuplicateIfNonNull(temp, NULL); + } + options_ = NULL; + return temp; +} +inline ::google::protobuf::EnumValueOptions* EnumValueDescriptorProto::unsafe_arena_release_options() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.EnumValueDescriptorProto.options) + clear_has_options(); + ::google::protobuf::EnumValueOptions* temp = options_; + options_ = NULL; + return temp; +} inline ::google::protobuf::EnumValueOptions* EnumValueDescriptorProto::mutable_options() { set_has_options(); if (options_ == NULL) { @@ -8039,40 +8226,25 @@ inline ::google::protobuf::EnumValueOptions* EnumValueDescriptorProto::mutable_o // @@protoc_insertion_point(field_mutable:google.protobuf.EnumValueDescriptorProto.options) return options_; } -inline ::google::protobuf::EnumValueOptions* EnumValueDescriptorProto::release_options() { - // @@protoc_insertion_point(field_release:google.protobuf.EnumValueDescriptorProto.options) - clear_has_options(); - if (GetArenaNoVirtual() != NULL) { - return _slow_release_options(); - } else { - ::google::protobuf::EnumValueOptions* temp = options_; - options_ = NULL; - return temp; - } -} -inline void EnumValueDescriptorProto::set_allocated_options(::google::protobuf::EnumValueOptions* options) { +inline void EnumValueDescriptorProto::set_allocated_options(::google::protobuf::EnumValueOptions* options) { ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); if (message_arena == NULL) { delete options_; } - if (options != NULL) { - _slow_set_allocated_options(message_arena, &options); - } - options_ = options; if (options) { + ::google::protobuf::Arena* submessage_arena = + ::google::protobuf::Arena::GetArena(options); + if (message_arena != submessage_arena) { + options = ::google::protobuf::internal::GetOwnedMessage( + message_arena, options, submessage_arena); + } set_has_options(); } else { clear_has_options(); } + options_ = options; // @@protoc_insertion_point(field_set_allocated:google.protobuf.EnumValueDescriptorProto.options) } -inline ::google::protobuf::EnumValueOptions* EnumValueDescriptorProto::unsafe_arena_release_options() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.EnumValueDescriptorProto.options) - clear_has_options(); - ::google::protobuf::EnumValueOptions* temp = options_; - options_ = NULL; - return temp; -} // ------------------------------------------------------------------- @@ -8133,13 +8305,6 @@ inline ::std::string* ServiceDescriptorProto::release_name() { clear_has_name(); return name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* ServiceDescriptorProto::unsafe_arena_release_name() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.ServiceDescriptorProto.name) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_name(); - return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void ServiceDescriptorProto::set_allocated_name(::std::string* name) { if (name != NULL) { set_has_name(); @@ -8150,6 +8315,13 @@ inline void ServiceDescriptorProto::set_allocated_name(::std::string* name) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.ServiceDescriptorProto.name) } +inline ::std::string* ServiceDescriptorProto::unsafe_arena_release_name() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.ServiceDescriptorProto.name) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_name(); + return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void ServiceDescriptorProto::unsafe_arena_set_allocated_name( ::std::string* name) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -8204,7 +8376,7 @@ inline void ServiceDescriptorProto::clear_has_options() { _has_bits_[0] &= ~0x00000002u; } inline void ServiceDescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::ServiceOptions::Clear(); + if (options_ != NULL) options_->Clear(); clear_has_options(); } inline const ::google::protobuf::ServiceOptions& ServiceDescriptorProto::options() const { @@ -8213,6 +8385,23 @@ inline const ::google::protobuf::ServiceOptions& ServiceDescriptorProto::options return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::ServiceOptions*>( &::google::protobuf::_ServiceOptions_default_instance_); } +inline ::google::protobuf::ServiceOptions* ServiceDescriptorProto::release_options() { + // @@protoc_insertion_point(field_release:google.protobuf.ServiceDescriptorProto.options) + clear_has_options(); + ::google::protobuf::ServiceOptions* temp = options_; + if (GetArenaNoVirtual() != NULL) { + temp = ::google::protobuf::internal::DuplicateIfNonNull(temp, NULL); + } + options_ = NULL; + return temp; +} +inline ::google::protobuf::ServiceOptions* ServiceDescriptorProto::unsafe_arena_release_options() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.ServiceDescriptorProto.options) + clear_has_options(); + ::google::protobuf::ServiceOptions* temp = options_; + options_ = NULL; + return temp; +} inline ::google::protobuf::ServiceOptions* ServiceDescriptorProto::mutable_options() { set_has_options(); if (options_ == NULL) { @@ -8221,40 +8410,25 @@ inline ::google::protobuf::ServiceOptions* ServiceDescriptorProto::mutable_optio // @@protoc_insertion_point(field_mutable:google.protobuf.ServiceDescriptorProto.options) return options_; } -inline ::google::protobuf::ServiceOptions* ServiceDescriptorProto::release_options() { - // @@protoc_insertion_point(field_release:google.protobuf.ServiceDescriptorProto.options) - clear_has_options(); - if (GetArenaNoVirtual() != NULL) { - return _slow_release_options(); - } else { - ::google::protobuf::ServiceOptions* temp = options_; - options_ = NULL; - return temp; - } -} -inline void ServiceDescriptorProto::set_allocated_options(::google::protobuf::ServiceOptions* options) { +inline void ServiceDescriptorProto::set_allocated_options(::google::protobuf::ServiceOptions* options) { ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); if (message_arena == NULL) { delete options_; } - if (options != NULL) { - _slow_set_allocated_options(message_arena, &options); - } - options_ = options; if (options) { + ::google::protobuf::Arena* submessage_arena = + ::google::protobuf::Arena::GetArena(options); + if (message_arena != submessage_arena) { + options = ::google::protobuf::internal::GetOwnedMessage( + message_arena, options, submessage_arena); + } set_has_options(); } else { clear_has_options(); } + options_ = options; // @@protoc_insertion_point(field_set_allocated:google.protobuf.ServiceDescriptorProto.options) } -inline ::google::protobuf::ServiceOptions* ServiceDescriptorProto::unsafe_arena_release_options() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.ServiceDescriptorProto.options) - clear_has_options(); - ::google::protobuf::ServiceOptions* temp = options_; - options_ = NULL; - return temp; -} // ------------------------------------------------------------------- @@ -8315,13 +8489,6 @@ inline ::std::string* MethodDescriptorProto::release_name() { clear_has_name(); return name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* MethodDescriptorProto::unsafe_arena_release_name() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.MethodDescriptorProto.name) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_name(); - return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void MethodDescriptorProto::set_allocated_name(::std::string* name) { if (name != NULL) { set_has_name(); @@ -8332,6 +8499,13 @@ inline void MethodDescriptorProto::set_allocated_name(::std::string* name) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.MethodDescriptorProto.name) } +inline ::std::string* MethodDescriptorProto::unsafe_arena_release_name() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.MethodDescriptorProto.name) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_name(); + return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void MethodDescriptorProto::unsafe_arena_set_allocated_name( ::std::string* name) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -8400,13 +8574,6 @@ inline ::std::string* MethodDescriptorProto::release_input_type() { clear_has_input_type(); return input_type_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* MethodDescriptorProto::unsafe_arena_release_input_type() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.MethodDescriptorProto.input_type) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_input_type(); - return input_type_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void MethodDescriptorProto::set_allocated_input_type(::std::string* input_type) { if (input_type != NULL) { set_has_input_type(); @@ -8417,6 +8584,13 @@ inline void MethodDescriptorProto::set_allocated_input_type(::std::string* input GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.MethodDescriptorProto.input_type) } +inline ::std::string* MethodDescriptorProto::unsafe_arena_release_input_type() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.MethodDescriptorProto.input_type) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_input_type(); + return input_type_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void MethodDescriptorProto::unsafe_arena_set_allocated_input_type( ::std::string* input_type) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -8485,13 +8659,6 @@ inline ::std::string* MethodDescriptorProto::release_output_type() { clear_has_output_type(); return output_type_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* MethodDescriptorProto::unsafe_arena_release_output_type() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.MethodDescriptorProto.output_type) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_output_type(); - return output_type_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void MethodDescriptorProto::set_allocated_output_type(::std::string* output_type) { if (output_type != NULL) { set_has_output_type(); @@ -8502,6 +8669,13 @@ inline void MethodDescriptorProto::set_allocated_output_type(::std::string* outp GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.MethodDescriptorProto.output_type) } +inline ::std::string* MethodDescriptorProto::unsafe_arena_release_output_type() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.MethodDescriptorProto.output_type) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_output_type(); + return output_type_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void MethodDescriptorProto::unsafe_arena_set_allocated_output_type( ::std::string* output_type) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -8526,7 +8700,7 @@ inline void MethodDescriptorProto::clear_has_options() { _has_bits_[0] &= ~0x00000008u; } inline void MethodDescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::MethodOptions::Clear(); + if (options_ != NULL) options_->Clear(); clear_has_options(); } inline const ::google::protobuf::MethodOptions& MethodDescriptorProto::options() const { @@ -8535,6 +8709,23 @@ inline const ::google::protobuf::MethodOptions& MethodDescriptorProto::options() return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::MethodOptions*>( &::google::protobuf::_MethodOptions_default_instance_); } +inline ::google::protobuf::MethodOptions* MethodDescriptorProto::release_options() { + // @@protoc_insertion_point(field_release:google.protobuf.MethodDescriptorProto.options) + clear_has_options(); + ::google::protobuf::MethodOptions* temp = options_; + if (GetArenaNoVirtual() != NULL) { + temp = ::google::protobuf::internal::DuplicateIfNonNull(temp, NULL); + } + options_ = NULL; + return temp; +} +inline ::google::protobuf::MethodOptions* MethodDescriptorProto::unsafe_arena_release_options() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.MethodDescriptorProto.options) + clear_has_options(); + ::google::protobuf::MethodOptions* temp = options_; + options_ = NULL; + return temp; +} inline ::google::protobuf::MethodOptions* MethodDescriptorProto::mutable_options() { set_has_options(); if (options_ == NULL) { @@ -8543,40 +8734,25 @@ inline ::google::protobuf::MethodOptions* MethodDescriptorProto::mutable_options // @@protoc_insertion_point(field_mutable:google.protobuf.MethodDescriptorProto.options) return options_; } -inline ::google::protobuf::MethodOptions* MethodDescriptorProto::release_options() { - // @@protoc_insertion_point(field_release:google.protobuf.MethodDescriptorProto.options) - clear_has_options(); - if (GetArenaNoVirtual() != NULL) { - return _slow_release_options(); - } else { - ::google::protobuf::MethodOptions* temp = options_; - options_ = NULL; - return temp; - } -} -inline void MethodDescriptorProto::set_allocated_options(::google::protobuf::MethodOptions* options) { +inline void MethodDescriptorProto::set_allocated_options(::google::protobuf::MethodOptions* options) { ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); if (message_arena == NULL) { delete options_; } - if (options != NULL) { - _slow_set_allocated_options(message_arena, &options); - } - options_ = options; if (options) { + ::google::protobuf::Arena* submessage_arena = + ::google::protobuf::Arena::GetArena(options); + if (message_arena != submessage_arena) { + options = ::google::protobuf::internal::GetOwnedMessage( + message_arena, options, submessage_arena); + } set_has_options(); } else { clear_has_options(); } + options_ = options; // @@protoc_insertion_point(field_set_allocated:google.protobuf.MethodDescriptorProto.options) } -inline ::google::protobuf::MethodOptions* MethodDescriptorProto::unsafe_arena_release_options() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.MethodDescriptorProto.options) - clear_has_options(); - ::google::protobuf::MethodOptions* temp = options_; - options_ = NULL; - return temp; -} // optional bool client_streaming = 5 [default = false]; inline bool MethodDescriptorProto::has_client_streaming() const { @@ -8685,13 +8861,6 @@ inline ::std::string* FileOptions::release_java_package() { clear_has_java_package(); return java_package_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* FileOptions::unsafe_arena_release_java_package() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileOptions.java_package) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_java_package(); - return java_package_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void FileOptions::set_allocated_java_package(::std::string* java_package) { if (java_package != NULL) { set_has_java_package(); @@ -8702,6 +8871,13 @@ inline void FileOptions::set_allocated_java_package(::std::string* java_package) GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileOptions.java_package) } +inline ::std::string* FileOptions::unsafe_arena_release_java_package() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileOptions.java_package) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_java_package(); + return java_package_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void FileOptions::unsafe_arena_set_allocated_java_package( ::std::string* java_package) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -8770,13 +8946,6 @@ inline ::std::string* FileOptions::release_java_outer_classname() { clear_has_java_outer_classname(); return java_outer_classname_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* FileOptions::unsafe_arena_release_java_outer_classname() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileOptions.java_outer_classname) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_java_outer_classname(); - return java_outer_classname_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void FileOptions::set_allocated_java_outer_classname(::std::string* java_outer_classname) { if (java_outer_classname != NULL) { set_has_java_outer_classname(); @@ -8787,6 +8956,13 @@ inline void FileOptions::set_allocated_java_outer_classname(::std::string* java_ GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileOptions.java_outer_classname) } +inline ::std::string* FileOptions::unsafe_arena_release_java_outer_classname() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileOptions.java_outer_classname) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_java_outer_classname(); + return java_outer_classname_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void FileOptions::unsafe_arena_set_allocated_java_outer_classname( ::std::string* java_outer_classname) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -8952,13 +9128,6 @@ inline ::std::string* FileOptions::release_go_package() { clear_has_go_package(); return go_package_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* FileOptions::unsafe_arena_release_go_package() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileOptions.go_package) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_go_package(); - return go_package_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void FileOptions::set_allocated_go_package(::std::string* go_package) { if (go_package != NULL) { set_has_go_package(); @@ -8969,6 +9138,13 @@ inline void FileOptions::set_allocated_go_package(::std::string* go_package) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileOptions.go_package) } +inline ::std::string* FileOptions::unsafe_arena_release_go_package() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileOptions.go_package) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_go_package(); + return go_package_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void FileOptions::unsafe_arena_set_allocated_go_package( ::std::string* go_package) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -9181,13 +9357,6 @@ inline ::std::string* FileOptions::release_objc_class_prefix() { clear_has_objc_class_prefix(); return objc_class_prefix_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* FileOptions::unsafe_arena_release_objc_class_prefix() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileOptions.objc_class_prefix) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_objc_class_prefix(); - return objc_class_prefix_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void FileOptions::set_allocated_objc_class_prefix(::std::string* objc_class_prefix) { if (objc_class_prefix != NULL) { set_has_objc_class_prefix(); @@ -9198,6 +9367,13 @@ inline void FileOptions::set_allocated_objc_class_prefix(::std::string* objc_cla GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileOptions.objc_class_prefix) } +inline ::std::string* FileOptions::unsafe_arena_release_objc_class_prefix() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileOptions.objc_class_prefix) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_objc_class_prefix(); + return objc_class_prefix_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void FileOptions::unsafe_arena_set_allocated_objc_class_prefix( ::std::string* objc_class_prefix) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -9266,13 +9442,6 @@ inline ::std::string* FileOptions::release_csharp_namespace() { clear_has_csharp_namespace(); return csharp_namespace_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* FileOptions::unsafe_arena_release_csharp_namespace() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileOptions.csharp_namespace) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_csharp_namespace(); - return csharp_namespace_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void FileOptions::set_allocated_csharp_namespace(::std::string* csharp_namespace) { if (csharp_namespace != NULL) { set_has_csharp_namespace(); @@ -9283,6 +9452,13 @@ inline void FileOptions::set_allocated_csharp_namespace(::std::string* csharp_na GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileOptions.csharp_namespace) } +inline ::std::string* FileOptions::unsafe_arena_release_csharp_namespace() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileOptions.csharp_namespace) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_csharp_namespace(); + return csharp_namespace_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void FileOptions::unsafe_arena_set_allocated_csharp_namespace( ::std::string* csharp_namespace) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -9351,13 +9527,6 @@ inline ::std::string* FileOptions::release_swift_prefix() { clear_has_swift_prefix(); return swift_prefix_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* FileOptions::unsafe_arena_release_swift_prefix() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileOptions.swift_prefix) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_swift_prefix(); - return swift_prefix_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void FileOptions::set_allocated_swift_prefix(::std::string* swift_prefix) { if (swift_prefix != NULL) { set_has_swift_prefix(); @@ -9368,6 +9537,13 @@ inline void FileOptions::set_allocated_swift_prefix(::std::string* swift_prefix) GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileOptions.swift_prefix) } +inline ::std::string* FileOptions::unsafe_arena_release_swift_prefix() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileOptions.swift_prefix) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_swift_prefix(); + return swift_prefix_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void FileOptions::unsafe_arena_set_allocated_swift_prefix( ::std::string* swift_prefix) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -9436,13 +9612,6 @@ inline ::std::string* FileOptions::release_php_class_prefix() { clear_has_php_class_prefix(); return php_class_prefix_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* FileOptions::unsafe_arena_release_php_class_prefix() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileOptions.php_class_prefix) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_php_class_prefix(); - return php_class_prefix_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void FileOptions::set_allocated_php_class_prefix(::std::string* php_class_prefix) { if (php_class_prefix != NULL) { set_has_php_class_prefix(); @@ -9453,6 +9622,13 @@ inline void FileOptions::set_allocated_php_class_prefix(::std::string* php_class GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileOptions.php_class_prefix) } +inline ::std::string* FileOptions::unsafe_arena_release_php_class_prefix() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileOptions.php_class_prefix) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_php_class_prefix(); + return php_class_prefix_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void FileOptions::unsafe_arena_set_allocated_php_class_prefix( ::std::string* php_class_prefix) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -9521,13 +9697,6 @@ inline ::std::string* FileOptions::release_php_namespace() { clear_has_php_namespace(); return php_namespace_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* FileOptions::unsafe_arena_release_php_namespace() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileOptions.php_namespace) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_php_namespace(); - return php_namespace_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void FileOptions::set_allocated_php_namespace(::std::string* php_namespace) { if (php_namespace != NULL) { set_has_php_namespace(); @@ -9538,6 +9707,13 @@ inline void FileOptions::set_allocated_php_namespace(::std::string* php_namespac GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileOptions.php_namespace) } +inline ::std::string* FileOptions::unsafe_arena_release_php_namespace() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.FileOptions.php_namespace) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_php_namespace(); + return php_namespace_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void FileOptions::unsafe_arena_set_allocated_php_namespace( ::std::string* php_namespace) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -10265,13 +10441,6 @@ inline ::std::string* UninterpretedOption_NamePart::release_name_part() { clear_has_name_part(); return name_part_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* UninterpretedOption_NamePart::unsafe_arena_release_name_part() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.UninterpretedOption.NamePart.name_part) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_name_part(); - return name_part_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void UninterpretedOption_NamePart::set_allocated_name_part(::std::string* name_part) { if (name_part != NULL) { set_has_name_part(); @@ -10282,6 +10451,13 @@ inline void UninterpretedOption_NamePart::set_allocated_name_part(::std::string* GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.UninterpretedOption.NamePart.name_part) } +inline ::std::string* UninterpretedOption_NamePart::unsafe_arena_release_name_part() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.UninterpretedOption.NamePart.name_part) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_name_part(); + return name_part_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void UninterpretedOption_NamePart::unsafe_arena_set_allocated_name_part( ::std::string* name_part) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -10408,13 +10584,6 @@ inline ::std::string* UninterpretedOption::release_identifier_value() { clear_has_identifier_value(); return identifier_value_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* UninterpretedOption::unsafe_arena_release_identifier_value() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.UninterpretedOption.identifier_value) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_identifier_value(); - return identifier_value_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void UninterpretedOption::set_allocated_identifier_value(::std::string* identifier_value) { if (identifier_value != NULL) { set_has_identifier_value(); @@ -10425,6 +10594,13 @@ inline void UninterpretedOption::set_allocated_identifier_value(::std::string* i GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.UninterpretedOption.identifier_value) } +inline ::std::string* UninterpretedOption::unsafe_arena_release_identifier_value() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.UninterpretedOption.identifier_value) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_identifier_value(); + return identifier_value_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void UninterpretedOption::unsafe_arena_set_allocated_identifier_value( ::std::string* identifier_value) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -10565,13 +10741,6 @@ inline ::std::string* UninterpretedOption::release_string_value() { clear_has_string_value(); return string_value_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* UninterpretedOption::unsafe_arena_release_string_value() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.UninterpretedOption.string_value) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_string_value(); - return string_value_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void UninterpretedOption::set_allocated_string_value(::std::string* string_value) { if (string_value != NULL) { set_has_string_value(); @@ -10582,6 +10751,13 @@ inline void UninterpretedOption::set_allocated_string_value(::std::string* strin GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.UninterpretedOption.string_value) } +inline ::std::string* UninterpretedOption::unsafe_arena_release_string_value() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.UninterpretedOption.string_value) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_string_value(); + return string_value_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void UninterpretedOption::unsafe_arena_set_allocated_string_value( ::std::string* string_value) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -10650,13 +10826,6 @@ inline ::std::string* UninterpretedOption::release_aggregate_value() { clear_has_aggregate_value(); return aggregate_value_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* UninterpretedOption::unsafe_arena_release_aggregate_value() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.UninterpretedOption.aggregate_value) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_aggregate_value(); - return aggregate_value_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void UninterpretedOption::set_allocated_aggregate_value(::std::string* aggregate_value) { if (aggregate_value != NULL) { set_has_aggregate_value(); @@ -10667,6 +10836,13 @@ inline void UninterpretedOption::set_allocated_aggregate_value(::std::string* ag GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.UninterpretedOption.aggregate_value) } +inline ::std::string* UninterpretedOption::unsafe_arena_release_aggregate_value() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.UninterpretedOption.aggregate_value) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_aggregate_value(); + return aggregate_value_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void UninterpretedOption::unsafe_arena_set_allocated_aggregate_value( ::std::string* aggregate_value) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -10799,13 +10975,6 @@ inline ::std::string* SourceCodeInfo_Location::release_leading_comments() { clear_has_leading_comments(); return leading_comments_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* SourceCodeInfo_Location::unsafe_arena_release_leading_comments() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.SourceCodeInfo.Location.leading_comments) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_leading_comments(); - return leading_comments_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void SourceCodeInfo_Location::set_allocated_leading_comments(::std::string* leading_comments) { if (leading_comments != NULL) { set_has_leading_comments(); @@ -10816,6 +10985,13 @@ inline void SourceCodeInfo_Location::set_allocated_leading_comments(::std::strin GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.SourceCodeInfo.Location.leading_comments) } +inline ::std::string* SourceCodeInfo_Location::unsafe_arena_release_leading_comments() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.SourceCodeInfo.Location.leading_comments) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_leading_comments(); + return leading_comments_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void SourceCodeInfo_Location::unsafe_arena_set_allocated_leading_comments( ::std::string* leading_comments) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -10884,13 +11060,6 @@ inline ::std::string* SourceCodeInfo_Location::release_trailing_comments() { clear_has_trailing_comments(); return trailing_comments_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* SourceCodeInfo_Location::unsafe_arena_release_trailing_comments() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.SourceCodeInfo.Location.trailing_comments) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_trailing_comments(); - return trailing_comments_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void SourceCodeInfo_Location::set_allocated_trailing_comments(::std::string* trailing_comments) { if (trailing_comments != NULL) { set_has_trailing_comments(); @@ -10901,6 +11070,13 @@ inline void SourceCodeInfo_Location::set_allocated_trailing_comments(::std::stri GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.SourceCodeInfo.Location.trailing_comments) } +inline ::std::string* SourceCodeInfo_Location::unsafe_arena_release_trailing_comments() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.SourceCodeInfo.Location.trailing_comments) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_trailing_comments(); + return trailing_comments_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void SourceCodeInfo_Location::unsafe_arena_set_allocated_trailing_comments( ::std::string* trailing_comments) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -11106,13 +11282,6 @@ inline ::std::string* GeneratedCodeInfo_Annotation::release_source_file() { clear_has_source_file(); return source_file_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* GeneratedCodeInfo_Annotation::unsafe_arena_release_source_file() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.GeneratedCodeInfo.Annotation.source_file) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - clear_has_source_file(); - return source_file_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void GeneratedCodeInfo_Annotation::set_allocated_source_file(::std::string* source_file) { if (source_file != NULL) { set_has_source_file(); @@ -11123,6 +11292,13 @@ inline void GeneratedCodeInfo_Annotation::set_allocated_source_file(::std::strin GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.GeneratedCodeInfo.Annotation.source_file) } +inline ::std::string* GeneratedCodeInfo_Annotation::unsafe_arena_release_source_file() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.GeneratedCodeInfo.Annotation.source_file) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + clear_has_source_file(); + return source_file_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void GeneratedCodeInfo_Annotation::unsafe_arena_set_allocated_source_file( ::std::string* source_file) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); diff --git a/src/google/protobuf/descriptor.proto b/src/google/protobuf/descriptor.proto index 4fd66e41..8697a50d 100644 --- a/src/google/protobuf/descriptor.proto +++ b/src/google/protobuf/descriptor.proto @@ -417,10 +417,12 @@ message FileOptions { // determining the namespace. optional string php_namespace = 41; - // The parser stores options it doesn't recognize here. See above. + // The parser stores options it doesn't recognize here. + // See the documentation for the "Options" section above. repeated UninterpretedOption uninterpreted_option = 999; - // Clients can define custom options in extensions of this message. See above. + // Clients can define custom options in extensions of this message. + // See the documentation for the "Options" section above. extensions 1000 to max; reserved 38; diff --git a/src/google/protobuf/duration.pb.cc b/src/google/protobuf/duration.pb.cc index 01c8c9aa..0a8aad48 100644 --- a/src/google/protobuf/duration.pb.cc +++ b/src/google/protobuf/duration.pb.cc @@ -14,6 +14,10 @@ #include <google/protobuf/generated_message_reflection.h> #include <google/protobuf/reflection_ops.h> #include <google/protobuf/wire_format.h> +// This is a temporary google only hack +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS +#include "third_party/protobuf/version.h" +#endif // @@protoc_insertion_point(includes) namespace google { namespace protobuf { @@ -28,7 +32,11 @@ namespace protobuf_google_2fprotobuf_2fduration_2eproto { void InitDefaultsDurationImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_Duration_default_instance_; new (ptr) ::google::protobuf::Duration(); @@ -159,12 +167,7 @@ Duration::~Duration() { } void Duration::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void Duration::ArenaDtor(void* object) { diff --git a/src/google/protobuf/empty.pb.cc b/src/google/protobuf/empty.pb.cc index 0cc6a313..caa019e8 100644 --- a/src/google/protobuf/empty.pb.cc +++ b/src/google/protobuf/empty.pb.cc @@ -14,6 +14,10 @@ #include <google/protobuf/generated_message_reflection.h> #include <google/protobuf/reflection_ops.h> #include <google/protobuf/wire_format.h> +// This is a temporary google only hack +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS +#include "third_party/protobuf/version.h" +#endif // @@protoc_insertion_point(includes) namespace google { namespace protobuf { @@ -28,7 +32,11 @@ namespace protobuf_google_2fprotobuf_2fempty_2eproto { void InitDefaultsEmptyImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_Empty_default_instance_; new (ptr) ::google::protobuf::Empty(); @@ -148,12 +156,7 @@ Empty::~Empty() { } void Empty::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void Empty::ArenaDtor(void* object) { diff --git a/src/google/protobuf/field_mask.pb.cc b/src/google/protobuf/field_mask.pb.cc index a81a71f5..c55a697a 100644 --- a/src/google/protobuf/field_mask.pb.cc +++ b/src/google/protobuf/field_mask.pb.cc @@ -14,6 +14,10 @@ #include <google/protobuf/generated_message_reflection.h> #include <google/protobuf/reflection_ops.h> #include <google/protobuf/wire_format.h> +// This is a temporary google only hack +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS +#include "third_party/protobuf/version.h" +#endif // @@protoc_insertion_point(includes) namespace google { namespace protobuf { @@ -28,7 +32,11 @@ namespace protobuf_google_2fprotobuf_2ffield_5fmask_2eproto { void InitDefaultsFieldMaskImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_FieldMask_default_instance_; new (ptr) ::google::protobuf::FieldMask(); diff --git a/src/google/protobuf/field_mask.proto b/src/google/protobuf/field_mask.proto index c68d247c..eb96ba00 100644 --- a/src/google/protobuf/field_mask.proto +++ b/src/google/protobuf/field_mask.proto @@ -240,6 +240,12 @@ option go_package = "google.golang.org/genproto/protobuf/field_mask;field_mask"; // // Note that oneof type names ("test_oneof" in this case) cannot be used in // paths. +// +// ## Field Mask Verification +// +// The implementation of the all the API methods, which have any FieldMask type +// field in the request, should verify the included field paths, and return +// `INVALID_ARGUMENT` error if any path is duplicated or unmappable. message FieldMask { // The set of field mask paths. repeated string paths = 1; diff --git a/src/google/protobuf/generated_message_reflection.h b/src/google/protobuf/generated_message_reflection.h index f6ce16a7..02ecba61 100644 --- a/src/google/protobuf/generated_message_reflection.h +++ b/src/google/protobuf/generated_message_reflection.h @@ -45,7 +45,6 @@ // TODO(jasonh): Remove this once the compiler change to directly include this // is released to components. #include <google/protobuf/generated_enum_reflection.h> -#include <google/protobuf/generated_message_util.h> #include <google/protobuf/message.h> #include <google/protobuf/metadata.h> #include <google/protobuf/unknown_field_set.h> diff --git a/src/google/protobuf/generated_message_util.cc b/src/google/protobuf/generated_message_util.cc index c9dfe61a..15d84222 100644 --- a/src/google/protobuf/generated_message_util.cc +++ b/src/google/protobuf/generated_message_util.cc @@ -43,14 +43,17 @@ #include <google/protobuf/extension_set.h> #include <google/protobuf/message_lite.h> #include <google/protobuf/metadata_lite.h> +#include <google/protobuf/stubs/port.h> #include <google/protobuf/repeated_field.h> #include <google/protobuf/wire_format_lite.h> #include <google/protobuf/wire_format_lite_inl.h> namespace google { + namespace protobuf { namespace internal { + double Infinity() { return std::numeric_limits<double>::infinity(); } @@ -695,6 +698,33 @@ void UnknownFieldSerializerLite(const uint8* ptr, uint32 offset, uint32 tag, ->unknown_fields()); } +MessageLite* DuplicateIfNonNullInternal(MessageLite* message, Arena* arena) { + if (message) { + MessageLite* ret = message->New(arena); + ret->CheckTypeAndMergeFrom(*message); + return ret; + } else { + return NULL; + } +} + +// Returns a message owned by this Arena. This may require Own()ing or +// duplicating the message. +MessageLite* GetOwnedMessageInternal(Arena* message_arena, + MessageLite* submessage, + Arena* submessage_arena) { + GOOGLE_DCHECK(submessage->GetArena() == submessage_arena); + GOOGLE_DCHECK(message_arena != submessage_arena); + if (message_arena != NULL && submessage_arena == NULL) { + message_arena->Own(submessage); + return submessage; + } else { + MessageLite* ret = submessage->New(message_arena); + ret->CheckTypeAndMergeFrom(*submessage); + return ret; + } +} + } // 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 096a84cd..8ebfc13b 100644 --- a/src/google/protobuf/generated_message_util.h +++ b/src/google/protobuf/generated_message_util.h @@ -274,6 +274,45 @@ void MapFieldSerializer(const uint8* base, uint32 offset, uint32 tag, } } +LIBPROTOBUF_EXPORT MessageLite* DuplicateIfNonNullInternal(MessageLite* message, Arena* arena); +LIBPROTOBUF_EXPORT MessageLite* GetOwnedMessageInternal(Arena* message_arena, + MessageLite* submessage, + Arena* submessage_arena); + +template <typename T> +T* DuplicateIfNonNull(T* message, Arena* arena) { + // The casts must be reinterpret_cast<> because T might be a forward-declared + // type that the compiler doesn't know is related to MessageLite. + return reinterpret_cast<T*>(DuplicateIfNonNullInternal( + reinterpret_cast<MessageLite*>(message), arena)); +} + +template <typename T> +T* GetOwnedMessage(Arena* message_arena, T* submessage, + Arena* submessage_arena) { + // The casts must be reinterpret_cast<> because T might be a forward-declared + // type that the compiler doesn't know is related to MessageLite. + return reinterpret_cast<T*>(GetOwnedMessageInternal( + message_arena, reinterpret_cast<MessageLite*>(submessage), + submessage_arena)); +} + +// Returns a message owned by this Arena. This may require Own()ing or +// duplicating the message. +template <typename T> +T* GetOwnedMessage(T* message, Arena* arena) { + GOOGLE_DCHECK(message); + Arena* message_arena = google::protobuf::Arena::GetArena(message); + if (message_arena == arena) { + return message; + } else if (arena != NULL && message_arena == NULL) { + arena->Own(message); + return message; + } else { + return DuplicateIfNonNull(message, arena); + } +} + } // namespace internal } // namespace protobuf diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h index 59db8ce1..3d30fac1 100644 --- a/src/google/protobuf/io/coded_stream.h +++ b/src/google/protobuf/io/coded_stream.h @@ -862,11 +862,11 @@ class LIBPROTOBUF_EXPORT CodedOutputStream { bool IsSerializationDeterministic() const { return serialization_deterministic_is_overridden_ ? serialization_deterministic_override_ : - default_serialization_deterministic_; + IsDefaultSerializationDeterministic(); } static bool IsDefaultSerializationDeterministic() { - return google::protobuf::internal::Acquire_Load(&default_serialization_deterministic_); + return google::protobuf::internal::NoBarrier_Load(&default_serialization_deterministic_); } private: @@ -882,6 +882,7 @@ class LIBPROTOBUF_EXPORT CodedOutputStream { bool serialization_deterministic_is_overridden_; bool serialization_deterministic_override_; // Conceptually, default_serialization_deterministic_ is an atomic bool. + // TODO(haberman): replace with std::atomic<bool> when we move to C++11. static google::protobuf::internal::AtomicWord default_serialization_deterministic_; // Advance the buffer by a given number of bytes. @@ -909,7 +910,7 @@ class LIBPROTOBUF_EXPORT CodedOutputStream { // thread has done so. friend void ::google::protobuf::internal::MapTestForceDeterministic(); static void SetDefaultSerializationDeterministic() { - google::protobuf::internal::Release_Store(&default_serialization_deterministic_, 1); + google::protobuf::internal::NoBarrier_Store(&default_serialization_deterministic_, 1); } }; diff --git a/src/google/protobuf/lite_arena_unittest.cc b/src/google/protobuf/lite_arena_unittest.cc index 1f4c2540..dadaffb6 100644 --- a/src/google/protobuf/lite_arena_unittest.cc +++ b/src/google/protobuf/lite_arena_unittest.cc @@ -39,16 +39,16 @@ namespace { class LiteArenaTest : public testing::Test { protected: - // We create an Arena with a large initial block of memory, so that tests can - // verify that no new allocations are made. - LiteArenaTest() : arena_block_(128 * 1024) { + LiteArenaTest() { ArenaOptions options; - options.initial_block = &arena_block_[0]; - options.initial_block_size = arena_block_.size(); + options.start_block_size = 128 * 1024; + options.max_block_size = 128 * 1024; arena_.reset(new Arena(options)); + // Trigger the allocation of the first arena block, so that further use of + // the arena will not require any heap allocations. + google::protobuf::Arena::CreateArray<char>(arena_.get(), 1); } - std::vector<char> arena_block_; google::protobuf::scoped_ptr<Arena> arena_; }; diff --git a/src/google/protobuf/map.h b/src/google/protobuf/map.h index 63db2925..7d9cc5c5 100644 --- a/src/google/protobuf/map.h +++ b/src/google/protobuf/map.h @@ -142,6 +142,26 @@ class Map { insert(other.begin(), other.end()); } +#if LANG_CXX11 + Map(Map&& other) noexcept : Map() { + if (other.arena_) { + *this = other; + } else { + swap(other); + } + } + Map& operator=(Map&& other) noexcept { + if (this != &other) { + if (arena_ != other.arena_) { + *this = other; + } else { + swap(other); + } + } + return *this; + } +#endif + template <class InputIt> Map(const InputIt& first, const InputIt& last) : arena_(NULL), default_enum_value_(0) { @@ -1036,12 +1056,12 @@ class Map { } const T& at(const key_type& key) const { const_iterator it = find(key); - GOOGLE_CHECK(it != end()); + GOOGLE_CHECK(it != end()) << "key not found: " << key; return it->second; } T& at(const key_type& key) { iterator it = find(key); - GOOGLE_CHECK(it != end()); + GOOGLE_CHECK(it != end()) << "key not found: " << key; return it->second; } diff --git a/src/google/protobuf/map_entry_lite.h b/src/google/protobuf/map_entry_lite.h index 7f8636a9..7c477c56 100644 --- a/src/google/protobuf/map_entry_lite.h +++ b/src/google/protobuf/map_entry_lite.h @@ -603,7 +603,7 @@ template <> struct FromHelper<WireFormatLite::TYPE_STRING> { static ArenaStringPtr From(const string& x) { ArenaStringPtr res; - res.UnsafeArenaSetAllocated(NULL, const_cast<string*>(&x), NULL); + *res.UnsafeRawStringPointer() = const_cast<string*>(&x); return res; } }; @@ -611,7 +611,7 @@ template <> struct FromHelper<WireFormatLite::TYPE_BYTES> { static ArenaStringPtr From(const string& x) { ArenaStringPtr res; - res.UnsafeArenaSetAllocated(NULL, const_cast<string*>(&x), NULL); + *res.UnsafeRawStringPointer() = const_cast<string*>(&x); return res; } }; diff --git a/src/google/protobuf/map_test.cc b/src/google/protobuf/map_test.cc index cea193c8..080c71a7 100644 --- a/src/google/protobuf/map_test.cc +++ b/src/google/protobuf/map_test.cc @@ -3283,6 +3283,44 @@ TEST(ArenaTest, IsInitialized) { EXPECT_EQ(0, (*message->mutable_map_int32_int32())[0]); } +#if LANG_CXX11 +TEST(MoveTest, MoveConstructorWorks) { + Map<int32, TestAllTypes> original_map; + original_map[42].mutable_optional_nested_message()->set_bb(42); + original_map[43].mutable_optional_nested_message()->set_bb(43); + const auto* nested_msg42_ptr = &original_map[42].optional_nested_message(); + const auto* nested_msg43_ptr = &original_map[43].optional_nested_message(); + + Map<int32, TestAllTypes> moved_to_map(std::move(original_map)); + EXPECT_TRUE(original_map.empty()); + EXPECT_EQ(2, moved_to_map.size()); + EXPECT_EQ(42, moved_to_map[42].optional_nested_message().bb()); + EXPECT_EQ(43, moved_to_map[43].optional_nested_message().bb()); + // This test takes advantage of the fact that pointers are swapped, so there + // should be pointer stability. + EXPECT_EQ(nested_msg42_ptr, &moved_to_map[42].optional_nested_message()); + EXPECT_EQ(nested_msg43_ptr, &moved_to_map[43].optional_nested_message()); +} + +TEST(MoveTest, MoveAssignmentWorks) { + Map<int32, TestAllTypes> original_map; + original_map[42].mutable_optional_nested_message()->set_bb(42); + original_map[43].mutable_optional_nested_message()->set_bb(43); + const auto* nested_msg42_ptr = &original_map[42].optional_nested_message(); + const auto* nested_msg43_ptr = &original_map[43].optional_nested_message(); + + Map<int32, TestAllTypes> moved_to_map = std::move(original_map); + EXPECT_TRUE(original_map.empty()); + EXPECT_EQ(2, moved_to_map.size()); + EXPECT_EQ(42, moved_to_map[42].optional_nested_message().bb()); + EXPECT_EQ(43, moved_to_map[43].optional_nested_message().bb()); + // This test takes advantage of the fact that pointers are swapped, so there + // should be pointer stability. + EXPECT_EQ(nested_msg42_ptr, &moved_to_map[42].optional_nested_message()); + EXPECT_EQ(nested_msg43_ptr, &moved_to_map[43].optional_nested_message()); +} +#endif + } // namespace internal } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/message_lite.cc b/src/google/protobuf/message_lite.cc index 6184472d..123b142d 100644 --- a/src/google/protobuf/message_lite.cc +++ b/src/google/protobuf/message_lite.cc @@ -394,7 +394,8 @@ void GenericTypeHandler<string>::Merge(const string& from, *to = from; } -bool proto3_preserve_unknown_ = false; +bool proto3_preserve_unknown_ = true; + void SetProto3PreserveUnknownsDefault(bool preserve) { proto3_preserve_unknown_ = preserve; } diff --git a/src/google/protobuf/message_unittest.cc b/src/google/protobuf/message_unittest.cc index 86c43774..d328f9dd 100644 --- a/src/google/protobuf/message_unittest.cc +++ b/src/google/protobuf/message_unittest.cc @@ -409,6 +409,7 @@ TEST(MessageTest, MessageIsStillValidAfterParseFails) { } } + namespace { void ExpectMessageMerged(const unittest::TestAllTypes& message) { diff --git a/src/google/protobuf/metadata_lite.h b/src/google/protobuf/metadata_lite.h index 10692e9b..454d088c 100644 --- a/src/google/protobuf/metadata_lite.h +++ b/src/google/protobuf/metadata_lite.h @@ -33,7 +33,7 @@ #include <google/protobuf/stubs/common.h> #include <google/protobuf/arena.h> -#include <google/protobuf/generated_message_util.h> +#include <google/protobuf/message_lite.h> #include <google/protobuf/stubs/port.h> namespace google { diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index 1910e362..8eb6c795 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -376,7 +376,7 @@ struct TypeImplementsMergeBehaviorProbeForMergeFrom { CheckType<U, bool, &U::MergeFrom>*); template<typename U> static HasNoMerge Check(...); - // Resovles to either google::protobuf::internal::true_type or google::protobuf::internal::false_type. + // Resolves to either google::protobuf::internal::true_type or google::protobuf::internal::false_type. typedef google::protobuf::internal::integral_constant<bool, (sizeof(Check<T>(0)) == sizeof(HasMerge))> type; }; @@ -528,11 +528,9 @@ class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase { inline void InternalSwap(RepeatedPtrFieldBase* other); template <typename TypeHandler> - void AddAllocatedInternal(typename TypeHandler::Type* value, - google::protobuf::internal::true_type); + void AddAllocatedInternal(typename TypeHandler::Type* value, google::protobuf::internal::true_type); template <typename TypeHandler> - void AddAllocatedInternal(typename TypeHandler::Type* value, - google::protobuf::internal::false_type); + void AddAllocatedInternal(typename TypeHandler::Type* value, google::protobuf::internal::false_type); template <typename TypeHandler> GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE void AddAllocatedSlowWithCopy(typename TypeHandler::Type* value, @@ -1735,7 +1733,6 @@ void RepeatedPtrFieldBase::AddAllocatedInternal( elems[current_size_] = value; current_size_ = current_size_ + 1; rep_->allocated_size = rep_->allocated_size + 1; - return; } else { AddAllocatedSlowWithCopy<TypeHandler>( value, TypeHandler::GetArena(value), arena); @@ -1782,7 +1779,6 @@ void RepeatedPtrFieldBase::AddAllocatedInternal( elems[current_size_] = value; current_size_ = current_size_ + 1; ++rep_->allocated_size; - return; } else { UnsafeArenaAddAllocated<TypeHandler>(value); } diff --git a/src/google/protobuf/source_context.pb.cc b/src/google/protobuf/source_context.pb.cc index 8024bcd1..4a290e1e 100644 --- a/src/google/protobuf/source_context.pb.cc +++ b/src/google/protobuf/source_context.pb.cc @@ -14,6 +14,10 @@ #include <google/protobuf/generated_message_reflection.h> #include <google/protobuf/reflection_ops.h> #include <google/protobuf/wire_format.h> +// This is a temporary google only hack +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS +#include "third_party/protobuf/version.h" +#endif // @@protoc_insertion_point(includes) namespace google { namespace protobuf { @@ -28,7 +32,11 @@ namespace protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto { void InitDefaultsSourceContextImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_SourceContext_default_instance_; new (ptr) ::google::protobuf::SourceContext(); diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc index 3bbbbfa4..fe3ba327 100644 --- a/src/google/protobuf/struct.pb.cc +++ b/src/google/protobuf/struct.pb.cc @@ -14,6 +14,10 @@ #include <google/protobuf/generated_message_reflection.h> #include <google/protobuf/reflection_ops.h> #include <google/protobuf/wire_format.h> +// This is a temporary google only hack +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS +#include "third_party/protobuf/version.h" +#endif // @@protoc_insertion_point(includes) namespace google { namespace protobuf { @@ -49,7 +53,11 @@ namespace protobuf_google_2fprotobuf_2fstruct_2eproto { void InitDefaultsListValueImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_Struct_FieldsEntry_DoNotUse_default_instance_; new (ptr) ::google::protobuf::Struct_FieldsEntry_DoNotUse(); @@ -266,12 +274,7 @@ Struct::~Struct() { } void Struct::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void Struct::ArenaDtor(void* object) { @@ -628,6 +631,36 @@ void Value::InitAsDefaultInstance() { ::google::protobuf::_Value_default_instance_.list_value_ = const_cast< ::google::protobuf::ListValue*>( ::google::protobuf::ListValue::internal_default_instance()); } +void Value::set_allocated_struct_value(::google::protobuf::Struct* struct_value) { + ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); + clear_kind(); + if (struct_value) { + ::google::protobuf::Arena* submessage_arena = + ::google::protobuf::Arena::GetArena(struct_value); + if (message_arena != submessage_arena) { + struct_value = ::google::protobuf::internal::GetOwnedMessage( + message_arena, struct_value, submessage_arena); + } + set_has_struct_value(); + kind_.struct_value_ = struct_value; + } + // @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.struct_value) +} +void Value::set_allocated_list_value(::google::protobuf::ListValue* list_value) { + ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); + clear_kind(); + if (list_value) { + ::google::protobuf::Arena* submessage_arena = + ::google::protobuf::Arena::GetArena(list_value); + if (message_arena != submessage_arena) { + list_value = ::google::protobuf::internal::GetOwnedMessage( + message_arena, list_value, submessage_arena); + } + set_has_list_value(); + kind_.list_value_ = list_value; + } + // @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.list_value) +} #if !defined(_MSC_VER) || _MSC_VER >= 1900 const int Value::kNullValueFieldNumber; const int Value::kNumberValueFieldNumber; @@ -702,12 +735,7 @@ Value::~Value() { } void Value::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); if (has_kind()) { clear_kind(); } @@ -863,7 +891,7 @@ bool Value::MergePartialFromCodedStream( case 5: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(42u /* 42 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage( input, mutable_struct_value())); } else { goto handle_unusual; @@ -875,7 +903,7 @@ bool Value::MergePartialFromCodedStream( case 6: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(50u /* 50 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage( input, mutable_list_value())); } else { goto handle_unusual; @@ -991,14 +1019,14 @@ void Value::SerializeWithCachedSizes( // .google.protobuf.Struct struct_value = 5; if (has_struct_value()) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 5, *kind_.struct_value_, deterministic, target); } // .google.protobuf.ListValue list_value = 6; if (has_list_value()) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 6, *kind_.list_value_, deterministic, target); } @@ -1046,14 +1074,14 @@ size_t Value::ByteSizeLong() const { // .google.protobuf.Struct struct_value = 5; case kStructValue: { total_size += 1 + - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( *kind_.struct_value_); break; } // .google.protobuf.ListValue list_value = 6; case kListValue: { total_size += 1 + - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( *kind_.list_value_); break; } @@ -1216,12 +1244,7 @@ ListValue::~ListValue() { } void ListValue::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void ListValue::ArenaDtor(void* object) { @@ -1273,8 +1296,7 @@ bool ListValue::MergePartialFromCodedStream( case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_values())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_values())); } else { goto handle_unusual; } @@ -1332,7 +1354,7 @@ void ListValue::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->values_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 1, this->values(static_cast<int>(i)), deterministic, target); } @@ -1359,7 +1381,7 @@ size_t ListValue::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->values(static_cast<int>(i))); } } diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index 2145ffda..83b7da6d 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -375,7 +375,13 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_ ::std::string* mutable_string_value(); ::std::string* release_string_value(); void set_allocated_string_value(::std::string* string_value); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_string_value(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_string_value( ::std::string* string_value); @@ -394,17 +400,14 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_ static const int kStructValueFieldNumber = 5; private: void _slow_mutable_struct_value(); - void _slow_set_allocated_struct_value( - ::google::protobuf::Arena* message_arena, ::google::protobuf::Struct** struct_value); - ::google::protobuf::Struct* _slow_release_struct_value(); public: const ::google::protobuf::Struct& struct_value() const; - ::google::protobuf::Struct* mutable_struct_value(); ::google::protobuf::Struct* release_struct_value(); + ::google::protobuf::Struct* mutable_struct_value(); void set_allocated_struct_value(::google::protobuf::Struct* struct_value); - ::google::protobuf::Struct* unsafe_arena_release_struct_value(); void unsafe_arena_set_allocated_struct_value( ::google::protobuf::Struct* struct_value); + ::google::protobuf::Struct* unsafe_arena_release_struct_value(); // .google.protobuf.ListValue list_value = 6; bool has_list_value() const; @@ -412,17 +415,14 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_ static const int kListValueFieldNumber = 6; private: void _slow_mutable_list_value(); - void _slow_set_allocated_list_value( - ::google::protobuf::Arena* message_arena, ::google::protobuf::ListValue** list_value); - ::google::protobuf::ListValue* _slow_release_list_value(); public: const ::google::protobuf::ListValue& list_value() const; - ::google::protobuf::ListValue* mutable_list_value(); ::google::protobuf::ListValue* release_list_value(); + ::google::protobuf::ListValue* mutable_list_value(); void set_allocated_list_value(::google::protobuf::ListValue* list_value); - ::google::protobuf::ListValue* unsafe_arena_release_list_value(); void unsafe_arena_set_allocated_list_value( ::google::protobuf::ListValue* list_value); + ::google::protobuf::ListValue* unsafe_arena_release_list_value(); KindCase kind_case() const; // @@protoc_insertion_point(class_scope:google.protobuf.Value) @@ -758,17 +758,6 @@ inline ::std::string* Value::release_string_value() { return NULL; } } -inline ::std::string* Value::unsafe_arena_release_string_value() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.string_value) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - if (has_string_value()) { - clear_has_kind(); - return kind_.string_value_.UnsafeArenaRelease( - &::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); - } else { - return NULL; - } -} inline void Value::set_allocated_string_value(::std::string* string_value) { if (!has_string_value()) { kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); @@ -781,6 +770,17 @@ inline void Value::set_allocated_string_value(::std::string* string_value) { } // @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.string_value) } +inline ::std::string* Value::unsafe_arena_release_string_value() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.string_value) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + if (has_string_value()) { + clear_has_kind(); + return kind_.string_value_.UnsafeArenaRelease( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); + } else { + return NULL; + } +} inline void Value::unsafe_arena_set_allocated_string_value(::std::string* string_value) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); if (!has_string_value()) { @@ -838,58 +838,25 @@ inline void Value::clear_struct_value() { clear_has_kind(); } } -inline const ::google::protobuf::Struct& Value::struct_value() const { - // @@protoc_insertion_point(field_get:google.protobuf.Value.struct_value) - return has_struct_value() - ? *kind_.struct_value_ - : ::google::protobuf::Struct::default_instance(); -} -inline ::google::protobuf::Struct* Value::mutable_struct_value() { - if (!has_struct_value()) { - clear_kind(); - set_has_struct_value(); - kind_.struct_value_ = - ::google::protobuf::Arena::CreateMessage< ::google::protobuf::Struct >( - GetArenaNoVirtual()); - } - // @@protoc_insertion_point(field_mutable:google.protobuf.Value.struct_value) - return kind_.struct_value_; -} inline ::google::protobuf::Struct* Value::release_struct_value() { // @@protoc_insertion_point(field_release:google.protobuf.Value.struct_value) if (has_struct_value()) { clear_has_kind(); - if (GetArenaNoVirtual() != NULL) { - ::google::protobuf::Struct* temp = new ::google::protobuf::Struct(*kind_.struct_value_); - kind_.struct_value_ = NULL; - return temp; - } else { ::google::protobuf::Struct* temp = kind_.struct_value_; - kind_.struct_value_ = NULL; - return temp; + if (GetArenaNoVirtual() != NULL) { + temp = ::google::protobuf::internal::DuplicateIfNonNull(temp, NULL); } + kind_.struct_value_ = NULL; + return temp; } else { return NULL; } } -inline void Value::set_allocated_struct_value(::google::protobuf::Struct* struct_value) { - clear_kind(); - if (struct_value) { - if (GetArenaNoVirtual() != NULL && - ::google::protobuf::Arena::GetArena(struct_value) == NULL) { - GetArenaNoVirtual()->Own(struct_value); - } else if (GetArenaNoVirtual() != - ::google::protobuf::Arena::GetArena(struct_value)) { - ::google::protobuf::Struct* new_struct_value = - ::google::protobuf::Arena::CreateMessage< ::google::protobuf::Struct >( - GetArenaNoVirtual()); - new_struct_value->CopyFrom(*struct_value); - struct_value = new_struct_value; - } - set_has_struct_value(); - kind_.struct_value_ = struct_value; - } - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.struct_value) +inline const ::google::protobuf::Struct& Value::struct_value() const { + // @@protoc_insertion_point(field_get:google.protobuf.Value.struct_value) + return has_struct_value() + ? *kind_.struct_value_ + : *reinterpret_cast< ::google::protobuf::Struct*>(&::google::protobuf::_Struct_default_instance_); } inline ::google::protobuf::Struct* Value::unsafe_arena_release_struct_value() { // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.struct_value) @@ -902,7 +869,7 @@ inline ::google::protobuf::Struct* Value::unsafe_arena_release_struct_value() { return NULL; } } -inline void Value::unsafe_arena_set_allocated_struct_value(::google::protobuf::Struct* struct_value) { +inline void Value::unsafe_arena_set_allocated_struct_value(::google::protobuf::Struct* struct_value) { clear_kind(); if (struct_value) { set_has_struct_value(); @@ -910,6 +877,17 @@ inline void Value::unsafe_arena_set_allocated_struct_value(::google::protobuf:: } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Value.struct_value) } +inline ::google::protobuf::Struct* Value::mutable_struct_value() { + if (!has_struct_value()) { + clear_kind(); + set_has_struct_value(); + kind_.struct_value_ = + ::google::protobuf::Arena::CreateMessage< ::google::protobuf::Struct >( + GetArenaNoVirtual()); + } + // @@protoc_insertion_point(field_mutable:google.protobuf.Value.struct_value) + return kind_.struct_value_; +} // .google.protobuf.ListValue list_value = 6; inline bool Value::has_list_value() const { @@ -926,58 +904,25 @@ inline void Value::clear_list_value() { clear_has_kind(); } } -inline const ::google::protobuf::ListValue& Value::list_value() const { - // @@protoc_insertion_point(field_get:google.protobuf.Value.list_value) - return has_list_value() - ? *kind_.list_value_ - : ::google::protobuf::ListValue::default_instance(); -} -inline ::google::protobuf::ListValue* Value::mutable_list_value() { - if (!has_list_value()) { - clear_kind(); - set_has_list_value(); - kind_.list_value_ = - ::google::protobuf::Arena::CreateMessage< ::google::protobuf::ListValue >( - GetArenaNoVirtual()); - } - // @@protoc_insertion_point(field_mutable:google.protobuf.Value.list_value) - return kind_.list_value_; -} inline ::google::protobuf::ListValue* Value::release_list_value() { // @@protoc_insertion_point(field_release:google.protobuf.Value.list_value) if (has_list_value()) { clear_has_kind(); - if (GetArenaNoVirtual() != NULL) { - ::google::protobuf::ListValue* temp = new ::google::protobuf::ListValue(*kind_.list_value_); - kind_.list_value_ = NULL; - return temp; - } else { ::google::protobuf::ListValue* temp = kind_.list_value_; - kind_.list_value_ = NULL; - return temp; + if (GetArenaNoVirtual() != NULL) { + temp = ::google::protobuf::internal::DuplicateIfNonNull(temp, NULL); } + kind_.list_value_ = NULL; + return temp; } else { return NULL; } } -inline void Value::set_allocated_list_value(::google::protobuf::ListValue* list_value) { - clear_kind(); - if (list_value) { - if (GetArenaNoVirtual() != NULL && - ::google::protobuf::Arena::GetArena(list_value) == NULL) { - GetArenaNoVirtual()->Own(list_value); - } else if (GetArenaNoVirtual() != - ::google::protobuf::Arena::GetArena(list_value)) { - ::google::protobuf::ListValue* new_list_value = - ::google::protobuf::Arena::CreateMessage< ::google::protobuf::ListValue >( - GetArenaNoVirtual()); - new_list_value->CopyFrom(*list_value); - list_value = new_list_value; - } - set_has_list_value(); - kind_.list_value_ = list_value; - } - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.list_value) +inline const ::google::protobuf::ListValue& Value::list_value() const { + // @@protoc_insertion_point(field_get:google.protobuf.Value.list_value) + return has_list_value() + ? *kind_.list_value_ + : *reinterpret_cast< ::google::protobuf::ListValue*>(&::google::protobuf::_ListValue_default_instance_); } inline ::google::protobuf::ListValue* Value::unsafe_arena_release_list_value() { // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.list_value) @@ -990,7 +935,7 @@ inline ::google::protobuf::ListValue* Value::unsafe_arena_release_list_value() { return NULL; } } -inline void Value::unsafe_arena_set_allocated_list_value(::google::protobuf::ListValue* list_value) { +inline void Value::unsafe_arena_set_allocated_list_value(::google::protobuf::ListValue* list_value) { clear_kind(); if (list_value) { set_has_list_value(); @@ -998,6 +943,17 @@ inline void Value::unsafe_arena_set_allocated_list_value(::google::protobuf::Li } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Value.list_value) } +inline ::google::protobuf::ListValue* Value::mutable_list_value() { + if (!has_list_value()) { + clear_kind(); + set_has_list_value(); + kind_.list_value_ = + ::google::protobuf::Arena::CreateMessage< ::google::protobuf::ListValue >( + GetArenaNoVirtual()); + } + // @@protoc_insertion_point(field_mutable:google.protobuf.Value.list_value) + return kind_.list_value_; +} inline bool Value::has_kind() const { return kind_case() != KIND_NOT_SET; diff --git a/src/google/protobuf/stubs/io_win32_unittest.cc b/src/google/protobuf/stubs/io_win32_unittest.cc index 3ef6c75d..288f27ab 100644 --- a/src/google/protobuf/stubs/io_win32_unittest.cc +++ b/src/google/protobuf/stubs/io_win32_unittest.cc @@ -123,8 +123,7 @@ void IoWin32Test::SetUp() { // "\\?\" prefix (except on Windows 10 version 1607 and beyond, after // opting in to long paths by default [1]). // - // [1] https://msdn.microsoft.com/en-us/library/windows/ \ - // desktop/aa365247(v=vs.85).aspx#maxpath + // [1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath DWORD result = ::GetCurrentDirectoryA(MAX_PATH, buffer); if (result > 0) { test_tmpdir = string(buffer); @@ -142,8 +141,7 @@ void IoWin32Test::SetUp() { test_tmpdir += "\\io_win32_unittest.tmp"; // CreateDirectoryA's limit is 248 chars, see MSDN. - // https://msdn.microsoft.com/en-us/library/windows/ \ - // desktop/aa363855(v=vs.85).aspx + // https://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx wtest_tmpdir = testonly_path_to_winpath(test_tmpdir); if (!DeleteAllUnder(wtest_tmpdir) || !CreateAllUnder(wtest_tmpdir)) { GOOGLE_CHECK_OK(false); diff --git a/src/google/protobuf/text_format.h b/src/google/protobuf/text_format.h index 57668927..a2670d6b 100644 --- a/src/google/protobuf/text_format.h +++ b/src/google/protobuf/text_format.h @@ -211,7 +211,7 @@ class LIBPROTOBUF_EXPORT TextFormat { single_line_mode_ = single_line_mode; } - bool IsInSingleLineMode() { + bool IsInSingleLineMode() const { return single_line_mode_; } diff --git a/src/google/protobuf/timestamp.pb.cc b/src/google/protobuf/timestamp.pb.cc index 0525c18d..36e3bb36 100644 --- a/src/google/protobuf/timestamp.pb.cc +++ b/src/google/protobuf/timestamp.pb.cc @@ -14,6 +14,10 @@ #include <google/protobuf/generated_message_reflection.h> #include <google/protobuf/reflection_ops.h> #include <google/protobuf/wire_format.h> +// This is a temporary google only hack +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS +#include "third_party/protobuf/version.h" +#endif // @@protoc_insertion_point(includes) namespace google { namespace protobuf { @@ -28,7 +32,11 @@ namespace protobuf_google_2fprotobuf_2ftimestamp_2eproto { void InitDefaultsTimestampImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_Timestamp_default_instance_; new (ptr) ::google::protobuf::Timestamp(); @@ -159,12 +167,7 @@ Timestamp::~Timestamp() { } void Timestamp::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void Timestamp::ArenaDtor(void* object) { diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc index 2cdb0146..92f6589c 100644 --- a/src/google/protobuf/type.pb.cc +++ b/src/google/protobuf/type.pb.cc @@ -14,6 +14,10 @@ #include <google/protobuf/generated_message_reflection.h> #include <google/protobuf/reflection_ops.h> #include <google/protobuf/wire_format.h> +// This is a temporary google only hack +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS +#include "third_party/protobuf/version.h" +#endif // @@protoc_insertion_point(includes) namespace google { namespace protobuf { @@ -48,7 +52,11 @@ namespace protobuf_google_2fprotobuf_2ftype_2eproto { void InitDefaultsTypeImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaultsField(); protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaultsOption(); protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::InitDefaultsSourceContext(); @@ -68,7 +76,11 @@ void InitDefaultsType() { void InitDefaultsFieldImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaultsOption(); { void* ptr = &::google::protobuf::_Field_default_instance_; @@ -86,7 +98,11 @@ void InitDefaultsField() { void InitDefaultsEnumImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaultsEnumValue(); protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaultsOption(); protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::InitDefaultsSourceContext(); @@ -106,7 +122,11 @@ void InitDefaultsEnum() { void InitDefaultsEnumValueImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaultsOption(); { void* ptr = &::google::protobuf::_EnumValue_default_instance_; @@ -124,7 +144,11 @@ void InitDefaultsEnumValue() { void InitDefaultsOptionImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS protobuf_google_2fprotobuf_2fany_2eproto::InitDefaultsAny(); { void* ptr = &::google::protobuf::_Option_default_instance_; @@ -400,15 +424,6 @@ void Type::_slow_mutable_source_context() { source_context_ = ::google::protobuf::Arena::Create< ::google::protobuf::SourceContext >( GetArenaNoVirtual()); } -::google::protobuf::SourceContext* Type::_slow_release_source_context() { - if (source_context_ == NULL) { - return NULL; - } else { - ::google::protobuf::SourceContext* temp = new ::google::protobuf::SourceContext(*source_context_); - source_context_ = NULL; - return temp; - } -} void Type::unsafe_arena_set_allocated_source_context( ::google::protobuf::SourceContext* source_context) { if (GetArenaNoVirtual() == NULL) { @@ -422,6 +437,12 @@ void Type::unsafe_arena_set_allocated_source_context( } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Type.source_context) } +void Type::clear_source_context() { + if (GetArenaNoVirtual() == NULL && source_context_ != NULL) { + delete source_context_; + } + source_context_ = NULL; +} #if !defined(_MSC_VER) || _MSC_VER >= 1900 const int Type::kNameFieldNumber; const int Type::kFieldsFieldNumber; @@ -486,13 +507,8 @@ Type::~Type() { } void Type::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - - name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); + name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); if (this != internal_default_instance()) delete source_context_; } @@ -569,8 +585,7 @@ bool Type::MergePartialFromCodedStream( case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_fields())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_fields())); } else { goto handle_unusual; } @@ -598,8 +613,7 @@ bool Type::MergePartialFromCodedStream( case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(34u /* 34 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_options())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_options())); } else { goto handle_unusual; } @@ -610,7 +624,7 @@ bool Type::MergePartialFromCodedStream( case 5: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(42u /* 42 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage( input, mutable_source_context())); } else { goto handle_unusual; @@ -734,7 +748,7 @@ void Type::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->fields_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 2, this->fields(static_cast<int>(i)), deterministic, target); } @@ -752,14 +766,14 @@ void Type::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->options_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 4, this->options(static_cast<int>(i)), deterministic, target); } // .google.protobuf.SourceContext source_context = 5; if (this->has_source_context()) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 5, *this->source_context_, deterministic, target); } @@ -792,7 +806,7 @@ size_t Type::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->fields(static_cast<int>(i))); } } @@ -811,7 +825,7 @@ size_t Type::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->options(static_cast<int>(i))); } } @@ -826,7 +840,7 @@ size_t Type::ByteSizeLong() const { // .google.protobuf.SourceContext source_context = 5; if (this->has_source_context()) { total_size += 1 + - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( *this->source_context_); } @@ -1017,16 +1031,11 @@ Field::~Field() { } void Field::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - - name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - type_url_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - json_name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - default_value_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); + name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + type_url_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + json_name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + default_value_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } void Field::ArenaDtor(void* object) { @@ -1189,8 +1198,7 @@ bool Field::MergePartialFromCodedStream( case 9: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(74u /* 74 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_options())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_options())); } else { goto handle_unusual; } @@ -1396,7 +1404,7 @@ void Field::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->options_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 9, this->options(static_cast<int>(i)), deterministic, target); } @@ -1445,7 +1453,7 @@ size_t Field::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->options(static_cast<int>(i))); } } @@ -1637,15 +1645,6 @@ void Enum::_slow_mutable_source_context() { source_context_ = ::google::protobuf::Arena::Create< ::google::protobuf::SourceContext >( GetArenaNoVirtual()); } -::google::protobuf::SourceContext* Enum::_slow_release_source_context() { - if (source_context_ == NULL) { - return NULL; - } else { - ::google::protobuf::SourceContext* temp = new ::google::protobuf::SourceContext(*source_context_); - source_context_ = NULL; - return temp; - } -} void Enum::unsafe_arena_set_allocated_source_context( ::google::protobuf::SourceContext* source_context) { if (GetArenaNoVirtual() == NULL) { @@ -1659,6 +1658,12 @@ void Enum::unsafe_arena_set_allocated_source_context( } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Enum.source_context) } +void Enum::clear_source_context() { + if (GetArenaNoVirtual() == NULL && source_context_ != NULL) { + delete source_context_; + } + source_context_ = NULL; +} #if !defined(_MSC_VER) || _MSC_VER >= 1900 const int Enum::kNameFieldNumber; const int Enum::kEnumvalueFieldNumber; @@ -1720,13 +1725,8 @@ Enum::~Enum() { } void Enum::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - - name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); + name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); if (this != internal_default_instance()) delete source_context_; } @@ -1802,8 +1802,7 @@ bool Enum::MergePartialFromCodedStream( case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_enumvalue())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_enumvalue())); } else { goto handle_unusual; } @@ -1814,8 +1813,7 @@ bool Enum::MergePartialFromCodedStream( case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_options())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_options())); } else { goto handle_unusual; } @@ -1826,7 +1824,7 @@ bool Enum::MergePartialFromCodedStream( case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(34u /* 34 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage( input, mutable_source_context())); } else { goto handle_unusual; @@ -1940,7 +1938,7 @@ void Enum::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->enumvalue_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 2, this->enumvalue(static_cast<int>(i)), deterministic, target); } @@ -1948,14 +1946,14 @@ void Enum::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->options_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 3, this->options(static_cast<int>(i)), deterministic, target); } // .google.protobuf.SourceContext source_context = 4; if (this->has_source_context()) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 4, *this->source_context_, deterministic, target); } @@ -1988,7 +1986,7 @@ size_t Enum::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->enumvalue(static_cast<int>(i))); } } @@ -1999,7 +1997,7 @@ size_t Enum::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->options(static_cast<int>(i))); } } @@ -2014,7 +2012,7 @@ size_t Enum::ByteSizeLong() const { // .google.protobuf.SourceContext source_context = 4; if (this->has_source_context()) { total_size += 1 + - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( *this->source_context_); } @@ -2174,13 +2172,8 @@ EnumValue::~EnumValue() { } void EnumValue::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - - name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); + name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } void EnumValue::ArenaDtor(void* object) { @@ -2264,8 +2257,7 @@ bool EnumValue::MergePartialFromCodedStream( case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, add_options())); + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_options())); } else { goto handle_unusual; } @@ -2354,7 +2346,7 @@ void EnumValue::SerializeWithCachedSizes( for (unsigned int i = 0, n = static_cast<unsigned int>(this->options_size()); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 3, this->options(static_cast<int>(i)), deterministic, target); } @@ -2381,7 +2373,7 @@ size_t EnumValue::ByteSizeLong() const { total_size += 1UL * count; for (unsigned int i = 0; i < count; i++) { total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( this->options(static_cast<int>(i))); } } @@ -2500,15 +2492,6 @@ void Option::_slow_mutable_value() { value_ = ::google::protobuf::Arena::Create< ::google::protobuf::Any >( GetArenaNoVirtual()); } -::google::protobuf::Any* Option::_slow_release_value() { - if (value_ == NULL) { - return NULL; - } else { - ::google::protobuf::Any* temp = new ::google::protobuf::Any(*value_); - value_ = NULL; - return temp; - } -} void Option::unsafe_arena_set_allocated_value( ::google::protobuf::Any* value) { if (GetArenaNoVirtual() == NULL) { @@ -2522,6 +2505,12 @@ void Option::unsafe_arena_set_allocated_value( } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Option.value) } +void Option::clear_value() { + if (GetArenaNoVirtual() == NULL && value_ != NULL) { + delete value_; + } + value_ = NULL; +} #if !defined(_MSC_VER) || _MSC_VER >= 1900 const int Option::kNameFieldNumber; const int Option::kValueFieldNumber; @@ -2573,13 +2562,8 @@ Option::~Option() { } void Option::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - - name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); + name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); if (this != internal_default_instance()) delete value_; } @@ -2652,7 +2636,7 @@ bool Option::MergePartialFromCodedStream( case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { - DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + DO_(::google::protobuf::internal::WireFormatLite::ReadMessage( input, mutable_value())); } else { goto handle_unusual; @@ -2730,7 +2714,7 @@ void Option::SerializeWithCachedSizes( // .google.protobuf.Any value = 2; if (this->has_value()) { target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessageNoVirtualToArray( + InternalWriteMessageToArray( 2, *this->value_, deterministic, target); } @@ -2761,7 +2745,7 @@ size_t Option::ByteSizeLong() const { // .google.protobuf.Any value = 2; if (this->has_value()) { total_size += 1 + - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + ::google::protobuf::internal::WireFormatLite::MessageSize( *this->value_); } diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index 8834e167..85bd660f 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -322,7 +322,13 @@ class LIBPROTOBUF_EXPORT Type : public ::google::protobuf::Message /* @@protoc_i ::std::string* mutable_name(); ::std::string* release_name(); void set_allocated_name(::std::string* name); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_name(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_name( ::std::string* name); @@ -332,15 +338,14 @@ class LIBPROTOBUF_EXPORT Type : public ::google::protobuf::Message /* @@protoc_i static const int kSourceContextFieldNumber = 5; private: void _slow_mutable_source_context(); - ::google::protobuf::SourceContext* _slow_release_source_context(); public: const ::google::protobuf::SourceContext& source_context() const; - ::google::protobuf::SourceContext* mutable_source_context(); ::google::protobuf::SourceContext* release_source_context(); + ::google::protobuf::SourceContext* mutable_source_context(); void set_allocated_source_context(::google::protobuf::SourceContext* source_context); - ::google::protobuf::SourceContext* unsafe_arena_release_source_context(); void unsafe_arena_set_allocated_source_context( ::google::protobuf::SourceContext* source_context); + ::google::protobuf::SourceContext* unsafe_arena_release_source_context(); // .google.protobuf.Syntax syntax = 6; void clear_syntax(); @@ -576,7 +581,13 @@ class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_ ::std::string* mutable_name(); ::std::string* release_name(); void set_allocated_name(::std::string* name); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_name(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_name( ::std::string* name); @@ -593,7 +604,13 @@ class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_ ::std::string* mutable_type_url(); ::std::string* release_type_url(); void set_allocated_type_url(::std::string* type_url); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_type_url(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_type_url( ::std::string* type_url); @@ -610,7 +627,13 @@ class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_ ::std::string* mutable_json_name(); ::std::string* release_json_name(); void set_allocated_json_name(::std::string* json_name); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_json_name(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_json_name( ::std::string* json_name); @@ -627,7 +650,13 @@ class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_ ::std::string* mutable_default_value(); ::std::string* release_default_value(); void set_allocated_default_value(::std::string* default_value); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_default_value(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_default_value( ::std::string* default_value); @@ -815,7 +844,13 @@ class LIBPROTOBUF_EXPORT Enum : public ::google::protobuf::Message /* @@protoc_i ::std::string* mutable_name(); ::std::string* release_name(); void set_allocated_name(::std::string* name); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_name(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_name( ::std::string* name); @@ -825,15 +860,14 @@ class LIBPROTOBUF_EXPORT Enum : public ::google::protobuf::Message /* @@protoc_i static const int kSourceContextFieldNumber = 4; private: void _slow_mutable_source_context(); - ::google::protobuf::SourceContext* _slow_release_source_context(); public: const ::google::protobuf::SourceContext& source_context() const; - ::google::protobuf::SourceContext* mutable_source_context(); ::google::protobuf::SourceContext* release_source_context(); + ::google::protobuf::SourceContext* mutable_source_context(); void set_allocated_source_context(::google::protobuf::SourceContext* source_context); - ::google::protobuf::SourceContext* unsafe_arena_release_source_context(); void unsafe_arena_set_allocated_source_context( ::google::protobuf::SourceContext* source_context); + ::google::protobuf::SourceContext* unsafe_arena_release_source_context(); // .google.protobuf.Syntax syntax = 5; void clear_syntax(); @@ -978,7 +1012,13 @@ class LIBPROTOBUF_EXPORT EnumValue : public ::google::protobuf::Message /* @@pro ::std::string* mutable_name(); ::std::string* release_name(); void set_allocated_name(::std::string* name); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_name(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_name( ::std::string* name); @@ -1111,7 +1151,13 @@ class LIBPROTOBUF_EXPORT Option : public ::google::protobuf::Message /* @@protoc ::std::string* mutable_name(); ::std::string* release_name(); void set_allocated_name(::std::string* name); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_name(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_name( ::std::string* name); @@ -1121,15 +1167,14 @@ class LIBPROTOBUF_EXPORT Option : public ::google::protobuf::Message /* @@protoc static const int kValueFieldNumber = 2; private: void _slow_mutable_value(); - ::google::protobuf::Any* _slow_release_value(); public: const ::google::protobuf::Any& value() const; - ::google::protobuf::Any* mutable_value(); ::google::protobuf::Any* release_value(); + ::google::protobuf::Any* mutable_value(); void set_allocated_value(::google::protobuf::Any* value); - ::google::protobuf::Any* unsafe_arena_release_value(); void unsafe_arena_set_allocated_value( ::google::protobuf::Any* value); + ::google::protobuf::Any* unsafe_arena_release_value(); // @@protoc_insertion_point(class_scope:google.protobuf.Option) private: @@ -1200,13 +1245,6 @@ inline ::std::string* Type::release_name() { return name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* Type::unsafe_arena_release_name() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Type.name) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - - return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void Type::set_allocated_name(::std::string* name) { if (name != NULL) { @@ -1217,6 +1255,13 @@ inline void Type::set_allocated_name(::std::string* name) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.Type.name) } +inline ::std::string* Type::unsafe_arena_release_name() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Type.name) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + + return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void Type::unsafe_arena_set_allocated_name( ::std::string* name) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -1363,16 +1408,29 @@ Type::options() const { inline bool Type::has_source_context() const { return this != internal_default_instance() && source_context_ != NULL; } -inline void Type::clear_source_context() { - if (GetArenaNoVirtual() == NULL && source_context_ != NULL) delete source_context_; - source_context_ = NULL; -} inline const ::google::protobuf::SourceContext& Type::source_context() const { const ::google::protobuf::SourceContext* p = source_context_; // @@protoc_insertion_point(field_get:google.protobuf.Type.source_context) return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::SourceContext*>( &::google::protobuf::_SourceContext_default_instance_); } +inline ::google::protobuf::SourceContext* Type::release_source_context() { + // @@protoc_insertion_point(field_release:google.protobuf.Type.source_context) + + ::google::protobuf::SourceContext* temp = source_context_; + if (GetArenaNoVirtual() != NULL) { + temp = ::google::protobuf::internal::DuplicateIfNonNull(temp, NULL); + } + source_context_ = NULL; + return temp; +} +inline ::google::protobuf::SourceContext* Type::unsafe_arena_release_source_context() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Type.source_context) + + ::google::protobuf::SourceContext* temp = source_context_; + source_context_ = NULL; + return temp; +} inline ::google::protobuf::SourceContext* Type::mutable_source_context() { if (source_context_ == NULL) { @@ -1381,42 +1439,24 @@ inline ::google::protobuf::SourceContext* Type::mutable_source_context() { // @@protoc_insertion_point(field_mutable:google.protobuf.Type.source_context) return source_context_; } -inline ::google::protobuf::SourceContext* Type::release_source_context() { - // @@protoc_insertion_point(field_release:google.protobuf.Type.source_context) - - if (GetArenaNoVirtual() != NULL) { - return _slow_release_source_context(); - } else { - ::google::protobuf::SourceContext* temp = source_context_; - source_context_ = NULL; - return temp; - } -} -inline void Type::set_allocated_source_context(::google::protobuf::SourceContext* source_context) { +inline void Type::set_allocated_source_context(::google::protobuf::SourceContext* source_context) { ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); if (message_arena == NULL) { - delete source_context_; - } - if (source_context != NULL) { - if (message_arena != NULL) { - message_arena->Own(source_context); - } + delete reinterpret_cast< ::google::protobuf::MessageLite*>(source_context_); } - source_context_ = source_context; if (source_context) { + ::google::protobuf::Arena* submessage_arena = NULL; + if (message_arena != submessage_arena) { + source_context = ::google::protobuf::internal::GetOwnedMessage( + message_arena, source_context, submessage_arena); + } } else { } + source_context_ = source_context; // @@protoc_insertion_point(field_set_allocated:google.protobuf.Type.source_context) } -inline ::google::protobuf::SourceContext* Type::unsafe_arena_release_source_context() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Type.source_context) - - ::google::protobuf::SourceContext* temp = source_context_; - source_context_ = NULL; - return temp; -} // .google.protobuf.Syntax syntax = 6; inline void Type::clear_syntax() { @@ -1523,13 +1563,6 @@ inline ::std::string* Field::release_name() { return name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* Field::unsafe_arena_release_name() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Field.name) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - - return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void Field::set_allocated_name(::std::string* name) { if (name != NULL) { @@ -1540,6 +1573,13 @@ inline void Field::set_allocated_name(::std::string* name) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.Field.name) } +inline ::std::string* Field::unsafe_arena_release_name() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Field.name) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + + return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void Field::unsafe_arena_set_allocated_name( ::std::string* name) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -1598,13 +1638,6 @@ inline ::std::string* Field::release_type_url() { return type_url_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* Field::unsafe_arena_release_type_url() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Field.type_url) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - - return type_url_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void Field::set_allocated_type_url(::std::string* type_url) { if (type_url != NULL) { @@ -1615,6 +1648,13 @@ inline void Field::set_allocated_type_url(::std::string* type_url) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.Field.type_url) } +inline ::std::string* Field::unsafe_arena_release_type_url() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Field.type_url) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + + return type_url_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void Field::unsafe_arena_set_allocated_type_url( ::std::string* type_url) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -1731,13 +1771,6 @@ inline ::std::string* Field::release_json_name() { return json_name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* Field::unsafe_arena_release_json_name() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Field.json_name) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - - return json_name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void Field::set_allocated_json_name(::std::string* json_name) { if (json_name != NULL) { @@ -1748,6 +1781,13 @@ inline void Field::set_allocated_json_name(::std::string* json_name) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.Field.json_name) } +inline ::std::string* Field::unsafe_arena_release_json_name() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Field.json_name) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + + return json_name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void Field::unsafe_arena_set_allocated_json_name( ::std::string* json_name) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -1806,13 +1846,6 @@ inline ::std::string* Field::release_default_value() { return default_value_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* Field::unsafe_arena_release_default_value() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Field.default_value) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - - return default_value_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void Field::set_allocated_default_value(::std::string* default_value) { if (default_value != NULL) { @@ -1823,6 +1856,13 @@ inline void Field::set_allocated_default_value(::std::string* default_value) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.Field.default_value) } +inline ::std::string* Field::unsafe_arena_release_default_value() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Field.default_value) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + + return default_value_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void Field::unsafe_arena_set_allocated_default_value( ::std::string* default_value) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -1885,13 +1925,6 @@ inline ::std::string* Enum::release_name() { return name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* Enum::unsafe_arena_release_name() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Enum.name) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - - return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void Enum::set_allocated_name(::std::string* name) { if (name != NULL) { @@ -1902,6 +1935,13 @@ inline void Enum::set_allocated_name(::std::string* name) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.Enum.name) } +inline ::std::string* Enum::unsafe_arena_release_name() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Enum.name) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + + return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void Enum::unsafe_arena_set_allocated_name( ::std::string* name) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -1979,16 +2019,29 @@ Enum::options() const { inline bool Enum::has_source_context() const { return this != internal_default_instance() && source_context_ != NULL; } -inline void Enum::clear_source_context() { - if (GetArenaNoVirtual() == NULL && source_context_ != NULL) delete source_context_; - source_context_ = NULL; -} inline const ::google::protobuf::SourceContext& Enum::source_context() const { const ::google::protobuf::SourceContext* p = source_context_; // @@protoc_insertion_point(field_get:google.protobuf.Enum.source_context) return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::SourceContext*>( &::google::protobuf::_SourceContext_default_instance_); } +inline ::google::protobuf::SourceContext* Enum::release_source_context() { + // @@protoc_insertion_point(field_release:google.protobuf.Enum.source_context) + + ::google::protobuf::SourceContext* temp = source_context_; + if (GetArenaNoVirtual() != NULL) { + temp = ::google::protobuf::internal::DuplicateIfNonNull(temp, NULL); + } + source_context_ = NULL; + return temp; +} +inline ::google::protobuf::SourceContext* Enum::unsafe_arena_release_source_context() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Enum.source_context) + + ::google::protobuf::SourceContext* temp = source_context_; + source_context_ = NULL; + return temp; +} inline ::google::protobuf::SourceContext* Enum::mutable_source_context() { if (source_context_ == NULL) { @@ -1997,42 +2050,24 @@ inline ::google::protobuf::SourceContext* Enum::mutable_source_context() { // @@protoc_insertion_point(field_mutable:google.protobuf.Enum.source_context) return source_context_; } -inline ::google::protobuf::SourceContext* Enum::release_source_context() { - // @@protoc_insertion_point(field_release:google.protobuf.Enum.source_context) - - if (GetArenaNoVirtual() != NULL) { - return _slow_release_source_context(); - } else { - ::google::protobuf::SourceContext* temp = source_context_; - source_context_ = NULL; - return temp; - } -} -inline void Enum::set_allocated_source_context(::google::protobuf::SourceContext* source_context) { +inline void Enum::set_allocated_source_context(::google::protobuf::SourceContext* source_context) { ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); if (message_arena == NULL) { - delete source_context_; - } - if (source_context != NULL) { - if (message_arena != NULL) { - message_arena->Own(source_context); - } + delete reinterpret_cast< ::google::protobuf::MessageLite*>(source_context_); } - source_context_ = source_context; if (source_context) { + ::google::protobuf::Arena* submessage_arena = NULL; + if (message_arena != submessage_arena) { + source_context = ::google::protobuf::internal::GetOwnedMessage( + message_arena, source_context, submessage_arena); + } } else { } + source_context_ = source_context; // @@protoc_insertion_point(field_set_allocated:google.protobuf.Enum.source_context) } -inline ::google::protobuf::SourceContext* Enum::unsafe_arena_release_source_context() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Enum.source_context) - - ::google::protobuf::SourceContext* temp = source_context_; - source_context_ = NULL; - return temp; -} // .google.protobuf.Syntax syntax = 5; inline void Enum::clear_syntax() { @@ -2097,13 +2132,6 @@ inline ::std::string* EnumValue::release_name() { return name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* EnumValue::unsafe_arena_release_name() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.EnumValue.name) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - - return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void EnumValue::set_allocated_name(::std::string* name) { if (name != NULL) { @@ -2114,6 +2142,13 @@ inline void EnumValue::set_allocated_name(::std::string* name) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.EnumValue.name) } +inline ::std::string* EnumValue::unsafe_arena_release_name() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.EnumValue.name) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + + return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void EnumValue::unsafe_arena_set_allocated_name( ::std::string* name) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -2220,13 +2255,6 @@ inline ::std::string* Option::release_name() { return name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* Option::unsafe_arena_release_name() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Option.name) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - - return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void Option::set_allocated_name(::std::string* name) { if (name != NULL) { @@ -2237,6 +2265,13 @@ inline void Option::set_allocated_name(::std::string* name) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.Option.name) } +inline ::std::string* Option::unsafe_arena_release_name() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Option.name) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + + return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void Option::unsafe_arena_set_allocated_name( ::std::string* name) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -2254,16 +2289,29 @@ inline void Option::unsafe_arena_set_allocated_name( inline bool Option::has_value() const { return this != internal_default_instance() && value_ != NULL; } -inline void Option::clear_value() { - if (GetArenaNoVirtual() == NULL && value_ != NULL) delete value_; - value_ = NULL; -} inline const ::google::protobuf::Any& Option::value() const { const ::google::protobuf::Any* p = value_; // @@protoc_insertion_point(field_get:google.protobuf.Option.value) return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::Any*>( &::google::protobuf::_Any_default_instance_); } +inline ::google::protobuf::Any* Option::release_value() { + // @@protoc_insertion_point(field_release:google.protobuf.Option.value) + + ::google::protobuf::Any* temp = value_; + if (GetArenaNoVirtual() != NULL) { + temp = ::google::protobuf::internal::DuplicateIfNonNull(temp, NULL); + } + value_ = NULL; + return temp; +} +inline ::google::protobuf::Any* Option::unsafe_arena_release_value() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Option.value) + + ::google::protobuf::Any* temp = value_; + value_ = NULL; + return temp; +} inline ::google::protobuf::Any* Option::mutable_value() { if (value_ == NULL) { @@ -2272,42 +2320,24 @@ inline ::google::protobuf::Any* Option::mutable_value() { // @@protoc_insertion_point(field_mutable:google.protobuf.Option.value) return value_; } -inline ::google::protobuf::Any* Option::release_value() { - // @@protoc_insertion_point(field_release:google.protobuf.Option.value) - - if (GetArenaNoVirtual() != NULL) { - return _slow_release_value(); - } else { - ::google::protobuf::Any* temp = value_; - value_ = NULL; - return temp; - } -} -inline void Option::set_allocated_value(::google::protobuf::Any* value) { +inline void Option::set_allocated_value(::google::protobuf::Any* value) { ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); if (message_arena == NULL) { - delete value_; - } - if (value != NULL) { - if (message_arena != NULL) { - message_arena->Own(value); - } + delete reinterpret_cast< ::google::protobuf::MessageLite*>(value_); } - value_ = value; if (value) { + ::google::protobuf::Arena* submessage_arena = NULL; + if (message_arena != submessage_arena) { + value = ::google::protobuf::internal::GetOwnedMessage( + message_arena, value, submessage_arena); + } } else { } + value_ = value; // @@protoc_insertion_point(field_set_allocated:google.protobuf.Option.value) } -inline ::google::protobuf::Any* Option::unsafe_arena_release_value() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Option.value) - - ::google::protobuf::Any* temp = value_; - value_ = NULL; - return temp; -} #ifdef __GNUC__ #pragma GCC diagnostic pop diff --git a/src/google/protobuf/unknown_field_set.h b/src/google/protobuf/unknown_field_set.h index beb4c9ec..619855ed 100644 --- a/src/google/protobuf/unknown_field_set.h +++ b/src/google/protobuf/unknown_field_set.h @@ -43,7 +43,7 @@ #include <vector> #include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/logging.h> -#include <google/protobuf/generated_message_util.h> +#include <google/protobuf/message_lite.h> namespace google { namespace protobuf { diff --git a/src/google/protobuf/util/field_mask_util.cc b/src/google/protobuf/util/field_mask_util.cc index 982d6407..4d0d3a46 100644 --- a/src/google/protobuf/util/field_mask_util.cc +++ b/src/google/protobuf/util/field_mask_util.cc @@ -192,6 +192,13 @@ class FieldMaskTree { // children removed because the path matches all the node's children. void AddPath(const string& path); + // Remove a path from the tree. + // If the path is a sub-path of an existing field path in the tree, it means + // we need remove the existing fied path and add all sub-paths except + // specified path. If the path matches an existing node in the tree, this node + // will be moved. + void RemovePath(const string& path, const Descriptor* descriptor); + // Calculate the intersection part of a field path with this tree and add // the intersection field path into out. void IntersectPath(const string& path, FieldMaskTree* out); @@ -333,6 +340,59 @@ void FieldMaskTree::AddPath(const string& path) { } } +void FieldMaskTree::RemovePath(const string& path, + const Descriptor* descriptor) { + std::vector<string> parts = Split(path, "."); + if (parts.empty()) { + return; + } + std::vector<Node*> nodes(parts.size()); + Node* node = &root_; + const Descriptor* current_descriptor = descriptor; + Node* new_branch_node = NULL; + for (int i = 0; i < parts.size(); ++i) { + nodes[i] = node; + const FieldDescriptor* field_descriptor = + current_descriptor->FindFieldByName(parts[i]); + if (field_descriptor == NULL || + (field_descriptor->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE && + i != parts.size() - 1)) { + // Invalid path. + if (new_branch_node != NULL) { + // If add any new nodes, cleanup. + new_branch_node->ClearChildren(); + } + return; + } + + if (node->children.empty()) { + if (new_branch_node == NULL) { + new_branch_node = node; + } + for (int i = 0; i < current_descriptor->field_count(); ++i) { + node->children[current_descriptor->field(i)->name()] = new Node(); + } + } + if (ContainsKey(node->children, parts[i])) { + node = node->children.at(parts[i]); + if (field_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { + current_descriptor = field_descriptor->message_type(); + } + } else { + // Path does not exist. + return; + } + } + // Remove path. + for (int i = parts.size() - 1; i >= 0; i--) { + delete nodes[i]->children[parts[i]]; + nodes[i]->children.erase(parts[i]); + if (!nodes[i]->children.empty()) { + break; + } + } +} + void FieldMaskTree::IntersectPath(const string& path, FieldMaskTree* out) { std::vector<string> parts = Split(path, "."); if (parts.empty()) { @@ -560,6 +620,22 @@ void FieldMaskUtil::Intersect(const FieldMask& mask1, const FieldMask& mask2, intersection.MergeToFieldMask(out); } +void FieldMaskUtil::InternalSubtract(const Descriptor* descriptor, + const FieldMask& mask1, + const FieldMask& mask2, FieldMask* out) { + if (mask1.paths().empty()) { + out->Clear(); + return; + } + FieldMaskTree tree; + tree.MergeFromFieldMask(mask1); + for (int i = 0; i < mask2.paths_size(); ++i) { + tree.RemovePath(mask2.paths(i), descriptor); + } + out->Clear(); + tree.MergeToFieldMask(out); +} + bool FieldMaskUtil::IsPathInFieldMask(StringPiece path, const FieldMask& mask) { for (int i = 0; i < mask.paths_size(); ++i) { const string& mask_path = mask.paths(i); diff --git a/src/google/protobuf/util/field_mask_util.h b/src/google/protobuf/util/field_mask_util.h index 71c68fec..01642c6f 100644 --- a/src/google/protobuf/util/field_mask_util.h +++ b/src/google/protobuf/util/field_mask_util.h @@ -113,6 +113,13 @@ class LIBPROTOBUF_EXPORT FieldMaskUtil { static void Intersect(const FieldMask& mask1, const FieldMask& mask2, FieldMask* out); + // Subtracts mask2 from mask1 base of type T. + template <typename T> + static void Subtract(const FieldMask& mask1, const FieldMask& mask2, + FieldMask* out) { + InternalSubtract(T::descriptor(), mask1, mask2, out); + } + // Returns true if path is covered by the given FieldMask. Note that path // "foo.bar" covers all paths like "foo.bar.baz", "foo.bar.quz.x", etc. static bool IsPathInFieldMask(StringPiece path, const FieldMask& mask); @@ -167,6 +174,10 @@ class LIBPROTOBUF_EXPORT FieldMaskUtil { static void InternalGetFieldMaskForAllFields(const Descriptor* descriptor, FieldMask* out); + + static void InternalSubtract(const Descriptor* descriptor, + const FieldMask& mask1, const FieldMask& mask2, + FieldMask* out); }; // Note that for compatibility with the defined behaviour for FieldMask in diff --git a/src/google/protobuf/util/field_mask_util_test.cc b/src/google/protobuf/util/field_mask_util_test.cc index 24943ed1..7939f733 100644 --- a/src/google/protobuf/util/field_mask_util_test.cc +++ b/src/google/protobuf/util/field_mask_util_test.cc @@ -348,6 +348,46 @@ TEST(FieldMaskUtilTest, TestIntersect) { EXPECT_EQ("foo.bar.baz", FieldMaskUtil::ToString(out)); } +TEST(FieldMaskUtilTest, TestSubtract) { + FieldMask mask1, mask2, out; + // Normal case. + FieldMaskUtil::FromString( + "optional_int32,optional_uint64,optional_nested_message,optional_foreign_" + "message,repeated_int32,repeated_foreign_message,repeated_nested_message." + "bb", + &mask1); + + FieldMaskUtil::FromString( + "optional_int32,optional_nested_message.bb,optional_foreign_message.c," + "repeated_int32,repeated_nested_message.bb,repeated_foreign_message.f," + "repeated_foreign_message.d,repeated_nested_message.bb,repeated_uint32", + &mask2); + + FieldMaskUtil::Subtract<TestAllTypes>(mask1, mask2, &out); + EXPECT_EQ( + "optional_foreign_message.d,optional_uint64,repeated_foreign_message.c", + FieldMaskUtil::ToString(out)); + + // mask1 is empty. + FieldMaskUtil::FromString("", &mask1); + FieldMaskUtil::Subtract<TestAllTypes>(mask1, mask2, &out); + EXPECT_EQ("", FieldMaskUtil::ToString(out)); + + // mask1 is "optional_nested_message" and mask2 is + // "optional_nested_message.nonexist_field". + FieldMaskUtil::FromString("optional_nested_message", &mask1); + FieldMaskUtil::FromString("optional_nested_message.nonexist_field", &mask2); + FieldMaskUtil::Subtract<TestAllTypes>(mask1, mask2, &out); + EXPECT_EQ("optional_nested_message", FieldMaskUtil::ToString(out)); + + // mask1 is "optional_nested_message" and mask2 is + // "optional_nested_message". + FieldMaskUtil::FromString("optional_nested_message", &mask1); + FieldMaskUtil::FromString("optional_nested_message", &mask2); + FieldMaskUtil::Subtract<TestAllTypes>(mask1, mask2, &out); + EXPECT_EQ("", FieldMaskUtil::ToString(out)); +} + TEST(FieldMaskUtilTest, TestIspathInFieldMask) { FieldMask mask; FieldMaskUtil::FromString("foo.bar", &mask); diff --git a/src/google/protobuf/util/internal/json_stream_parser.cc b/src/google/protobuf/util/internal/json_stream_parser.cc index 047c14e1..2ada3583 100644 --- a/src/google/protobuf/util/internal/json_stream_parser.cc +++ b/src/google/protobuf/util/internal/json_stream_parser.cc @@ -498,6 +498,19 @@ util::Status JsonStreamParser::ParseNumber() { return result; } +util::Status JsonStreamParser::ParseDoubleHelper( + const string& number, NumberResult* result) { + if (!safe_strtod(number, &result->double_val)) { + return ReportFailure("Unable to parse number."); + } + if (!loose_float_number_conversion_ && + !MathLimits<double>::IsFinite(result->double_val)) { + return ReportFailure("Number exceeds the range of double."); + } + result->type = NumberResult::DOUBLE; + return util::Status(); +} + util::Status JsonStreamParser::ParseNumberHelper(NumberResult* result) { const char* data = p_.data(); int length = p_.length(); @@ -533,16 +546,11 @@ util::Status JsonStreamParser::ParseNumberHelper(NumberResult* result) { // Floating point number, parse as a double. if (floating) { - if (!safe_strtod(number, &result->double_val)) { - return ReportFailure("Unable to parse number."); + util::Status status = ParseDoubleHelper(number, result); + if (status.ok()) { + p_.remove_prefix(index); } - if (!loose_float_number_conversion_ && - !MathLimits<double>::IsFinite(result->double_val)) { - return ReportFailure("Number exceeds the range of double."); - } - result->type = NumberResult::DOUBLE; - p_.remove_prefix(index); - return util::Status(); + return status; } // Positive non-floating point number, parse as a uint64. @@ -551,12 +559,18 @@ util::Status JsonStreamParser::ParseNumberHelper(NumberResult* result) { if (number.length() >= 2 && number[0] == '0') { return ReportFailure("Octal/hex numbers are not valid JSON values."); } - if (!safe_strtou64(number, &result->uint_val)) { - return ReportFailure("Unable to parse number."); + if (safe_strtou64(number, &result->uint_val)) { + result->type = NumberResult::UINT; + p_.remove_prefix(index); + return util::Status(); + } else { + // If the value is too large, parse it as double. + util::Status status = ParseDoubleHelper(number, result); + if (status.ok()) { + p_.remove_prefix(index); + } + return status; } - result->type = NumberResult::UINT; - p_.remove_prefix(index); - return util::Status(); } // Octal/Hex numbers are not valid JSON values. @@ -564,12 +578,18 @@ util::Status JsonStreamParser::ParseNumberHelper(NumberResult* result) { return ReportFailure("Octal/hex numbers are not valid JSON values."); } // Negative non-floating point number, parse as an int64. - if (!safe_strto64(number, &result->int_val)) { - return ReportFailure("Unable to parse number."); + if (safe_strto64(number, &result->int_val)) { + result->type = NumberResult::INT; + p_.remove_prefix(index); + return util::Status(); + } else { + // If the value is too large, parse it as double. + util::Status status = ParseDoubleHelper(number, result); + if (status.ok()) { + p_.remove_prefix(index); + } + return status; } - result->type = NumberResult::INT; - p_.remove_prefix(index); - return util::Status(); } util::Status JsonStreamParser::HandleBeginObject() { diff --git a/src/google/protobuf/util/internal/json_stream_parser.h b/src/google/protobuf/util/internal/json_stream_parser.h index 6b9d46ee..31933b67 100644 --- a/src/google/protobuf/util/internal/json_stream_parser.h +++ b/src/google/protobuf/util/internal/json_stream_parser.h @@ -154,6 +154,9 @@ class LIBPROTOBUF_EXPORT JsonStreamParser { // component. util::Status ParseNumberHelper(NumberResult* result); + // Parse a number as double into a NumberResult. + util::Status ParseDoubleHelper(const string& number, NumberResult* result); + // Handles a { during parsing of a value. util::Status HandleBeginObject(); diff --git a/src/google/protobuf/util/internal/json_stream_parser_test.cc b/src/google/protobuf/util/internal/json_stream_parser_test.cc index ca71ff24..a11e9be0 100644 --- a/src/google/protobuf/util/internal/json_stream_parser_test.cc +++ b/src/google/protobuf/util/internal/json_stream_parser_test.cc @@ -694,20 +694,19 @@ TEST_F(JsonStreamParserTest, ExtraCharactersAfterObject) { } } -// numbers too large -TEST_F(JsonStreamParserTest, PositiveNumberTooBig) { - StringPiece str = "[18446744073709551616]"; // 2^64 +TEST_F(JsonStreamParserTest, PositiveNumberTooBigIsDouble) { + StringPiece str = "18446744073709551616"; // 2^64 for (int i = 0; i <= str.length(); ++i) { - ow_.StartList(""); - DoErrorTest(str, i, "Unable to parse number."); + ow_.RenderDouble("", 18446744073709552000.0); + DoTest(str, i); } } -TEST_F(JsonStreamParserTest, NegativeNumberTooBig) { - StringPiece str = "[-18446744073709551616]"; +TEST_F(JsonStreamParserTest, NegativeNumberTooBigIsDouble) { + StringPiece str = "-18446744073709551616"; for (int i = 0; i <= str.length(); ++i) { - ow_.StartList(""); - DoErrorTest(str, i, "Unable to parse number."); + ow_.RenderDouble("", -18446744073709551616.0); + DoTest(str, i); } } diff --git a/src/google/protobuf/util/message_differencer.cc b/src/google/protobuf/util/message_differencer.cc index d62038ad..e964e041 100644 --- a/src/google/protobuf/util/message_differencer.cc +++ b/src/google/protobuf/util/message_differencer.cc @@ -1440,9 +1440,6 @@ bool MessageDifferencer::MatchRepeatedFieldIndices( match_list1->assign(count1, -1); match_list2->assign(count2, -1); - SpecificField specific_field; - specific_field.field = repeated_field; - bool success = true; // Find potential match if this is a special repeated field. if (key_comparator != NULL || IsTreatedAsSet(repeated_field)) { @@ -1469,20 +1466,15 @@ bool MessageDifferencer::MatchRepeatedFieldIndices( // Indicates any matched elements for this repeated field. bool match = false; - specific_field.index = i; - specific_field.new_index = i; - for (int j = 0; j < count2; j++) { if (match_list2->at(j) != -1) continue; - specific_field.index = i; - specific_field.new_index = j; match = IsMatch(repeated_field, key_comparator, &message1, &message2, parent_fields, i, j); if (match) { - match_list1->at(specific_field.index) = specific_field.new_index; - match_list2->at(specific_field.new_index) = specific_field.index; + match_list1->at(i) = j; + match_list2->at(j) = i; break; } } diff --git a/src/google/protobuf/wire_format_lite.h b/src/google/protobuf/wire_format_lite.h index 8a1540b7..cf614c02 100644 --- a/src/google/protobuf/wire_format_lite.h +++ b/src/google/protobuf/wire_format_lite.h @@ -336,7 +336,6 @@ class LIBPROTOBUF_EXPORT WireFormatLite { static bool ReadBytes(io::CodedInputStream* input, string* value); static bool ReadBytes(io::CodedInputStream* input, string** p); - enum Operation { PARSE = 0, SERIALIZE = 1, @@ -855,20 +854,24 @@ inline double WireFormatLite::DecodeDouble(uint64 value) { inline uint32 WireFormatLite::ZigZagEncode32(int32 n) { // Note: the right-shift must be arithmetic - return static_cast<uint32>((n << 1) ^ (n >> 31)); + // Note: left shift must be unsigned because of overflow + return (static_cast<uint32>(n) << 1) ^ static_cast<uint32>(n >> 31); } inline int32 WireFormatLite::ZigZagDecode32(uint32 n) { - return static_cast<int32>(n >> 1) ^ -static_cast<int32>(n & 1); + // Note: Using unsigned types prevent undefined behavior + return static_cast<int32>((n >> 1) ^ -(n & 1)); } inline uint64 WireFormatLite::ZigZagEncode64(int64 n) { // Note: the right-shift must be arithmetic - return static_cast<uint64>((n << 1) ^ (n >> 63)); + // Note: left shift must be unsigned because of overflow + return (static_cast<uint64>(n) << 1) ^ static_cast<uint64>(n >> 63); } inline int64 WireFormatLite::ZigZagDecode64(uint64 n) { - return static_cast<int64>(n >> 1) ^ -static_cast<int64>(n & 1); + // Note: Using unsigned types prevent undefined behavior + return static_cast<int64>((n >> 1) ^ -(n & 1)); } // String is for UTF-8 text only, but, even so, ReadString() can simply diff --git a/src/google/protobuf/wire_format_lite_inl.h b/src/google/protobuf/wire_format_lite_inl.h index c044def8..b264bd7e 100644 --- a/src/google/protobuf/wire_format_lite_inl.h +++ b/src/google/protobuf/wire_format_lite_inl.h @@ -426,7 +426,6 @@ bool WireFormatLite::ReadPackedPrimitiveNoInline(io::CodedInputStream* input, } - inline bool WireFormatLite::ReadGroup(int field_number, io::CodedInputStream* input, MessageLite* value) { diff --git a/src/google/protobuf/wrappers.pb.cc b/src/google/protobuf/wrappers.pb.cc index 110b6b56..00e01256 100644 --- a/src/google/protobuf/wrappers.pb.cc +++ b/src/google/protobuf/wrappers.pb.cc @@ -14,6 +14,10 @@ #include <google/protobuf/generated_message_reflection.h> #include <google/protobuf/reflection_ops.h> #include <google/protobuf/wire_format.h> +// This is a temporary google only hack +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS +#include "third_party/protobuf/version.h" +#endif // @@protoc_insertion_point(includes) namespace google { namespace protobuf { @@ -68,7 +72,11 @@ namespace protobuf_google_2fprotobuf_2fwrappers_2eproto { void InitDefaultsDoubleValueImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_DoubleValue_default_instance_; new (ptr) ::google::protobuf::DoubleValue(); @@ -85,7 +93,11 @@ void InitDefaultsDoubleValue() { void InitDefaultsFloatValueImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_FloatValue_default_instance_; new (ptr) ::google::protobuf::FloatValue(); @@ -102,7 +114,11 @@ void InitDefaultsFloatValue() { void InitDefaultsInt64ValueImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_Int64Value_default_instance_; new (ptr) ::google::protobuf::Int64Value(); @@ -119,7 +135,11 @@ void InitDefaultsInt64Value() { void InitDefaultsUInt64ValueImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_UInt64Value_default_instance_; new (ptr) ::google::protobuf::UInt64Value(); @@ -136,7 +156,11 @@ void InitDefaultsUInt64Value() { void InitDefaultsInt32ValueImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_Int32Value_default_instance_; new (ptr) ::google::protobuf::Int32Value(); @@ -153,7 +177,11 @@ void InitDefaultsInt32Value() { void InitDefaultsUInt32ValueImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_UInt32Value_default_instance_; new (ptr) ::google::protobuf::UInt32Value(); @@ -170,7 +198,11 @@ void InitDefaultsUInt32Value() { void InitDefaultsBoolValueImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_BoolValue_default_instance_; new (ptr) ::google::protobuf::BoolValue(); @@ -187,7 +219,11 @@ void InitDefaultsBoolValue() { void InitDefaultsStringValueImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_StringValue_default_instance_; new (ptr) ::google::protobuf::StringValue(); @@ -204,7 +240,11 @@ void InitDefaultsStringValue() { void InitDefaultsBytesValueImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; +#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS + ::google::protobuf::internal::InitProtobufDefaultsForceUnique(); +#else ::google::protobuf::internal::InitProtobufDefaults(); +#endif // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS { void* ptr = &::google::protobuf::_BytesValue_default_instance_; new (ptr) ::google::protobuf::BytesValue(); @@ -399,12 +439,7 @@ DoubleValue::~DoubleValue() { } void DoubleValue::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void DoubleValue::ArenaDtor(void* object) { @@ -666,12 +701,7 @@ FloatValue::~FloatValue() { } void FloatValue::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void FloatValue::ArenaDtor(void* object) { @@ -933,12 +963,7 @@ Int64Value::~Int64Value() { } void Int64Value::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void Int64Value::ArenaDtor(void* object) { @@ -1202,12 +1227,7 @@ UInt64Value::~UInt64Value() { } void UInt64Value::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void UInt64Value::ArenaDtor(void* object) { @@ -1471,12 +1491,7 @@ Int32Value::~Int32Value() { } void Int32Value::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void Int32Value::ArenaDtor(void* object) { @@ -1740,12 +1755,7 @@ UInt32Value::~UInt32Value() { } void UInt32Value::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void UInt32Value::ArenaDtor(void* object) { @@ -2009,12 +2019,7 @@ BoolValue::~BoolValue() { } void BoolValue::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); } void BoolValue::ArenaDtor(void* object) { @@ -2280,13 +2285,8 @@ StringValue::~StringValue() { } void StringValue::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - - value_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); + value_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } void StringValue::ArenaDtor(void* object) { @@ -2567,13 +2567,8 @@ BytesValue::~BytesValue() { } void BytesValue::SharedDtor() { - ::google::protobuf::Arena* arena = GetArenaNoVirtual(); - GOOGLE_DCHECK(arena == NULL); - if (arena != NULL) { - return; - } - - value_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); + value_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } void BytesValue::ArenaDtor(void* object) { diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index 9ed1c0b2..be49c3ec 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -1013,7 +1013,13 @@ class LIBPROTOBUF_EXPORT StringValue : public ::google::protobuf::Message /* @@p ::std::string* mutable_value(); ::std::string* release_value(); void set_allocated_value(::std::string* value); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_value(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_value( ::std::string* value); @@ -1138,7 +1144,13 @@ class LIBPROTOBUF_EXPORT BytesValue : public ::google::protobuf::Message /* @@pr ::std::string* mutable_value(); ::std::string* release_value(); void set_allocated_value(::std::string* value); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") ::std::string* unsafe_arena_release_value(); + PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") void unsafe_arena_set_allocated_value( ::std::string* value); @@ -1336,13 +1348,6 @@ inline ::std::string* StringValue::release_value() { return value_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* StringValue::unsafe_arena_release_value() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.StringValue.value) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - - return value_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void StringValue::set_allocated_value(::std::string* value) { if (value != NULL) { @@ -1353,6 +1358,13 @@ inline void StringValue::set_allocated_value(::std::string* value) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.StringValue.value) } +inline ::std::string* StringValue::unsafe_arena_release_value() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.StringValue.value) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + + return value_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void StringValue::unsafe_arena_set_allocated_value( ::std::string* value) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); @@ -1415,13 +1427,6 @@ inline ::std::string* BytesValue::release_value() { return value_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } -inline ::std::string* BytesValue::unsafe_arena_release_value() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.BytesValue.value) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - - return value_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); -} inline void BytesValue::set_allocated_value(::std::string* value) { if (value != NULL) { @@ -1432,6 +1437,13 @@ inline void BytesValue::set_allocated_value(::std::string* value) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.BytesValue.value) } +inline ::std::string* BytesValue::unsafe_arena_release_value() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.BytesValue.value) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + + return value_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} inline void BytesValue::unsafe_arena_set_allocated_value( ::std::string* value) { GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); |