Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: third_party/protobuf/src/google/protobuf/message_lite.cc

Issue 1291903002: Pull new version of protobuf sources. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Build fix attempts Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..da6e933b0c4a76388fa0b343b980e3eb1d69bbab 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,6 +34,8 @@
// 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/common.h>
#include <google/protobuf/io/coded_stream.h>
@@ -153,6 +155,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 +244,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 +294,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 +338,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 +354,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
« no previous file with comments | « third_party/protobuf/src/google/protobuf/message_lite.h ('k') | third_party/protobuf/src/google/protobuf/message_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698