| Index: third_party/protobuf/src/google/protobuf/message_lite.cc
|
| diff --git a/third_party/protobuf/src/google/protobuf/message_lite.cc b/third_party/protobuf/src/google/protobuf/message_lite.cc
|
| index 49dbe6e09d9a2cc7674af69e0ba1ecb9ad8a2dde..5bd8bcfb12f3a51478e3a75b249627fc23364118 100644
|
| --- a/third_party/protobuf/src/google/protobuf/message_lite.cc
|
| +++ b/third_party/protobuf/src/google/protobuf/message_lite.cc
|
| @@ -1,6 +1,6 @@
|
| // Protocol Buffers - Google's data interchange format
|
| // Copyright 2008 Google Inc. All rights reserved.
|
| -// http://code.google.com/p/protobuf/
|
| +// 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
|
| @@ -34,7 +34,10 @@
|
| // Sanjay Ghemawat, Jeff Dean, and others.
|
|
|
| #include <google/protobuf/message_lite.h>
|
| +#include <google/protobuf/arena.h>
|
| +#include <google/protobuf/repeated_field.h>
|
| #include <string>
|
| +#include <google/protobuf/stubs/logging.h>
|
| #include <google/protobuf/stubs/common.h>
|
| #include <google/protobuf/io/coded_stream.h>
|
| #include <google/protobuf/io/zero_copy_stream_impl_lite.h>
|
| @@ -97,27 +100,19 @@ string InitializationErrorMessage(const char* action,
|
| // call MergePartialFromCodedStream(). However, when parsing very small
|
| // messages, every function call introduces significant overhead. To avoid
|
| // this without reproducing code, we use these forced-inline helpers.
|
| -//
|
| -// Note: GCC only allows GOOGLE_ATTRIBUTE_ALWAYS_INLINE on declarations, not
|
| -// definitions.
|
| +GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool InlineMergeFromCodedStream(
|
| + io::CodedInputStream* input, MessageLite* message);
|
| +GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool InlineParseFromCodedStream(
|
| + io::CodedInputStream* input, MessageLite* message);
|
| +GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool InlineParsePartialFromCodedStream(
|
| + io::CodedInputStream* input, MessageLite* message);
|
| +GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool InlineParseFromArray(
|
| + const void* data, int size, MessageLite* message);
|
| +GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool InlineParsePartialFromArray(
|
| + const void* data, int size, MessageLite* message);
|
| +
|
| inline bool InlineMergeFromCodedStream(io::CodedInputStream* input,
|
| - MessageLite* message)
|
| - GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
|
| -inline bool InlineParseFromCodedStream(io::CodedInputStream* input,
|
| - MessageLite* message)
|
| - GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
|
| -inline bool InlineParsePartialFromCodedStream(io::CodedInputStream* input,
|
| - MessageLite* message)
|
| - GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
|
| -inline bool InlineParseFromArray(const void* data, int size,
|
| - MessageLite* message)
|
| - GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
|
| -inline bool InlineParsePartialFromArray(const void* data, int size,
|
| - MessageLite* message)
|
| - GOOGLE_ATTRIBUTE_ALWAYS_INLINE;
|
| -
|
| -bool InlineMergeFromCodedStream(io::CodedInputStream* input,
|
| - MessageLite* message) {
|
| + MessageLite* message) {
|
| if (!message->MergePartialFromCodedStream(input)) return false;
|
| if (!message->IsInitialized()) {
|
| GOOGLE_LOG(ERROR) << InitializationErrorMessage("parse", *message);
|
| @@ -126,26 +121,27 @@ bool InlineMergeFromCodedStream(io::CodedInputStream* input,
|
| return true;
|
| }
|
|
|
| -bool InlineParseFromCodedStream(io::CodedInputStream* input,
|
| - MessageLite* message) {
|
| +inline bool InlineParseFromCodedStream(io::CodedInputStream* input,
|
| + MessageLite* message) {
|
| message->Clear();
|
| return InlineMergeFromCodedStream(input, message);
|
| }
|
|
|
| -bool InlineParsePartialFromCodedStream(io::CodedInputStream* input,
|
| - MessageLite* message) {
|
| +inline bool InlineParsePartialFromCodedStream(io::CodedInputStream* input,
|
| + MessageLite* message) {
|
| message->Clear();
|
| return message->MergePartialFromCodedStream(input);
|
| }
|
|
|
| -bool InlineParseFromArray(const void* data, int size, MessageLite* message) {
|
| +inline bool InlineParseFromArray(
|
| + const void* data, int size, MessageLite* message) {
|
| io::CodedInputStream input(reinterpret_cast<const uint8*>(data), size);
|
| return InlineParseFromCodedStream(&input, message) &&
|
| input.ConsumedEntireMessage();
|
| }
|
|
|
| -bool InlineParsePartialFromArray(const void* data, int size,
|
| - MessageLite* message) {
|
| +inline bool InlineParsePartialFromArray(
|
| + const void* data, int size, MessageLite* message) {
|
| io::CodedInputStream input(reinterpret_cast<const uint8*>(data), size);
|
| return InlineParsePartialFromCodedStream(&input, message) &&
|
| input.ConsumedEntireMessage();
|
| @@ -153,6 +149,15 @@ bool InlineParsePartialFromArray(const void* data, int size,
|
|
|
| } // namespace
|
|
|
| +
|
| +MessageLite* MessageLite::New(::google::protobuf::Arena* arena) const {
|
| + MessageLite* message = New();
|
| + if (arena != NULL) {
|
| + arena->Own(message);
|
| + }
|
| + return message;
|
| +}
|
| +
|
| bool MessageLite::MergeFromCodedStream(io::CodedInputStream* input) {
|
| return InlineMergeFromCodedStream(input, this);
|
| }
|
| @@ -233,6 +238,12 @@ bool MessageLite::SerializeToCodedStream(io::CodedOutputStream* output) const {
|
| bool MessageLite::SerializePartialToCodedStream(
|
| io::CodedOutputStream* output) const {
|
| const int size = ByteSize(); // Force size to be cached.
|
| + if (size < 0) {
|
| + // Messages >2G cannot be serialized due to overflow computing ByteSize.
|
| + GOOGLE_LOG(ERROR) << "Error computing ByteSize (possible overflow?).";
|
| + return false;
|
| + }
|
| +
|
| uint8* buffer = output->GetDirectBufferForNBytesAndAdvance(size);
|
| if (buffer != NULL) {
|
| uint8* end = SerializeWithCachedSizesToArray(buffer);
|
| @@ -277,8 +288,15 @@ bool MessageLite::AppendToString(string* output) const {
|
| bool MessageLite::AppendPartialToString(string* output) const {
|
| int old_size = output->size();
|
| int byte_size = ByteSize();
|
| + if (byte_size < 0) {
|
| + // Messages >2G cannot be serialized due to overflow computing ByteSize.
|
| + GOOGLE_LOG(ERROR) << "Error computing ByteSize (possible overflow?).";
|
| + return false;
|
| + }
|
| +
|
| STLStringResizeUninitialized(output, old_size + byte_size);
|
| - uint8* start = reinterpret_cast<uint8*>(string_as_array(output) + old_size);
|
| + uint8* start =
|
| + reinterpret_cast<uint8*>(io::mutable_string_data(output) + old_size);
|
| uint8* end = SerializeWithCachedSizesToArray(start);
|
| if (end - start != byte_size) {
|
| ByteSizeConsistencyError(byte_size, ByteSize(), end - start);
|
| @@ -314,7 +332,7 @@ bool MessageLite::SerializePartialToArray(void* data, int size) const {
|
|
|
| string MessageLite::SerializeAsString() const {
|
| // If the compiler implements the (Named) Return Value Optimization,
|
| - // the local variable 'result' will not actually reside on the stack
|
| + // the local variable 'output' will not actually reside on the stack
|
| // of this function, but will be overlaid with the object that the
|
| // caller supplied for the return value to be constructed in.
|
| string output;
|
| @@ -330,5 +348,18 @@ string MessageLite::SerializePartialAsString() const {
|
| return output;
|
| }
|
|
|
| +namespace internal {
|
| +template<>
|
| +MessageLite* GenericTypeHandler<MessageLite>::NewFromPrototype(
|
| + const MessageLite* prototype, google::protobuf::Arena* arena) {
|
| + return prototype->New(arena);
|
| +}
|
| +template <>
|
| +void GenericTypeHandler<MessageLite>::Merge(const MessageLite& from,
|
| + MessageLite* to) {
|
| + to->CheckTypeAndMergeFrom(from);
|
| +}
|
| +} // namespace internal
|
| +
|
| } // namespace protobuf
|
| } // namespace google
|
|
|