Internal changes

PiperOrigin-RevId: 493996493
pull/11214/head
Mike Kruskal 2 years ago committed by Copybara-Service
parent 9e0e7d5f59
commit d64a5c44e4
  1. 52
      src/google/protobuf/io/coded_stream.cc
  2. 8
      src/google/protobuf/io/coded_stream.h
  3. 13
      src/google/protobuf/io/coded_stream_unittest.cc
  4. 13
      src/google/protobuf/io/gzip_stream.cc
  5. 21
      src/google/protobuf/io/printer.cc
  6. 9
      src/google/protobuf/io/printer.h
  7. 7
      src/google/protobuf/io/printer_death_test.cc
  8. 4
      src/google/protobuf/io/printer_unittest.cc
  9. 8
      src/google/protobuf/io/strtod.cc
  10. 14
      src/google/protobuf/io/tokenizer.cc
  11. 1
      src/google/protobuf/io/tokenizer.h
  12. 1
      src/google/protobuf/io/tokenizer_unittest.cc
  13. 4
      src/google/protobuf/io/zero_copy_sink_test.cc
  14. 6
      src/google/protobuf/io/zero_copy_stream.cc
  15. 2
      src/google/protobuf/io/zero_copy_stream.h
  16. 19
      src/google/protobuf/io/zero_copy_stream_impl.cc
  17. 44
      src/google/protobuf/io/zero_copy_stream_impl_lite.cc
  18. 5
      src/google/protobuf/io/zero_copy_stream_unittest.cc

@ -48,6 +48,7 @@
#include <cstring>
#include <utility>
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/strings/cord.h"
#include "absl/strings/internal/resize_uninitialized.h"
@ -174,7 +175,7 @@ CodedInputStream::Limit CodedInputStream::ReadLengthAndPushLimit() {
bool CodedInputStream::DecrementRecursionDepthAndPopLimit(Limit limit) {
bool result = ConsumedEntireMessage();
PopLimit(limit);
GOOGLE_DCHECK_LT(recursion_budget_, recursion_limit_);
GOOGLE_ABSL_DCHECK_LT(recursion_budget_, recursion_limit_);
++recursion_budget_;
return result;
}
@ -206,13 +207,12 @@ int CodedInputStream::BytesUntilTotalBytesLimit() const {
}
void CodedInputStream::PrintTotalBytesLimitError() {
GOOGLE_LOG(ERROR)
<< "A protocol message was rejected because it was too "
"big (more than "
<< total_bytes_limit_
<< " bytes). To increase the limit (or to disable these "
"warnings), see CodedInputStream::SetTotalBytesLimit() "
"in third_party/protobuf/io/coded_stream.h.";
GOOGLE_ABSL_LOG(ERROR) << "A protocol message was rejected because it was too "
"big (more than "
<< total_bytes_limit_
<< " bytes). To increase the limit (or to disable these "
"warnings), see CodedInputStream::SetTotalBytesLimit() "
"in third_party/protobuf/io/coded_stream.h.";
}
bool CodedInputStream::SkipFallback(int count, int original_buffer_size) {
@ -280,7 +280,7 @@ bool CodedInputStream::ReadString(std::string* buffer, int size) {
if (z.second) {
// Oddly enough, memcpy() requires its first two args to be non-NULL even
// if we copy 0 bytes. So, we have ensured that z.first is non-NULL here.
GOOGLE_DCHECK(z.first != NULL);
GOOGLE_ABSL_DCHECK(z.first != NULL);
memcpy(z.first, buffer_, size);
Advance(size);
}
@ -405,7 +405,7 @@ namespace {
// subtracting 0x80 at each iteration, it subtracts properly shifted mask once.
template <size_t N>
const uint8_t* DecodeVarint64KnownSize(const uint8_t* buffer, uint64_t* value) {
GOOGLE_DCHECK_GT(N, 0);
GOOGLE_ABSL_DCHECK_GT(N, 0);
uint64_t result = static_cast<uint64_t>(buffer[N - 1]) << (7 * (N - 1));
for (size_t i = 0, offset = 0; i < N - 1; i++, offset += 7) {
result += static_cast<uint64_t>(buffer[i] - 0x80) << offset;
@ -426,8 +426,8 @@ inline ::std::pair<bool, const uint8_t*> ReadVarint32FromArray(
uint32_t first_byte, const uint8_t* buffer, uint32_t* value) {
// Fast path: We have enough bytes left in the buffer to guarantee that
// this read won't cross the end, so we can skip the checks.
GOOGLE_DCHECK_EQ(*buffer, first_byte);
GOOGLE_DCHECK_EQ(first_byte & 0x80, 0x80) << first_byte;
GOOGLE_ABSL_DCHECK_EQ(*buffer, first_byte);
GOOGLE_ABSL_DCHECK_EQ(first_byte & 0x80, 0x80) << first_byte;
const uint8_t* ptr = buffer;
uint32_t b;
uint32_t result = first_byte - 0x80;
@ -470,7 +470,7 @@ PROTOBUF_ALWAYS_INLINE::std::pair<bool, const uint8_t*> ReadVarint64FromArray(
inline ::std::pair<bool, const uint8_t*> ReadVarint64FromArray(
const uint8_t* buffer, uint64_t* value) {
// Assumes varint64 is at least 2 bytes.
GOOGLE_DCHECK_GE(buffer[0], 128);
GOOGLE_ABSL_DCHECK_GE(buffer[0], 128);
const uint8_t* next;
if (buffer[1] < 128) {
@ -515,7 +515,7 @@ int64_t CodedInputStream::ReadVarint32Fallback(uint32_t first_byte_or_zero) {
// Optimization: We're also safe if the buffer is non-empty and it ends
// with a byte that would terminate a varint.
(buffer_end_ > buffer_ && !(buffer_end_[-1] & 0x80))) {
GOOGLE_DCHECK_NE(first_byte_or_zero, 0)
GOOGLE_ABSL_DCHECK_NE(first_byte_or_zero, 0)
<< "Caller should provide us with *buffer_ when buffer is non-empty";
uint32_t temp;
::std::pair<bool, const uint8_t*> p =
@ -590,7 +590,7 @@ uint32_t CodedInputStream::ReadTagFallback(uint32_t first_byte_or_zero) {
// Optimization: We're also safe if the buffer is non-empty and it ends
// with a byte that would terminate a varint.
(buf_size > 0 && !(buffer_end_[-1] & 0x80))) {
GOOGLE_DCHECK_EQ(first_byte_or_zero, buffer_[0]);
GOOGLE_ABSL_DCHECK_EQ(first_byte_or_zero, buffer_[0]);
if (first_byte_or_zero == 0) {
++buffer_;
return 0;
@ -670,7 +670,7 @@ std::pair<uint64_t, bool> CodedInputStream::ReadVarint64Fallback() {
}
bool CodedInputStream::Refresh() {
GOOGLE_DCHECK_EQ(0, BufferSize());
GOOGLE_ABSL_DCHECK_EQ(0, BufferSize());
if (buffer_size_after_limit_ > 0 || overflow_bytes_ > 0 ||
total_bytes_read_ == current_limit_) {
@ -691,7 +691,7 @@ bool CodedInputStream::Refresh() {
if (NextNonEmpty(input_, &void_buffer, &buffer_size)) {
buffer_ = reinterpret_cast<const uint8_t*>(void_buffer);
buffer_end_ = buffer_ + buffer_size;
GOOGLE_CHECK_GE(buffer_size, 0);
GOOGLE_ABSL_CHECK_GE(buffer_size, 0);
if (total_bytes_read_ <= INT_MAX - buffer_size) {
total_bytes_read_ += buffer_size;
@ -738,8 +738,8 @@ int64_t EpsCopyOutputStream::ByteCount(uint8_t* ptr) const {
int EpsCopyOutputStream::Flush(uint8_t* ptr) {
while (buffer_end_ && ptr > end_) {
int overrun = ptr - end_;
GOOGLE_DCHECK(!had_error_);
GOOGLE_DCHECK(overrun <= kSlopBytes); // NOLINT
GOOGLE_ABSL_DCHECK(!had_error_);
GOOGLE_ABSL_DCHECK(overrun <= kSlopBytes); // NOLINT
ptr = Next() + overrun;
if (had_error_) return 0;
}
@ -753,7 +753,7 @@ int EpsCopyOutputStream::Flush(uint8_t* ptr) {
s = end_ + kSlopBytes - ptr;
buffer_end_ = ptr;
}
GOOGLE_DCHECK(s >= 0); // NOLINT
GOOGLE_ABSL_DCHECK(s >= 0); // NOLINT
return s;
}
@ -841,7 +841,7 @@ uint8_t* EpsCopyOutputStream::GetDirectBufferForNBytesAndAdvance(int size,
}
uint8_t* EpsCopyOutputStream::Next() {
GOOGLE_DCHECK(!had_error_); // NOLINT
GOOGLE_ABSL_DCHECK(!had_error_); // NOLINT
if (PROTOBUF_PREDICT_FALSE(stream_ == nullptr)) return Error();
if (buffer_end_) {
// We're in the patch buffer and need to fill up the previous buffer.
@ -863,7 +863,7 @@ uint8_t* EpsCopyOutputStream::Next() {
buffer_end_ = nullptr;
return ptr;
} else {
GOOGLE_DCHECK(size > 0); // NOLINT
GOOGLE_ABSL_DCHECK(size > 0); // NOLINT
// Buffer to small
std::memmove(buffer_, end_, kSlopBytes);
buffer_end_ = ptr;
@ -882,11 +882,11 @@ uint8_t* EpsCopyOutputStream::EnsureSpaceFallback(uint8_t* ptr) {
do {
if (PROTOBUF_PREDICT_FALSE(had_error_)) return buffer_;
int overrun = ptr - end_;
GOOGLE_DCHECK(overrun >= 0); // NOLINT
GOOGLE_DCHECK(overrun <= kSlopBytes); // NOLINT
GOOGLE_ABSL_DCHECK(overrun >= 0); // NOLINT
GOOGLE_ABSL_DCHECK(overrun <= kSlopBytes); // NOLINT
ptr = Next() + overrun;
} while (ptr >= end_);
GOOGLE_DCHECK(ptr < end_); // NOLINT
GOOGLE_ABSL_DCHECK(ptr < end_); // NOLINT
return ptr;
}
@ -1029,7 +1029,7 @@ uint8_t* CodedOutputStream::WriteCordToArray(const absl::Cord& cord,
uint8_t* CodedOutputStream::WriteStringWithSizeToArray(const std::string& str,
uint8_t* target) {
GOOGLE_DCHECK_LE(str.size(), std::numeric_limits<uint32_t>::max());
GOOGLE_ABSL_DCHECK_LE(str.size(), std::numeric_limits<uint32_t>::max());
target = WriteVarint32ToArray(str.size(), target);
return WriteStringToArray(str, target);
}

@ -128,8 +128,8 @@
#include "google/protobuf/stubs/common.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/base/attributes.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/numeric/bits.h"
#include "absl/strings/cord.h"
#include "absl/strings/string_view.h"
@ -844,7 +844,7 @@ class PROTOBUF_EXPORT EpsCopyOutputStream {
inline uint8_t* Next();
int Flush(uint8_t* ptr);
std::ptrdiff_t GetSize(uint8_t* ptr) const {
GOOGLE_DCHECK(ptr <= end_ + kSlopBytes); // NOLINT
GOOGLE_ABSL_DCHECK(ptr <= end_ + kSlopBytes); // NOLINT
return end_ + kSlopBytes - ptr;
}
@ -865,7 +865,7 @@ class PROTOBUF_EXPORT EpsCopyOutputStream {
PROTOBUF_ALWAYS_INLINE uint8_t* WriteTag(uint32_t num, uint32_t wt,
uint8_t* ptr) {
GOOGLE_DCHECK(ptr < end_); // NOLINT
GOOGLE_ABSL_DCHECK(ptr < end_); // NOLINT
return UnsafeVarint((num << 3) | wt, ptr);
}
@ -1074,7 +1074,7 @@ class PROTOBUF_EXPORT CodedOutputStream {
// errors.
bool HadError() {
cur_ = impl_.FlushAndResetBuffer(cur_);
GOOGLE_DCHECK(cur_);
GOOGLE_ABSL_DCHECK(cur_);
return impl_.HadError();
}

@ -44,9 +44,10 @@
#include <vector>
#include "google/protobuf/stubs/common.h"
#include "google/protobuf/stubs/logging.h"
#include <gtest/gtest.h>
#include "absl/base/casts.h"
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/strings/cord.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/io/zero_copy_stream_impl.h"
@ -237,9 +238,11 @@ TEST_F(CodedStreamTest, EmptyInputBeforeEos) {
*size = 0;
return count_++ < 2;
}
void BackUp(int count) override { GOOGLE_LOG(FATAL) << "Tests never call this."; }
void BackUp(int count) override {
GOOGLE_ABSL_LOG(FATAL) << "Tests never call this.";
}
bool Skip(int count) override {
GOOGLE_LOG(FATAL) << "Tests never call this.";
GOOGLE_ABSL_LOG(FATAL) << "Tests never call this.";
return false;
}
int64_t ByteCount() const override { return 0; }
@ -1490,11 +1493,11 @@ class ReallyBigInputStream : public ZeroCopyInputStream {
void BackUp(int count) override { backup_amount_ = count; }
bool Skip(int count) override {
GOOGLE_LOG(FATAL) << "Not implemented.";
GOOGLE_ABSL_LOG(FATAL) << "Not implemented.";
return false;
}
int64_t ByteCount() const override {
GOOGLE_LOG(FATAL) << "Not implemented.";
GOOGLE_ABSL_LOG(FATAL) << "Not implemented.";
return 0;
}

@ -36,10 +36,11 @@
#if HAVE_ZLIB
#include "google/protobuf/io/gzip_stream.h"
#include "google/protobuf/port.h"
#include "google/protobuf/stubs/common.h"
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/port.h"
namespace google {
namespace protobuf {
@ -65,7 +66,7 @@ GzipInputStream::GzipInputStream(ZeroCopyInputStream* sub_stream, Format format,
output_buffer_length_ = buffer_size;
}
output_buffer_ = operator new(output_buffer_length_);
GOOGLE_CHECK(output_buffer_ != NULL);
GOOGLE_ABSL_CHECK(output_buffer_ != NULL);
zcontext_.next_out = static_cast<Bytef*>(output_buffer_);
zcontext_.avail_out = output_buffer_length_;
output_position_ = output_buffer_;
@ -220,7 +221,7 @@ void GzipOutputStream::Init(ZeroCopyOutputStream* sub_stream,
input_buffer_length_ = options.buffer_size;
input_buffer_ = operator new(input_buffer_length_);
GOOGLE_CHECK(input_buffer_ != NULL);
GOOGLE_ABSL_CHECK(input_buffer_ != NULL);
zcontext_.zalloc = Z_NULL;
zcontext_.zfree = Z_NULL;
@ -259,7 +260,7 @@ int GzipOutputStream::Deflate(int flush) {
sub_data_size_ = 0;
return Z_BUF_ERROR;
}
GOOGLE_CHECK_GT(sub_data_size_, 0);
GOOGLE_ABSL_CHECK_GT(sub_data_size_, 0);
zcontext_.next_out = static_cast<Bytef*>(sub_data_);
zcontext_.avail_out = sub_data_size_;
}
@ -294,12 +295,12 @@ bool GzipOutputStream::Next(void** data, int* size) {
*size = input_buffer_length_;
} else {
// The loop in Deflate should consume all avail_in
GOOGLE_LOG(DFATAL) << "Deflate left bytes unconsumed";
GOOGLE_ABSL_LOG(DFATAL) << "Deflate left bytes unconsumed";
}
return true;
}
void GzipOutputStream::BackUp(int count) {
GOOGLE_CHECK_GE(zcontext_.avail_in, static_cast<uInt>(count));
GOOGLE_ABSL_CHECK_GE(zcontext_.avail_in, static_cast<uInt>(count));
zcontext_.avail_in -= count;
}
int64_t GzipOutputStream::ByteCount() const {

@ -44,8 +44,9 @@
#include <utility>
#include <vector>
#include "google/protobuf/stubs/logging.h"
#include "absl/container/flat_hash_map.h"
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/match.h"
@ -139,10 +140,10 @@ Printer::Printer(ZeroCopyOutputStream* output, Options options)
absl::string_view Printer::LookupVar(absl::string_view var) {
LookupResult result = LookupInFrameStack(var, absl::MakeSpan(var_lookups_));
GOOGLE_CHECK(result.has_value()) << "could not find " << var;
GOOGLE_ABSL_CHECK(result.has_value()) << "could not find " << var;
auto* view = absl::get_if<absl::string_view>(&*result);
GOOGLE_CHECK(view != nullptr) << "could not find " << var
<< "; found callback instead";
GOOGLE_ABSL_CHECK(view != nullptr)
<< "could not find " << var << "; found callback instead";
return *view;
}
@ -151,9 +152,9 @@ bool Printer::Validate(bool cond, Printer::PrintOptions opts,
absl::FunctionRef<std::string()> message) {
if (!cond) {
if (opts.checks_are_debug_only) {
GOOGLE_LOG(DFATAL) << message();
GOOGLE_ABSL_LOG(DFATAL) << message();
} else {
GOOGLE_LOG(FATAL) << message();
GOOGLE_ABSL_LOG(FATAL) << message();
}
}
return cond;
@ -165,7 +166,7 @@ bool Printer::Validate(bool cond, Printer::PrintOptions opts,
}
// This function is outlined to isolate the use of
// GOOGLE_CHECK into the .cc file.
// GOOGLE_ABSL_CHECK into the .cc file.
void Printer::Outdent() {
PrintOptions opts;
opts.checks_are_debug_only = true;
@ -226,8 +227,8 @@ void Printer::Annotate(absl::string_view begin_varname,
return;
}
if (begin->first > end->second) {
GOOGLE_LOG(DFATAL) << "annotation has negative length from " << begin_varname
<< " to " << end_varname;
GOOGLE_ABSL_LOG(DFATAL) << "annotation has negative length from " << begin_varname
<< " to " << end_varname;
return;
}
options_.annotation_collector->AddAnnotation(begin->first, end->second,
@ -588,7 +589,7 @@ void Printer::PrintImpl(absl::string_view format,
}
} else {
auto* fnc = absl::get_if<std::function<void()>>(&*sub);
GOOGLE_CHECK(fnc != nullptr);
GOOGLE_ABSL_CHECK(fnc != nullptr);
Validate(
prefix.empty() && suffix.empty(), opts,

@ -46,10 +46,10 @@
#include <utility>
#include <vector>
#include "google/protobuf/stubs/logging.h"
#include "absl/cleanup/cleanup.h"
#include "absl/container/flat_hash_map.h"
#include "absl/functional/function_ref.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
@ -885,8 +885,9 @@ auto Printer::WithDefs(
for (auto& var : vars) {
auto result = var_map.insert({var.key, var.value});
GOOGLE_CHECK(result.second) << "repeated variable in Emit() or WithVars() call: \""
<< var.key << "\"";
GOOGLE_ABSL_CHECK(result.second)
<< "repeated variable in Emit() or WithVars() call: \"" << var.key
<< "\"";
if (var.annotation.has_value()) {
annotation_map.insert({var.key, *var.annotation});
}
@ -903,7 +904,7 @@ auto Printer::WithDefs(
}
auto* f = absl::get_if<std::function<void()>>(&it->second);
GOOGLE_CHECK(f != nullptr);
GOOGLE_ABSL_CHECK(f != nullptr);
return *f;
});

@ -32,21 +32,20 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
#include "google/protobuf/io/printer.h"
#include <ostream>
#include <string>
#include <tuple>
#include <vector>
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/descriptor.pb.h"
#include <gmock/gmock.h>
#include "google/protobuf/testing/googletest.h"
#include <gtest/gtest.h>
#include "absl/container/flat_hash_map.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/strings/str_join.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/io/printer.h"
#include "google/protobuf/io/zero_copy_stream.h"
#include "google/protobuf/io/zero_copy_stream_impl.h"
#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
@ -57,7 +56,7 @@ namespace io {
class PrinterTest : public testing::Test {
protected:
ZeroCopyOutputStream* output() {
GOOGLE_CHECK(stream_.has_value());
GOOGLE_ABSL_CHECK(stream_.has_value());
return &*stream_;
}
absl::string_view written() {

@ -39,12 +39,12 @@
#include <tuple>
#include <vector>
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/descriptor.pb.h"
#include <gmock/gmock.h>
#include "google/protobuf/testing/googletest.h"
#include <gtest/gtest.h>
#include "absl/container/flat_hash_map.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/strings/str_join.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/io/zero_copy_stream.h"
@ -64,7 +64,7 @@ using ::testing::MatchesRegex;
class PrinterTest : public testing::Test {
protected:
ZeroCopyOutputStream* output() {
GOOGLE_CHECK(stream_.has_value());
GOOGLE_ABSL_CHECK(stream_.has_value());
return &*stream_;
}
absl::string_view written() {

@ -208,7 +208,7 @@ char *FloatToBuffer(float value, char *buffer) {
// The snprintf should never overflow because the buffer is significantly
// larger than the precision we asked for.
GOOGLE_DCHECK(snprintf_result > 0 && snprintf_result < kFloatToBufferSize);
GOOGLE_ABSL_DCHECK(snprintf_result > 0 && snprintf_result < kFloatToBufferSize);
float parsed_value;
if (!safe_strtof(buffer, &parsed_value) || parsed_value != value) {
@ -216,7 +216,7 @@ char *FloatToBuffer(float value, char *buffer) {
absl::SNPrintF(buffer, kFloatToBufferSize, "%.*g", FLT_DIG + 3, value);
// Should never overflow; see above.
GOOGLE_DCHECK(snprintf_result > 0 && snprintf_result < kFloatToBufferSize);
GOOGLE_ABSL_DCHECK(snprintf_result > 0 && snprintf_result < kFloatToBufferSize);
}
DelocalizeRadix(buffer);
@ -246,7 +246,7 @@ char *DoubleToBuffer(double value, char *buffer) {
// The snprintf should never overflow because the buffer is significantly
// larger than the precision we asked for.
GOOGLE_DCHECK(snprintf_result > 0 && snprintf_result < kDoubleToBufferSize);
GOOGLE_ABSL_DCHECK(snprintf_result > 0 && snprintf_result < kDoubleToBufferSize);
// We need to make parsed_value volatile in order to force the compiler to
// write it out to the stack. Otherwise, it may keep the value in a
@ -260,7 +260,7 @@ char *DoubleToBuffer(double value, char *buffer) {
absl::SNPrintF(buffer, kDoubleToBufferSize, "%.*g", DBL_DIG + 2, value);
// Should never overflow; see above.
GOOGLE_DCHECK(snprintf_result > 0 && snprintf_result < kDoubleToBufferSize);
GOOGLE_ABSL_DCHECK(snprintf_result > 0 && snprintf_result < kDoubleToBufferSize);
}
DelocalizeRadix(buffer);

@ -92,6 +92,7 @@
#include "google/protobuf/stubs/common.h"
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_format.h"
#include "google/protobuf/io/strtod.h"
@ -1034,7 +1035,7 @@ bool Tokenizer::ParseInteger(const std::string& text, uint64_t max_value,
double Tokenizer::ParseFloat(const std::string& text) {
double result = 0;
if (!TryParseFloat(text, &result)) {
GOOGLE_LOG(DFATAL)
GOOGLE_ABSL_LOG(DFATAL)
<< " Tokenizer::ParseFloat() passed text that could not have been"
" tokenized as a float: "
<< absl::CEscape(text);
@ -1129,8 +1130,8 @@ static inline bool IsTrailSurrogate(uint32_t code_point) {
// Combine a head and trail surrogate into a single Unicode code point.
static uint32_t AssembleUTF16(uint32_t head_surrogate,
uint32_t trail_surrogate) {
GOOGLE_DCHECK(IsHeadSurrogate(head_surrogate));
GOOGLE_DCHECK(IsTrailSurrogate(trail_surrogate));
GOOGLE_ABSL_DCHECK(IsHeadSurrogate(head_surrogate));
GOOGLE_ABSL_DCHECK(IsTrailSurrogate(trail_surrogate));
return 0x10000 + (((head_surrogate - kMinHeadSurrogate) << 10) |
(trail_surrogate - kMinTrailSurrogate));
}
@ -1179,9 +1180,10 @@ void Tokenizer::ParseStringAppend(const std::string& text,
// empty, it's invalid, so we'll just return).
const size_t text_size = text.size();
if (text_size == 0) {
GOOGLE_LOG(DFATAL) << " Tokenizer::ParseStringAppend() passed text that could not"
" have been tokenized as a string: "
<< absl::CEscape(text);
GOOGLE_ABSL_LOG(DFATAL)
<< " Tokenizer::ParseStringAppend() passed text that could not"
" have been tokenized as a string: "
<< absl::CEscape(text);
return;
}

@ -41,7 +41,6 @@
#include <vector>
#include "google/protobuf/stubs/common.h"
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/port.h"
// Must be included last.

@ -40,7 +40,6 @@
#include <vector>
#include "google/protobuf/stubs/common.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/strings/escaping.h"
#include "absl/strings/substitute.h"
#include "google/protobuf/io/zero_copy_stream_impl.h"

@ -36,8 +36,8 @@
#include <string>
#include <vector>
#include "google/protobuf/stubs/logging.h"
#include <gtest/gtest.h>
#include "google/protobuf/stubs/logging.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
@ -133,7 +133,7 @@ class PatternedOutputStream : public io::ZeroCopyOutputStream {
}
void BackUp(int length) override {
GOOGLE_CHECK(length <= static_cast<int>(segment_.size()));
GOOGLE_ABSL_CHECK(length <= static_cast<int>(segment_.size()));
size_t backup = segment_.size() - static_cast<size_t>(length);
back_up_.push_back(segment_.substr(backup));

@ -133,9 +133,9 @@ bool ZeroCopyOutputStream::WriteCord(const absl::Cord& cord) {
bool ZeroCopyOutputStream::WriteAliasedRaw(const void* /* data */,
int /* size */) {
GOOGLE_LOG(FATAL) << "This ZeroCopyOutputStream doesn't support aliasing. "
"Reaching here usually means a ZeroCopyOutputStream "
"implementation bug.";
GOOGLE_ABSL_LOG(FATAL) << "This ZeroCopyOutputStream doesn't support aliasing. "
"Reaching here usually means a ZeroCopyOutputStream "
"implementation bug.";
return false;
}

@ -252,7 +252,7 @@ class PROTOBUF_EXPORT ZeroCopyOutputStream {
// Write a given chunk of data to the output. Some output streams may
// implement this in a way that avoids copying. Check AllowsAliasing() before
// calling WriteAliasedRaw(). It will GOOGLE_CHECK fail if WriteAliasedRaw() is
// calling WriteAliasedRaw(). It will GOOGLE_ABSL_CHECK fail if WriteAliasedRaw() is
// called on a stream that does not allow aliasing.
//
// NOTE: It is caller's responsibility to ensure that the chunk of memory

@ -45,6 +45,7 @@
#include "google/protobuf/stubs/common.h"
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/io/io_win32.h"
#include "google/protobuf/io/zero_copy_stream_impl.h"
@ -113,13 +114,13 @@ FileInputStream::CopyingFileInputStream::CopyingFileInputStream(
FileInputStream::CopyingFileInputStream::~CopyingFileInputStream() {
if (close_on_delete_) {
if (!Close()) {
GOOGLE_LOG(ERROR) << "close() failed: " << strerror(errno_);
GOOGLE_ABSL_LOG(ERROR) << "close() failed: " << strerror(errno_);
}
}
}
bool FileInputStream::CopyingFileInputStream::Close() {
GOOGLE_CHECK(!is_closed_);
GOOGLE_ABSL_CHECK(!is_closed_);
is_closed_ = true;
if (close_no_eintr(file_) != 0) {
@ -134,7 +135,7 @@ bool FileInputStream::CopyingFileInputStream::Close() {
}
int FileInputStream::CopyingFileInputStream::Read(void* buffer, int size) {
GOOGLE_CHECK(!is_closed_);
GOOGLE_ABSL_CHECK(!is_closed_);
int result;
do {
@ -150,7 +151,7 @@ int FileInputStream::CopyingFileInputStream::Read(void* buffer, int size) {
}
int FileInputStream::CopyingFileInputStream::Skip(int count) {
GOOGLE_CHECK(!is_closed_);
GOOGLE_ABSL_CHECK(!is_closed_);
if (!previous_seek_failed_ && lseek(file_, count, SEEK_CUR) != (off_t)-1) {
// Seek succeeded.
@ -190,13 +191,13 @@ FileOutputStream::~FileOutputStream() { Flush(); }
FileOutputStream::CopyingFileOutputStream::~CopyingFileOutputStream() {
if (close_on_delete_) {
if (!Close()) {
GOOGLE_LOG(ERROR) << "close() failed: " << strerror(errno_);
GOOGLE_ABSL_LOG(ERROR) << "close() failed: " << strerror(errno_);
}
}
}
bool FileOutputStream::CopyingFileOutputStream::Close() {
GOOGLE_CHECK(!is_closed_);
GOOGLE_ABSL_CHECK(!is_closed_);
is_closed_ = true;
if (close_no_eintr(file_) != 0) {
@ -212,7 +213,7 @@ bool FileOutputStream::CopyingFileOutputStream::Close() {
bool FileOutputStream::CopyingFileOutputStream::Write(const void* buffer,
int size) {
GOOGLE_CHECK(!is_closed_);
GOOGLE_ABSL_CHECK(!is_closed_);
int total_written = 0;
const uint8_t* buffer_base = reinterpret_cast<const uint8_t*>(buffer);
@ -329,7 +330,7 @@ void ConcatenatingInputStream::BackUp(int count) {
if (stream_count_ > 0) {
streams_[0]->BackUp(count);
} else {
GOOGLE_LOG(DFATAL) << "Can't BackUp() after failed Next().";
GOOGLE_ABSL_LOG(DFATAL) << "Can't BackUp() after failed Next().";
}
}
@ -343,7 +344,7 @@ bool ConcatenatingInputStream::Skip(int count) {
// Hit the end of the stream. Figure out how many more bytes we still have
// to skip.
int64_t final_byte_count = streams_[0]->ByteCount();
GOOGLE_DCHECK_LT(final_byte_count, target_byte_count);
GOOGLE_ABSL_DCHECK_LT(final_byte_count, target_byte_count);
count = target_byte_count - final_byte_count;
// That stream is done. Advance to the next one.

@ -39,8 +39,8 @@
#include <utility>
#include "google/protobuf/stubs/common.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/base/casts.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/strings/cord.h"
#include "absl/strings/internal/resize_uninitialized.h"
@ -82,16 +82,16 @@ bool ArrayInputStream::Next(const void** data, int* size) {
}
void ArrayInputStream::BackUp(int count) {
GOOGLE_CHECK_GT(last_returned_size_, 0)
GOOGLE_ABSL_CHECK_GT(last_returned_size_, 0)
<< "BackUp() can only be called after a successful Next().";
GOOGLE_CHECK_LE(count, last_returned_size_);
GOOGLE_CHECK_GE(count, 0);
GOOGLE_ABSL_CHECK_LE(count, last_returned_size_);
GOOGLE_ABSL_CHECK_GE(count, 0);
position_ -= count;
last_returned_size_ = 0; // Don't let caller back up further.
}
bool ArrayInputStream::Skip(int count) {
GOOGLE_CHECK_GE(count, 0);
GOOGLE_ABSL_CHECK_GE(count, 0);
last_returned_size_ = 0; // Don't let caller back up.
if (count > size_ - position_) {
position_ = size_;
@ -129,9 +129,9 @@ bool ArrayOutputStream::Next(void** data, int* size) {
}
void ArrayOutputStream::BackUp(int count) {
GOOGLE_CHECK_LE(count, last_returned_size_)
GOOGLE_ABSL_CHECK_LE(count, last_returned_size_)
<< "BackUp() can not exceed the size of the last Next() call.";
GOOGLE_CHECK_GE(count, 0);
GOOGLE_ABSL_CHECK_GE(count, 0);
position_ -= count;
last_returned_size_ -= count;
}
@ -143,7 +143,7 @@ int64_t ArrayOutputStream::ByteCount() const { return position_; }
StringOutputStream::StringOutputStream(std::string* target) : target_(target) {}
bool StringOutputStream::Next(void** data, int* size) {
GOOGLE_CHECK(target_ != NULL);
GOOGLE_ABSL_CHECK(target_ != NULL);
size_t old_size = target_->size();
// Grow the string.
@ -170,14 +170,14 @@ bool StringOutputStream::Next(void** data, int* size) {
}
void StringOutputStream::BackUp(int count) {
GOOGLE_CHECK_GE(count, 0);
GOOGLE_CHECK(target_ != NULL);
GOOGLE_CHECK_LE(static_cast<size_t>(count), target_->size());
GOOGLE_ABSL_CHECK_GE(count, 0);
GOOGLE_ABSL_CHECK(target_ != NULL);
GOOGLE_ABSL_CHECK_LE(static_cast<size_t>(count), target_->size());
target_->resize(target_->size() - count);
}
int64_t StringOutputStream::ByteCount() const {
GOOGLE_CHECK(target_ != NULL);
GOOGLE_ABSL_CHECK(target_ != NULL);
return target_->size();
}
@ -249,18 +249,18 @@ bool CopyingInputStreamAdaptor::Next(const void** data, int* size) {
}
void CopyingInputStreamAdaptor::BackUp(int count) {
GOOGLE_CHECK(backup_bytes_ == 0 && buffer_.get() != NULL)
GOOGLE_ABSL_CHECK(backup_bytes_ == 0 && buffer_.get() != NULL)
<< " BackUp() can only be called after Next().";
GOOGLE_CHECK_LE(count, buffer_used_)
GOOGLE_ABSL_CHECK_LE(count, buffer_used_)
<< " Can't back up over more bytes than were returned by the last call"
" to Next().";
GOOGLE_CHECK_GE(count, 0) << " Parameter to BackUp() can't be negative.";
GOOGLE_ABSL_CHECK_GE(count, 0) << " Parameter to BackUp() can't be negative.";
backup_bytes_ = count;
}
bool CopyingInputStreamAdaptor::Skip(int count) {
GOOGLE_CHECK_GE(count, 0);
GOOGLE_ABSL_CHECK_GE(count, 0);
if (failed_) {
// Already failed on a previous read.
@ -293,7 +293,7 @@ void CopyingInputStreamAdaptor::AllocateBufferIfNeeded() {
}
void CopyingInputStreamAdaptor::FreeBuffer() {
GOOGLE_CHECK_EQ(backup_bytes_, 0);
GOOGLE_ABSL_CHECK_EQ(backup_bytes_, 0);
buffer_used_ = 0;
buffer_.reset();
}
@ -336,10 +336,10 @@ void CopyingOutputStreamAdaptor::BackUp(int count) {
Flush();
return;
}
GOOGLE_CHECK_GE(count, 0);
GOOGLE_CHECK_EQ(buffer_used_, buffer_size_)
GOOGLE_ABSL_CHECK_GE(count, 0);
GOOGLE_ABSL_CHECK_EQ(buffer_used_, buffer_size_)
<< " BackUp() can only be called after Next().";
GOOGLE_CHECK_LE(count, buffer_used_)
GOOGLE_ABSL_CHECK_LE(count, buffer_used_)
<< " Can't back up over more bytes than were returned by the last call"
" to Next().";
@ -355,7 +355,7 @@ bool CopyingOutputStreamAdaptor::WriteAliasedRaw(const void* data, int size) {
if (!Flush() || !copying_stream_->Write(data, size)) {
return false;
}
GOOGLE_DCHECK_EQ(buffer_used_, 0);
GOOGLE_ABSL_DCHECK_EQ(buffer_used_, 0);
position_ += size;
return true;
}
@ -533,7 +533,7 @@ bool CordInputStream::Next(const void** data, int* size) {
void CordInputStream::BackUp(int count) {
// Backup is only allowed on last returned chunk from `Next()`.
GOOGLE_CHECK_LE(static_cast<size_t>(count), size_ - available_);
GOOGLE_ABSL_CHECK_LE(static_cast<size_t>(count), size_ - available_);
available_ += count;
bytes_remaining_ += count;

@ -80,10 +80,11 @@
#endif
#include "google/protobuf/stubs/common.h"
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/testing/file.h"
#include "google/protobuf/testing/googletest.h"
#include <gtest/gtest.h>
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/status/status.h"
#include "absl/strings/cord.h"
#include "absl/strings/cord_buffer.h"
@ -587,7 +588,7 @@ TEST_F(IoTest, CompressionOptions) {
std::string golden_filename =
TestUtil::GetTestDataPath("third_party/protobuf/testdata/golden_message");
std::string golden;
GOOGLE_CHECK_OK(File::GetContents(golden_filename, &golden, true));
GOOGLE_ABSL_CHECK_OK(File::GetContents(golden_filename, &golden, true));
GzipOutputStream::Options options;
std::string gzip_compressed = Compress(golden, options);

Loading…
Cancel
Save