aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/io
diff options
context:
space:
mode:
authorGravatar Adam Cozzette <acozzette@google.com>2017-09-12 10:32:01 -0700
committerGravatar Adam Cozzette <acozzette@google.com>2017-09-14 10:03:57 -0700
commit13fd045dbb2b4dacea32be162a41d5a4b0d1802f (patch)
treec219e7eb18b82523e36c6748861c403a14ea66ae /src/google/protobuf/io
parentd1bc27caef8377a710370189675cb0958443e8f1 (diff)
Integrated internal changes from Google
Diffstat (limited to 'src/google/protobuf/io')
-rw-r--r--src/google/protobuf/io/coded_stream.cc7
-rw-r--r--src/google/protobuf/io/coded_stream.h41
-rw-r--r--src/google/protobuf/io/zero_copy_stream_impl.cc2
-rw-r--r--src/google/protobuf/io/zero_copy_stream_impl_lite.cc21
-rw-r--r--src/google/protobuf/io/zero_copy_stream_impl_lite.h20
-rw-r--r--src/google/protobuf/io/zero_copy_stream_unittest.cc2
6 files changed, 24 insertions, 69 deletions
diff --git a/src/google/protobuf/io/coded_stream.cc b/src/google/protobuf/io/coded_stream.cc
index 17eb0ffa..79cff2c7 100644
--- a/src/google/protobuf/io/coded_stream.cc
+++ b/src/google/protobuf/io/coded_stream.cc
@@ -315,7 +315,8 @@ namespace {
// The first part of the pair is true iff the read was successful. The second
// part is buffer + (number of bytes read). This function is always inlined,
// so returning a pair is costless.
-GOOGLE_ATTRIBUTE_ALWAYS_INLINE ::std::pair<bool, const uint8*> ReadVarint32FromArray(
+GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE
+::std::pair<bool, const uint8*> ReadVarint32FromArray(
uint32 first_byte, const uint8* buffer,
uint32* value);
inline ::std::pair<bool, const uint8*> ReadVarint32FromArray(
@@ -352,8 +353,8 @@ inline ::std::pair<bool, const uint8*> ReadVarint32FromArray(
return std::make_pair(true, ptr);
}
-GOOGLE_ATTRIBUTE_ALWAYS_INLINE::std::pair<bool, const uint8*> ReadVarint64FromArray(
- const uint8* buffer, uint64* value);
+GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE::std::pair<bool, const uint8*>
+ReadVarint64FromArray(const uint8* buffer, uint64* value);
inline ::std::pair<bool, const uint8*> ReadVarint64FromArray(
const uint8* buffer, uint64* value) {
const uint8* ptr = buffer;
diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h
index 6d2599fb..59db8ce1 100644
--- a/src/google/protobuf/io/coded_stream.h
+++ b/src/google/protobuf/io/coded_stream.h
@@ -134,6 +134,7 @@
#include <google/protobuf/stubs/atomicops.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/port.h>
+#include <google/protobuf/stubs/port.h>
namespace google {
@@ -197,28 +198,23 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
// Like GetDirectBufferPointer, but this method is inlined, and does not
// attempt to Refresh() if the buffer is currently empty.
- GOOGLE_ATTRIBUTE_ALWAYS_INLINE void GetDirectBufferPointerInline(const void** data,
- int* size);
+ GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE
+ void GetDirectBufferPointerInline(const void** data, int* size);
// Read raw bytes, copying them into the given buffer.
bool ReadRaw(void* buffer, int size);
// Like the above, with inlined optimizations. This should only be used
// by the protobuf implementation.
- GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool InternalReadRawInline(void* buffer, int size);
+ GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE
+ bool InternalReadRawInline(void* buffer, int size);
// Like ReadRaw, but reads into a string.
- //
- // Implementation Note: ReadString() grows the string gradually as it
- // reads in the data, rather than allocating the entire requested size
- // upfront. This prevents denial-of-service attacks in which a client
- // could claim that a string is going to be MAX_INT bytes long in order to
- // crash the server because it can't allocate this much space at once.
bool ReadString(string* buffer, int size);
// Like the above, with inlined optimizations. This should only be used
// by the protobuf implementation.
- GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool InternalReadStringInline(string* buffer,
- int size);
+ GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE
+ bool InternalReadStringInline(string* buffer, int size);
// Read a 32-bit little-endian integer.
@@ -261,11 +257,11 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
// Always inline because this is only called in one place per parse loop
// but it is called for every iteration of said loop, so it should be fast.
// GCC doesn't want to inline this by default.
- GOOGLE_ATTRIBUTE_ALWAYS_INLINE uint32 ReadTag() {
+ GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE uint32 ReadTag() {
return last_tag_ = ReadTagNoLastTag();
}
- GOOGLE_ATTRIBUTE_ALWAYS_INLINE uint32 ReadTagNoLastTag();
+ GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE uint32 ReadTagNoLastTag();
// This usually a faster alternative to ReadTag() when cutoff is a manifest
@@ -276,15 +272,15 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
// above cutoff or is 0. (There's intentional wiggle room when tag is 0,
// because that can arise in several ways, and for best performance we want
// to avoid an extra "is tag == 0?" check here.)
- GOOGLE_ATTRIBUTE_ALWAYS_INLINE std::pair<uint32, bool> ReadTagWithCutoff(
- uint32 cutoff) {
+ GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE
+ std::pair<uint32, bool> ReadTagWithCutoff(uint32 cutoff) {
std::pair<uint32, bool> result = ReadTagWithCutoffNoLastTag(cutoff);
last_tag_ = result.first;
return result;
}
- GOOGLE_ATTRIBUTE_ALWAYS_INLINE std::pair<uint32, bool> ReadTagWithCutoffNoLastTag(
- uint32 cutoff);
+ GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE
+ std::pair<uint32, bool> ReadTagWithCutoffNoLastTag(uint32 cutoff);
// Usually returns true if calling ReadVarint32() now would produce the given
// value. Will always return false if ReadVarint32() would not return the
@@ -293,7 +289,7 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
// parameter.
// Always inline because this collapses to a small number of instructions
// when given a constant parameter, but GCC doesn't want to inline by default.
- GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool ExpectTag(uint32 expected);
+ GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE bool ExpectTag(uint32 expected);
// Like above, except this reads from the specified buffer. The caller is
// responsible for ensuring that the buffer is large enough to read a varint
@@ -302,9 +298,8 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
//
// Returns a pointer beyond the expected tag if it was found, or NULL if it
// was not.
- GOOGLE_ATTRIBUTE_ALWAYS_INLINE static const uint8* ExpectTagFromArray(
- const uint8* buffer,
- uint32 expected);
+ GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE
+ static const uint8* ExpectTagFromArray(const uint8* buffer, uint32 expected);
// Usually returns true if no more bytes can be read. Always returns false
// if more bytes can be read. If ExpectAtEnd() returns true, a subsequent
@@ -799,8 +794,8 @@ class LIBPROTOBUF_EXPORT CodedOutputStream {
// but GCC by default doesn't want to inline this.
void WriteTag(uint32 value);
// Like WriteTag() but writing directly to the target array.
- GOOGLE_ATTRIBUTE_ALWAYS_INLINE static uint8* WriteTagToArray(uint32 value,
- uint8* target);
+ GOOGLE_PROTOBUF_ATTRIBUTE_ALWAYS_INLINE
+ static uint8* WriteTagToArray(uint32 value, uint8* target);
// Returns the number of bytes needed to encode the given value as a varint.
static size_t VarintSize32(uint32 value);
diff --git a/src/google/protobuf/io/zero_copy_stream_impl.cc b/src/google/protobuf/io/zero_copy_stream_impl.cc
index 81fb5033..83dec3e6 100644
--- a/src/google/protobuf/io/zero_copy_stream_impl.cc
+++ b/src/google/protobuf/io/zero_copy_stream_impl.cc
@@ -43,9 +43,9 @@
#include <algorithm>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/stubs/io_win32.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/stl_util.h>
+#include <google/protobuf/stubs/io_win32.h>
namespace google {
diff --git a/src/google/protobuf/io/zero_copy_stream_impl_lite.cc b/src/google/protobuf/io/zero_copy_stream_impl_lite.cc
index 60c71c80..66ad49bc 100644
--- a/src/google/protobuf/io/zero_copy_stream_impl_lite.cc
+++ b/src/google/protobuf/io/zero_copy_stream_impl_lite.cc
@@ -196,27 +196,6 @@ void StringOutputStream::SetString(string* target) {
// ===================================================================
-LazyStringOutputStream::LazyStringOutputStream(
- ResultCallback<string*>* callback)
- : StringOutputStream(NULL),
- callback_(GOOGLE_CHECK_NOTNULL(callback)),
- string_is_set_(false) {
-}
-
-bool LazyStringOutputStream::Next(void** data, int* size) {
- if (!string_is_set_) {
- SetString(callback_->Run());
- string_is_set_ = true;
- }
- return StringOutputStream::Next(data, size);
-}
-
-int64 LazyStringOutputStream::ByteCount() const {
- return string_is_set_ ? StringOutputStream::ByteCount() : 0;
-}
-
-// ===================================================================
-
int CopyingInputStream::Skip(int count) {
char junk[4096];
int skipped = 0;
diff --git a/src/google/protobuf/io/zero_copy_stream_impl_lite.h b/src/google/protobuf/io/zero_copy_stream_impl_lite.h
index a7bbc625..ab0fd5ac 100644
--- a/src/google/protobuf/io/zero_copy_stream_impl_lite.h
+++ b/src/google/protobuf/io/zero_copy_stream_impl_lite.h
@@ -156,26 +156,6 @@ class LIBPROTOBUF_EXPORT StringOutputStream : public ZeroCopyOutputStream {
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringOutputStream);
};
-// LazyStringOutputStream is a StringOutputStream with lazy acquisition of
-// the output string from a callback. The string is owned externally, and not
-// deleted in the stream destructor.
-class LIBPROTOBUF_EXPORT LazyStringOutputStream : public StringOutputStream {
- public:
- // Callback should be permanent (non-self-deleting). Ownership is transferred
- // to the LazyStringOutputStream.
- explicit LazyStringOutputStream(ResultCallback<string*>* callback);
-
- // implements ZeroCopyOutputStream, overriding StringOutputStream -----------
- bool Next(void** data, int* size);
- int64 ByteCount() const;
-
- private:
- const google::protobuf::scoped_ptr<ResultCallback<string*> > callback_;
- bool string_is_set_;
-
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(LazyStringOutputStream);
-};
-
// Note: There is no StringInputStream. Instead, just create an
// ArrayInputStream as follows:
// ArrayInputStream input(str.data(), str.size());
diff --git a/src/google/protobuf/io/zero_copy_stream_unittest.cc b/src/google/protobuf/io/zero_copy_stream_unittest.cc
index 2bca6a90..dfc383a3 100644
--- a/src/google/protobuf/io/zero_copy_stream_unittest.cc
+++ b/src/google/protobuf/io/zero_copy_stream_unittest.cc
@@ -70,11 +70,11 @@
#endif
#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/stubs/io_win32.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/testing/googletest.h>
#include <google/protobuf/testing/file.h>
#include <gtest/gtest.h>
+#include <google/protobuf/stubs/io_win32.h>
namespace google {
namespace protobuf {