aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/io
diff options
context:
space:
mode:
authorGravatar Adam Cozzette <acozzette@google.com>2018-03-13 16:37:29 -0700
committerGravatar Adam Cozzette <acozzette@google.com>2018-03-13 16:37:29 -0700
commit0400cca3236de1ca303af38bf81eab332d042b7c (patch)
treea8a9b19853f64567c96750a1c7d253926471daa5 /src/google/protobuf/io
parent96b535cc2f4f7b7e22a1b8622149f7c26a5a3f63 (diff)
Integrated internal changes from Google
Diffstat (limited to 'src/google/protobuf/io')
-rw-r--r--src/google/protobuf/io/coded_stream.cc26
-rw-r--r--src/google/protobuf/io/coded_stream.h23
-rw-r--r--src/google/protobuf/io/coded_stream_unittest.cc5
-rw-r--r--src/google/protobuf/io/zero_copy_stream_impl_lite.h7
-rw-r--r--src/google/protobuf/io/zero_copy_stream_unittest.cc5
5 files changed, 21 insertions, 45 deletions
diff --git a/src/google/protobuf/io/coded_stream.cc b/src/google/protobuf/io/coded_stream.cc
index d3bc7c6d..0851ff0c 100644
--- a/src/google/protobuf/io/coded_stream.cc
+++ b/src/google/protobuf/io/coded_stream.cc
@@ -217,8 +217,12 @@ bool CodedInputStream::SkipFallback(int count, int original_buffer_size) {
return false;
}
+ if (!input_->Skip(count)) {
+ total_bytes_read_ = input_->ByteCount();
+ return false;
+ }
total_bytes_read_ += count;
- return input_->Skip(count);
+ return true;
}
bool CodedInputStream::GetDirectBufferPointer(const void** data, int* size) {
@@ -615,23 +619,11 @@ bool CodedInputStream::Refresh() {
// CodedOutputStream =================================================
-google::protobuf::internal::AtomicWord CodedOutputStream::default_serialization_deterministic_ = 0;
+std::atomic<bool> CodedOutputStream::default_serialization_deterministic_{
+ false};
CodedOutputStream::CodedOutputStream(ZeroCopyOutputStream* output)
- : output_(output),
- buffer_(NULL),
- buffer_size_(0),
- total_bytes_(0),
- had_error_(false),
- aliasing_enabled_(false),
- serialization_deterministic_is_overridden_(false) {
- // Eagerly Refresh() so buffer space is immediately available.
- Refresh();
- // The Refresh() may have failed. If the client doesn't write any data,
- // though, don't consider this an error. If the client does write data, then
- // another Refresh() will be attempted and it will set the error once again.
- had_error_ = false;
-}
+ : CodedOutputStream(output, true) {}
CodedOutputStream::CodedOutputStream(ZeroCopyOutputStream* output,
bool do_eager_refresh)
@@ -641,7 +633,7 @@ CodedOutputStream::CodedOutputStream(ZeroCopyOutputStream* output,
total_bytes_(0),
had_error_(false),
aliasing_enabled_(false),
- serialization_deterministic_is_overridden_(false) {
+ is_serialization_deterministic_(IsDefaultSerializationDeterministic()) {
if (do_eager_refresh) {
// Eagerly Refresh() so buffer space is immediately available.
Refresh();
diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h
index ec85147b..9dad1c61 100644
--- a/src/google/protobuf/io/coded_stream.h
+++ b/src/google/protobuf/io/coded_stream.h
@@ -110,6 +110,7 @@
#define GOOGLE_PROTOBUF_IO_CODED_STREAM_H__
#include <assert.h>
+#include <atomic>
#include <climits>
#include <string>
#include <utility>
@@ -131,7 +132,6 @@
#define PROTOBUF_LITTLE_ENDIAN 1
#endif
#endif
-#include <google/protobuf/stubs/atomicops.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/port.h>
#include <google/protobuf/stubs/port.h>
@@ -829,7 +829,7 @@ class LIBPROTOBUF_EXPORT CodedOutputStream {
// canonicalization specification and implement the serializer using
// reflection APIs rather than relying on this API.
//
- // If determinisitc serialization is requested, the serializer will
+ // If deterministic serialization is requested, the serializer will
// sort map entries by keys in lexicographical order or numerical order.
// (This is an implementation detail and may subject to change.)
//
@@ -840,21 +840,18 @@ class LIBPROTOBUF_EXPORT CodedOutputStream {
// Otherwise, SetSerializationDeterministic has been called, and the last
// value passed to it is all that matters.
void SetSerializationDeterministic(bool value) {
- serialization_deterministic_is_overridden_ = true;
- serialization_deterministic_override_ = value;
+ is_serialization_deterministic_ = value;
}
// See above. Also, note that users of this CodedOutputStream may need to
// call IsSerializationDeterministic() to serialize in the intended way. This
// CodedOutputStream cannot enforce a desire for deterministic serialization
// by itself.
bool IsSerializationDeterministic() const {
- return serialization_deterministic_is_overridden_ ?
- serialization_deterministic_override_ :
- IsDefaultSerializationDeterministic();
+ return is_serialization_deterministic_;
}
static bool IsDefaultSerializationDeterministic() {
- return google::protobuf::internal::NoBarrier_Load(&default_serialization_deterministic_);
+ return default_serialization_deterministic_.load(std::memory_order_relaxed);
}
private:
@@ -866,12 +863,8 @@ class LIBPROTOBUF_EXPORT CodedOutputStream {
int total_bytes_; // Sum of sizes of all buffers seen so far.
bool had_error_; // Whether an error occurred during output.
bool aliasing_enabled_; // See EnableAliasing().
- // See SetSerializationDeterministic() regarding these three fields.
- bool serialization_deterministic_is_overridden_;
- bool serialization_deterministic_override_;
- // 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_;
+ bool is_serialization_deterministic_;
+ static std::atomic<bool> default_serialization_deterministic_;
// Advance the buffer by a given number of bytes.
void Advance(int amount);
@@ -898,7 +891,7 @@ class LIBPROTOBUF_EXPORT CodedOutputStream {
// thread has done so.
friend void ::google::protobuf::internal::MapTestForceDeterministic();
static void SetDefaultSerializationDeterministic() {
- google::protobuf::internal::NoBarrier_Store(&default_serialization_deterministic_, 1);
+ default_serialization_deterministic_.store(true, std::memory_order_relaxed);
}
};
diff --git a/src/google/protobuf/io/coded_stream_unittest.cc b/src/google/protobuf/io/coded_stream_unittest.cc
index 96f91ae9..1c8d3272 100644
--- a/src/google/protobuf/io/coded_stream_unittest.cc
+++ b/src/google/protobuf/io/coded_stream_unittest.cc
@@ -35,9 +35,6 @@
// This file contains tests and benchmarks.
#include <memory>
-#ifndef _SHARED_PTR_H
-#include <google/protobuf/stubs/shared_ptr.h>
-#endif
#include <vector>
#include <google/protobuf/io/coded_stream.h>
@@ -737,7 +734,7 @@ TEST_F(CodedStreamTest, ReadStringImpossiblyLargeFromStringOnStack) {
}
TEST_F(CodedStreamTest, ReadStringImpossiblyLargeFromStringOnHeap) {
- google::protobuf::scoped_array<uint8> buffer(new uint8[8]);
+ std::unique_ptr<uint8[]> buffer(new uint8[8]);
CodedInputStream coded_input(buffer.get(), 8);
string str;
EXPECT_FALSE(coded_input.ReadString(&str, 1 << 30));
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 ab0fd5ac..29f63bf0 100644
--- a/src/google/protobuf/io/zero_copy_stream_impl_lite.h
+++ b/src/google/protobuf/io/zero_copy_stream_impl_lite.h
@@ -45,9 +45,6 @@
#define GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_LITE_H__
#include <memory>
-#ifndef _SHARED_PTR_H
-#include <google/protobuf/stubs/shared_ptr.h>
-#endif
#include <string>
#include <iosfwd>
#include <google/protobuf/io/zero_copy_stream.h>
@@ -239,7 +236,7 @@ class LIBPROTOBUF_EXPORT CopyingInputStreamAdaptor : public ZeroCopyInputStream
// Data is read into this buffer. It may be NULL if no buffer is currently
// in use. Otherwise, it points to an array of size buffer_size_.
- google::protobuf::scoped_array<uint8> buffer_;
+ std::unique_ptr<uint8[]> buffer_;
const int buffer_size_;
// Number of valid bytes currently in the buffer (i.e. the size last
@@ -328,7 +325,7 @@ class LIBPROTOBUF_EXPORT CopyingOutputStreamAdaptor : public ZeroCopyOutputStrea
// Data is written from this buffer. It may be NULL if no buffer is
// currently in use. Otherwise, it points to an array of size buffer_size_.
- google::protobuf::scoped_array<uint8> buffer_;
+ std::unique_ptr<uint8[]> buffer_;
const int buffer_size_;
// Number of valid bytes currently in the buffer (i.e. the size last
diff --git a/src/google/protobuf/io/zero_copy_stream_unittest.cc b/src/google/protobuf/io/zero_copy_stream_unittest.cc
index 91792f18..08de8cb1 100644
--- a/src/google/protobuf/io/zero_copy_stream_unittest.cc
+++ b/src/google/protobuf/io/zero_copy_stream_unittest.cc
@@ -56,9 +56,6 @@
#include <fcntl.h>
#include <errno.h>
#include <memory>
-#ifndef _SHARED_PTR_H
-#include <google/protobuf/stubs/shared_ptr.h>
-#endif
#include <sstream>
#include <google/protobuf/testing/file.h>
@@ -206,7 +203,7 @@ void IoTest::WriteString(ZeroCopyOutputStream* output, const string& str) {
}
void IoTest::ReadString(ZeroCopyInputStream* input, const string& str) {
- google::protobuf::scoped_array<char> buffer(new char[str.size() + 1]);
+ std::unique_ptr<char[]> buffer(new char[str.size() + 1]);
buffer[str.size()] = '\0';
EXPECT_EQ(ReadFromInput(input, buffer.get(), str.size()), str.size());
EXPECT_STREQ(str.c_str(), buffer.get());