Merge tag 'refs/tags/sync-piper' into sync-stage

pull/9859/head
Joshua Haberman 3 years ago
commit 65236e967e
  1. BIN
      csharp/src/Google.Protobuf.Test/testprotos.pb
  2. 3
      java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java
  3. 3
      java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto
  4. 38
      python/google/protobuf/internal/descriptor_pool_test.py
  5. 76
      python/google/protobuf/internal/message_test.py
  6. 2
      python/google/protobuf/internal/unknown_fields_test.py
  7. 3
      src/google/protobuf/compiler/java/helpers.cc
  8. 129
      src/google/protobuf/io/coded_stream_unittest.cc
  9. 9
      src/google/protobuf/port_def.inc
  10. 1
      src/google/protobuf/port_undef.inc
  11. 15
      src/google/protobuf/util/delimited_message_util.cc
  12. 17
      src/google/protobuf/util/time_util.cc
  13. 4
      src/google/protobuf/util/time_util.h

@ -83,8 +83,7 @@ final class DescriptorMessageInfoFactory implements MessageInfoFactory {
"AllFields", "AllFields",
"DescriptorForType", "DescriptorForType",
"InitializationErrorString", "InitializationErrorString",
// TODO(b/219045204): re-enable "UnknownFields",
// "UnknownFields",
// obsolete. kept for backwards compatibility of generated code // obsolete. kept for backwards compatibility of generated code
"CachedSize")); "CachedSize"));

@ -57,8 +57,7 @@ message ForbiddenWordsUnderscoreMessage {
optional bool all_fields = 5; optional bool all_fields = 5;
optional bool descriptor_for_type = 6; optional bool descriptor_for_type = 6;
optional bool initialization_error_string = 7; optional bool initialization_error_string = 7;
// TODO(b/219045204): re-enable optional bool unknown_fields = 8;
// optional bool unknown_fields = 8;
// obsolete. kept for backwards compatibility of generated code // obsolete. kept for backwards compatibility of generated code
optional bool cached_size = 9; optional bool cached_size = 9;
} }

@ -243,10 +243,10 @@ class DescriptorPoolTestBase(object):
self.assertRaises(KeyError, self.pool.FindMethodByName, '') self.assertRaises(KeyError, self.pool.FindMethodByName, '')
# TODO(jieluo): Fix python to raise correct errors. # TODO(jieluo): Fix python to raise correct errors.
if api_implementation.Type() == 'cpp': if api_implementation.Type() == 'python':
error_type = TypeError
else:
error_type = AttributeError error_type = AttributeError
else:
error_type = TypeError
self.assertRaises(error_type, self.pool.FindMessageTypeByName, 0) self.assertRaises(error_type, self.pool.FindMessageTypeByName, 0)
self.assertRaises(error_type, self.pool.FindFieldByName, 0) self.assertRaises(error_type, self.pool.FindFieldByName, 0)
self.assertRaises(error_type, self.pool.FindExtensionByName, 0) self.assertRaises(error_type, self.pool.FindExtensionByName, 0)
@ -395,7 +395,7 @@ class DescriptorPoolTestBase(object):
def testAddSerializedFile(self): def testAddSerializedFile(self):
if isinstance(self, SecondaryDescriptorFromDescriptorDB): if isinstance(self, SecondaryDescriptorFromDescriptorDB):
if api_implementation.Type() == 'cpp': if api_implementation.Type() != 'python':
# Cpp extension cannot call Add on a DescriptorPool # Cpp extension cannot call Add on a DescriptorPool
# that uses a DescriptorDatabase. # that uses a DescriptorDatabase.
# TODO(jieluo): Fix python and cpp extension diff. # TODO(jieluo): Fix python and cpp extension diff.
@ -434,7 +434,7 @@ class DescriptorPoolTestBase(object):
_CheckDefaultValue(file_descriptor) _CheckDefaultValue(file_descriptor)
if isinstance(self, SecondaryDescriptorFromDescriptorDB): if isinstance(self, SecondaryDescriptorFromDescriptorDB):
if api_implementation.Type() == 'cpp': if api_implementation.Type() != 'python':
# Cpp extension cannot call Add on a DescriptorPool # Cpp extension cannot call Add on a DescriptorPool
# that uses a DescriptorDatabase. # that uses a DescriptorDatabase.
# TODO(jieluo): Fix python and cpp extension diff. # TODO(jieluo): Fix python and cpp extension diff.
@ -488,7 +488,7 @@ class DescriptorPoolTestBase(object):
def testAddFileDescriptor(self): def testAddFileDescriptor(self):
if isinstance(self, SecondaryDescriptorFromDescriptorDB): if isinstance(self, SecondaryDescriptorFromDescriptorDB):
if api_implementation.Type() == 'cpp': if api_implementation.Type() != 'python':
# Cpp extension cannot call Add on a DescriptorPool # Cpp extension cannot call Add on a DescriptorPool
# that uses a DescriptorDatabase. # that uses a DescriptorDatabase.
# TODO(jieluo): Fix python and cpp extension diff. # TODO(jieluo): Fix python and cpp extension diff.
@ -499,7 +499,7 @@ class DescriptorPoolTestBase(object):
def testComplexNesting(self): def testComplexNesting(self):
if isinstance(self, SecondaryDescriptorFromDescriptorDB): if isinstance(self, SecondaryDescriptorFromDescriptorDB):
if api_implementation.Type() == 'cpp': if api_implementation.Type() != 'python':
# Cpp extension cannot call Add on a DescriptorPool # Cpp extension cannot call Add on a DescriptorPool
# that uses a DescriptorDatabase. # that uses a DescriptorDatabase.
# TODO(jieluo): Fix python and cpp extension diff. # TODO(jieluo): Fix python and cpp extension diff.
@ -518,7 +518,7 @@ class DescriptorPoolTestBase(object):
def testConflictRegister(self): def testConflictRegister(self):
if isinstance(self, SecondaryDescriptorFromDescriptorDB): if isinstance(self, SecondaryDescriptorFromDescriptorDB):
if api_implementation.Type() == 'cpp': if api_implementation.Type() != 'python':
# Cpp extension cannot call Add on a DescriptorPool # Cpp extension cannot call Add on a DescriptorPool
# that uses a DescriptorDatabase. # that uses a DescriptorDatabase.
# TODO(jieluo): Fix python and cpp extension diff. # TODO(jieluo): Fix python and cpp extension diff.
@ -527,7 +527,7 @@ class DescriptorPoolTestBase(object):
unittest_pb2.DESCRIPTOR.serialized_pb) unittest_pb2.DESCRIPTOR.serialized_pb)
conflict_fd = copy.deepcopy(unittest_fd) conflict_fd = copy.deepcopy(unittest_fd)
conflict_fd.name = 'other_file' conflict_fd.name = 'other_file'
if api_implementation.Type() == 'cpp': if api_implementation.Type() != 'python':
pass pass
else: else:
pool = copy.deepcopy(self.pool) pool = copy.deepcopy(self.pool)
@ -670,7 +670,7 @@ class SecondaryDescriptorFromDescriptorDB(DescriptorPoolTestBase,
# called the first time, a KeyError will be raised but call the find # called the first time, a KeyError will be raised but call the find
# method later will return a descriptor which is not build. # method later will return a descriptor which is not build.
# TODO(jieluo): fix pure python to revert the load if file can not be build # TODO(jieluo): fix pure python to revert the load if file can not be build
if api_implementation.Type() == 'cpp': if api_implementation.Type() != 'python':
error_msg = ('Invalid proto descriptor for file "error_file":\\n ' error_msg = ('Invalid proto descriptor for file "error_file":\\n '
'collector.ErrorMessage.nested_message_field: "SubMessage" ' 'collector.ErrorMessage.nested_message_field: "SubMessage" '
'is not defined.\\n collector.ErrorMessage.MyOneof: Oneof ' 'is not defined.\\n collector.ErrorMessage.MyOneof: Oneof '
@ -906,8 +906,8 @@ class AddDescriptorTest(unittest.TestCase):
pool.FindFileContainingSymbol( pool.FindFileContainingSymbol(
prefix + 'protobuf_unittest.TestAllTypes.NestedMessage').name) prefix + 'protobuf_unittest.TestAllTypes.NestedMessage').name)
@unittest.skipIf(api_implementation.Type() == 'cpp', @unittest.skipIf(api_implementation.Type() != 'python',
'With the cpp implementation, Add() must be called first') 'Only pure python allows _Add*()')
def testMessage(self): def testMessage(self):
self._TestMessage('') self._TestMessage('')
self._TestMessage('.') self._TestMessage('.')
@ -948,14 +948,14 @@ class AddDescriptorTest(unittest.TestCase):
pool.FindFileContainingSymbol( pool.FindFileContainingSymbol(
prefix + 'protobuf_unittest.TestAllTypes.NestedEnum').name) prefix + 'protobuf_unittest.TestAllTypes.NestedEnum').name)
@unittest.skipIf(api_implementation.Type() == 'cpp', @unittest.skipIf(api_implementation.Type() != 'python',
'With the cpp implementation, Add() must be called first') 'Only pure python allows _Add*()')
def testEnum(self): def testEnum(self):
self._TestEnum('') self._TestEnum('')
self._TestEnum('.') self._TestEnum('.')
@unittest.skipIf(api_implementation.Type() == 'cpp', @unittest.skipIf(api_implementation.Type() != 'python',
'With the cpp implementation, Add() must be called first') 'Only pure python allows _Add*()')
def testService(self): def testService(self):
pool = descriptor_pool.DescriptorPool() pool = descriptor_pool.DescriptorPool()
with self.assertRaises(KeyError): with self.assertRaises(KeyError):
@ -965,8 +965,8 @@ class AddDescriptorTest(unittest.TestCase):
'protobuf_unittest.TestService', 'protobuf_unittest.TestService',
pool.FindServiceByName('protobuf_unittest.TestService').full_name) pool.FindServiceByName('protobuf_unittest.TestService').full_name)
@unittest.skipIf(api_implementation.Type() == 'cpp', @unittest.skipIf(api_implementation.Type() != 'python',
'With the cpp implementation, Add() must be called first') 'Only pure python allows _Add*()')
def testFile(self): def testFile(self):
pool = descriptor_pool.DescriptorPool() pool = descriptor_pool.DescriptorPool()
pool._AddFileDescriptor(unittest_pb2.DESCRIPTOR) pool._AddFileDescriptor(unittest_pb2.DESCRIPTOR)
@ -1043,7 +1043,7 @@ class AddDescriptorTest(unittest.TestCase):
def testAddTypeError(self): def testAddTypeError(self):
pool = descriptor_pool.DescriptorPool() pool = descriptor_pool.DescriptorPool()
if api_implementation.Type() == 'cpp': if api_implementation.Type() != 'python':
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
pool.AddDescriptor(0) pool.AddDescriptor(0)
with self.assertRaises(TypeError): with self.assertRaises(TypeError):

@ -58,11 +58,7 @@ from google.protobuf import map_proto2_unittest_pb2
from google.protobuf import map_unittest_pb2 from google.protobuf import map_unittest_pb2
from google.protobuf import unittest_pb2 from google.protobuf import unittest_pb2
from google.protobuf import unittest_proto3_arena_pb2 from google.protobuf import unittest_proto3_arena_pb2
from google.protobuf import descriptor_pb2
from google.protobuf import descriptor from google.protobuf import descriptor
from google.protobuf import descriptor_pool
from google.protobuf import message_factory
from google.protobuf import text_format
from google.protobuf.internal import api_implementation from google.protobuf.internal import api_implementation
from google.protobuf.internal import encoder from google.protobuf.internal import encoder
from google.protobuf.internal import more_extensions_pb2 from google.protobuf.internal import more_extensions_pb2
@ -2542,66 +2538,34 @@ class PackedFieldTest(unittest.TestCase):
self.assertEqual(golden_data, message.SerializeToString()) self.assertEqual(golden_data, message.SerializeToString())
@unittest.skipIf(api_implementation.Type() != 'cpp', @unittest.skipIf(api_implementation.Type() == 'python',
'explicit tests of the C++ implementation') 'explicit tests of the C++ implementation')
@testing_refleaks.TestCase @testing_refleaks.TestCase
class OversizeProtosTest(unittest.TestCase): class OversizeProtosTest(unittest.TestCase):
@classmethod def GenerateNestedProto(self, n):
def setUpClass(cls): msg = unittest_pb2.TestRecursiveMessage()
# At the moment, reference cycles between DescriptorPool and Message classes sub = msg
# are not detected and these objects are never freed. for _ in range(n):
# To avoid errors with ReferenceLeakChecker, we create the class only once. sub = sub.a
file_desc = """ sub.i = 0
name: "f/f.msg2" return msg.SerializeToString()
package: "f"
message_type { def testSucceedOkSizedProto(self):
name: "msg1" msg = unittest_pb2.TestRecursiveMessage()
field { msg.ParseFromString(self.GenerateNestedProto(100))
name: "payload"
number: 1
label: LABEL_OPTIONAL
type: TYPE_STRING
}
}
message_type {
name: "msg2"
field {
name: "field"
number: 1
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
type_name: "msg1"
}
}
"""
pool = descriptor_pool.DescriptorPool()
desc = descriptor_pb2.FileDescriptorProto()
text_format.Parse(file_desc, desc)
pool.Add(desc)
cls.proto_cls = message_factory.MessageFactory(pool).GetPrototype(
pool.FindMessageTypeByName('f.msg2'))
def setUp(self):
self.p = self.proto_cls()
self.p.field.payload = 'c' * (1024 * 1024 * 64 + 1)
self.p_serialized = self.p.SerializeToString()
def testAssertOversizeProto(self): def testAssertOversizeProto(self):
from google.protobuf.pyext._message import SetAllowOversizeProtos api_implementation._c_module.SetAllowOversizeProtos(False)
SetAllowOversizeProtos(False) msg = unittest_pb2.TestRecursiveMessage()
q = self.proto_cls() with self.assertRaises(message.DecodeError) as context:
try: msg.ParseFromString(self.GenerateNestedProto(101))
q.ParseFromString(self.p_serialized) self.assertIn('Error parsing message', str(context.exception))
except message.DecodeError as e:
self.assertEqual(str(e), 'Error parsing message')
def testSucceedOversizeProto(self): def testSucceedOversizeProto(self):
from google.protobuf.pyext._message import SetAllowOversizeProtos api_implementation._c_module.SetAllowOversizeProtos(True)
SetAllowOversizeProtos(True) msg = unittest_pb2.TestRecursiveMessage()
q = self.proto_cls() msg.ParseFromString(self.GenerateNestedProto(101))
q.ParseFromString(self.p_serialized)
self.assertEqual(self.p.field.payload, q.field.payload)
if __name__ == '__main__': if __name__ == '__main__':

@ -184,7 +184,7 @@ class UnknownFieldsAccessorsTest(unittest.TestCase):
# serialized string is checked. # serialized string is checked.
# TODO(jieluo): Remove message._unknown_fields. # TODO(jieluo): Remove message._unknown_fields.
def InternalCheckUnknownField(self, name, expected_value): def InternalCheckUnknownField(self, name, expected_value):
if api_implementation.Type() == 'cpp': if api_implementation.Type() != 'python':
return return
field_descriptor = self.descriptor.fields_by_name[name] field_descriptor = self.descriptor.fields_by_name[name]
wire_type = type_checkers.FIELD_TYPE_TO_WIRE_TYPE[field_descriptor.type] wire_type = type_checkers.FIELD_TYPE_TO_WIRE_TYPE[field_descriptor.type]

@ -86,8 +86,7 @@ const char* kForbiddenWordList[] = {
"AllFields", "AllFields",
"DescriptorForType", "DescriptorForType",
"InitializationErrorString", "InitializationErrorString",
// TODO(b/219045204): re-enable "UnknownFields",
// "UnknownFields",
// obsolete. kept for backwards compatibility of generated code // obsolete. kept for backwards compatibility of generated code
"CachedSize", "CachedSize",
}; };

@ -38,7 +38,9 @@
#include <limits.h> #include <limits.h>
#include <algorithm>
#include <memory> #include <memory>
#include <string>
#include <vector> #include <vector>
#include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/common.h>
@ -90,7 +92,7 @@ namespace {
}; \ }; \
\ \
TEST_F(FIXTURE##_##NAME##_DD, NAME) { \ TEST_F(FIXTURE##_##NAME##_DD, NAME) { \
for (int i = 0; i < GOOGLE_ARRAYSIZE(CASES); i++) { \ for (size_t i = 0; i < GOOGLE_ARRAYSIZE(CASES); i++) { \
SCOPED_TRACE(testing::Message() \ SCOPED_TRACE(testing::Message() \
<< #CASES " case #" << i << ": " << CASES[i]); \ << #CASES " case #" << i << ": " << CASES[i]); \
DoSingleCase(CASES[i]); \ DoSingleCase(CASES[i]); \
@ -109,8 +111,8 @@ namespace {
}; \ }; \
\ \
TEST_F(FIXTURE##_##NAME##_DD, NAME) { \ TEST_F(FIXTURE##_##NAME##_DD, NAME) { \
for (int i = 0; i < GOOGLE_ARRAYSIZE(CASES1); i++) { \ for (size_t i = 0; i < GOOGLE_ARRAYSIZE(CASES1); i++) { \
for (int j = 0; j < GOOGLE_ARRAYSIZE(CASES2); j++) { \ for (size_t j = 0; j < GOOGLE_ARRAYSIZE(CASES2); j++) { \
SCOPED_TRACE(testing::Message() \ SCOPED_TRACE(testing::Message() \
<< #CASES1 " case #" << i << ": " << CASES1[i] << ", " \ << #CASES1 " case #" << i << ": " << CASES1[i] << ", " \
<< #CASES2 " case #" << j << ": " << CASES2[j]); \ << #CASES2 " case #" << j << ": " << CASES2[j]); \
@ -129,10 +131,10 @@ class CodedStreamTest : public testing::Test {
protected: protected:
// Buffer used during most of the tests. This assumes tests run sequentially. // Buffer used during most of the tests. This assumes tests run sequentially.
static constexpr int kBufferSize = 1024 * 64; static constexpr int kBufferSize = 1024 * 64;
static uint8 buffer_[kBufferSize]; static uint8_t buffer_[kBufferSize];
}; };
uint8 CodedStreamTest::buffer_[CodedStreamTest::kBufferSize]; uint8_t CodedStreamTest::buffer_[CodedStreamTest::kBufferSize];
// We test each operation over a variety of block sizes to insure that // We test each operation over a variety of block sizes to insure that
// we test cases where reads or writes cross buffer boundaries, cases // we test cases where reads or writes cross buffer boundaries, cases
@ -146,9 +148,9 @@ const int kBlockSizes[] = {1, 2, 3, 5, 7, 13, 32, 1024};
// Varint tests. // Varint tests.
struct VarintCase { struct VarintCase {
uint8 bytes[10]; // Encoded bytes. uint8_t bytes[10]; // Encoded bytes.
int size; // Encoded size, in bytes. size_t size; // Encoded size, in bytes.
uint64 value; // Parsed value. uint64_t value; // Parsed value.
}; };
inline std::ostream& operator<<(std::ostream& os, const VarintCase& c) { inline std::ostream& operator<<(std::ostream& os, const VarintCase& c) {
@ -192,9 +194,9 @@ TEST_2D(CodedStreamTest, ReadVarint32, kVarintCases, kBlockSizes) {
{ {
CodedInputStream coded_input(&input); CodedInputStream coded_input(&input);
uint32 value; uint32_t value;
EXPECT_TRUE(coded_input.ReadVarint32(&value)); EXPECT_TRUE(coded_input.ReadVarint32(&value));
EXPECT_EQ(static_cast<uint32>(kVarintCases_case.value), value); EXPECT_EQ(static_cast<uint32_t>(kVarintCases_case.value), value);
} }
EXPECT_EQ(kVarintCases_case.size, input.ByteCount()); EXPECT_EQ(kVarintCases_case.size, input.ByteCount());
@ -207,7 +209,7 @@ TEST_2D(CodedStreamTest, ReadTag, kVarintCases, kBlockSizes) {
{ {
CodedInputStream coded_input(&input); CodedInputStream coded_input(&input);
uint32 expected_value = static_cast<uint32>(kVarintCases_case.value); uint32_t expected_value = static_cast<uint32_t>(kVarintCases_case.value);
EXPECT_EQ(expected_value, coded_input.ReadTag()); EXPECT_EQ(expected_value, coded_input.ReadTag());
EXPECT_TRUE(coded_input.LastTagWas(expected_value)); EXPECT_TRUE(coded_input.LastTagWas(expected_value));
@ -226,7 +228,7 @@ TEST_F(CodedStreamTest, EmptyInputBeforeEos) {
private: private:
bool Next(const void** data, int* size) override { bool Next(const void** data, int* size) override {
*data = NULL; *data = nullptr;
*size = 0; *size = 0;
return count_++ < 2; return count_++ < 2;
} }
@ -255,11 +257,11 @@ TEST_1D(CodedStreamTest, ExpectTag, kVarintCases) {
// Read one byte to force coded_input.Refill() to be called. Otherwise, // Read one byte to force coded_input.Refill() to be called. Otherwise,
// ExpectTag() will return a false negative. // ExpectTag() will return a false negative.
uint8 dummy; uint8_t dummy;
coded_input.ReadRaw(&dummy, 1); coded_input.ReadRaw(&dummy, 1);
EXPECT_EQ((uint)'\0', (uint)dummy); EXPECT_EQ((uint)'\0', (uint)dummy);
uint32 expected_value = static_cast<uint32>(kVarintCases_case.value); uint32_t expected_value = static_cast<uint32_t>(kVarintCases_case.value);
// ExpectTag() produces false negatives for large values. // ExpectTag() produces false negatives for large values.
if (kVarintCases_case.size <= 2) { if (kVarintCases_case.size <= 2) {
@ -280,16 +282,17 @@ TEST_1D(CodedStreamTest, ExpectTag, kVarintCases) {
TEST_1D(CodedStreamTest, ExpectTagFromArray, kVarintCases) { TEST_1D(CodedStreamTest, ExpectTagFromArray, kVarintCases) {
memcpy(buffer_, kVarintCases_case.bytes, kVarintCases_case.size); memcpy(buffer_, kVarintCases_case.bytes, kVarintCases_case.size);
const uint32 expected_value = static_cast<uint32>(kVarintCases_case.value); const uint32_t expected_value =
static_cast<uint32_t>(kVarintCases_case.value);
// If the expectation succeeds, it should return a pointer past the tag. // If the expectation succeeds, it should return a pointer past the tag.
if (kVarintCases_case.size <= 2) { if (kVarintCases_case.size <= 2) {
EXPECT_TRUE(NULL == CodedInputStream::ExpectTagFromArray( EXPECT_TRUE(nullptr == CodedInputStream::ExpectTagFromArray(
buffer_, expected_value + 1)); buffer_, expected_value + 1));
EXPECT_TRUE(buffer_ + kVarintCases_case.size == EXPECT_TRUE(buffer_ + kVarintCases_case.size ==
CodedInputStream::ExpectTagFromArray(buffer_, expected_value)); CodedInputStream::ExpectTagFromArray(buffer_, expected_value));
} else { } else {
EXPECT_TRUE(NULL == EXPECT_TRUE(nullptr ==
CodedInputStream::ExpectTagFromArray(buffer_, expected_value)); CodedInputStream::ExpectTagFromArray(buffer_, expected_value));
} }
} }
@ -301,7 +304,7 @@ TEST_2D(CodedStreamTest, ReadVarint64, kVarintCases, kBlockSizes) {
{ {
CodedInputStream coded_input(&input); CodedInputStream coded_input(&input);
uint64 value; uint64_t value;
EXPECT_TRUE(coded_input.ReadVarint64(&value)); EXPECT_TRUE(coded_input.ReadVarint64(&value));
EXPECT_EQ(kVarintCases_case.value, value); EXPECT_EQ(kVarintCases_case.value, value);
} }
@ -320,7 +323,7 @@ TEST_2D(CodedStreamTest, WriteVarint32, kVarintCases, kBlockSizes) {
{ {
CodedOutputStream coded_output(&output); CodedOutputStream coded_output(&output);
coded_output.WriteVarint32(static_cast<uint32>(kVarintCases_case.value)); coded_output.WriteVarint32(static_cast<uint32_t>(kVarintCases_case.value));
EXPECT_FALSE(coded_output.HadError()); EXPECT_FALSE(coded_output.HadError());
EXPECT_EQ(kVarintCases_case.size, coded_output.ByteCount()); EXPECT_EQ(kVarintCases_case.size, coded_output.ByteCount());
@ -352,7 +355,7 @@ TEST_2D(CodedStreamTest, WriteVarint64, kVarintCases, kBlockSizes) {
// "sorry, unimplemented: `method_call_expr' not supported by dump_expr" // "sorry, unimplemented: `method_call_expr' not supported by dump_expr"
#if !defined(__GNUC__) || __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3) #if !defined(__GNUC__) || __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3)
int32 kSignExtendedVarintCases[] = {0, 1, -1, 1237894, -37895138}; int32_t kSignExtendedVarintCases[] = {0, 1, -1, 1237894, -37895138};
TEST_2D(CodedStreamTest, WriteVarint32SignExtended, kSignExtendedVarintCases, TEST_2D(CodedStreamTest, WriteVarint32SignExtended, kSignExtendedVarintCases,
kBlockSizes) { kBlockSizes) {
@ -383,10 +386,10 @@ TEST_2D(CodedStreamTest, WriteVarint32SignExtended, kSignExtendedVarintCases,
{ {
CodedInputStream coded_input(&input); CodedInputStream coded_input(&input);
uint64 value; uint64_t value;
EXPECT_TRUE(coded_input.ReadVarint64(&value)); EXPECT_TRUE(coded_input.ReadVarint64(&value));
EXPECT_EQ(kSignExtendedVarintCases_case, static_cast<int64>(value)); EXPECT_EQ(kSignExtendedVarintCases_case, static_cast<int64_t>(value));
} }
EXPECT_EQ(output.ByteCount(), input.ByteCount()); EXPECT_EQ(output.ByteCount(), input.ByteCount());
@ -399,8 +402,8 @@ TEST_2D(CodedStreamTest, WriteVarint32SignExtended, kSignExtendedVarintCases,
// Varint failure test. // Varint failure test.
struct VarintErrorCase { struct VarintErrorCase {
uint8 bytes[12]; uint8_t bytes[12];
int size; size_t size;
bool can_parse; bool can_parse;
}; };
@ -430,22 +433,22 @@ const VarintErrorCase kVarintErrorCases[] = {
TEST_2D(CodedStreamTest, ReadVarint32Error, kVarintErrorCases, kBlockSizes) { TEST_2D(CodedStreamTest, ReadVarint32Error, kVarintErrorCases, kBlockSizes) {
memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size); memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size);
ArrayInputStream input(buffer_, kVarintErrorCases_case.size, ArrayInputStream input(buffer_, static_cast<int>(kVarintErrorCases_case.size),
kBlockSizes_case); kBlockSizes_case);
CodedInputStream coded_input(&input); CodedInputStream coded_input(&input);
uint32 value; uint32_t value;
EXPECT_EQ(kVarintErrorCases_case.can_parse, coded_input.ReadVarint32(&value)); EXPECT_EQ(kVarintErrorCases_case.can_parse, coded_input.ReadVarint32(&value));
} }
TEST_2D(CodedStreamTest, ReadVarint32Error_LeavesValueInInitializedState, TEST_2D(CodedStreamTest, ReadVarint32Error_LeavesValueInInitializedState,
kVarintErrorCases, kBlockSizes) { kVarintErrorCases, kBlockSizes) {
memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size); memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size);
ArrayInputStream input(buffer_, kVarintErrorCases_case.size, ArrayInputStream input(buffer_, static_cast<int>(kVarintErrorCases_case.size),
kBlockSizes_case); kBlockSizes_case);
CodedInputStream coded_input(&input); CodedInputStream coded_input(&input);
uint32 value = 0; uint32_t value = 0;
EXPECT_EQ(kVarintErrorCases_case.can_parse, coded_input.ReadVarint32(&value)); EXPECT_EQ(kVarintErrorCases_case.can_parse, coded_input.ReadVarint32(&value));
// While the specific value following a failure is not critical, we do want to // While the specific value following a failure is not critical, we do want to
// ensure that it doesn't get set to an uninitialized value. (This check fails // ensure that it doesn't get set to an uninitialized value. (This check fails
@ -455,22 +458,22 @@ TEST_2D(CodedStreamTest, ReadVarint32Error_LeavesValueInInitializedState,
TEST_2D(CodedStreamTest, ReadVarint64Error, kVarintErrorCases, kBlockSizes) { TEST_2D(CodedStreamTest, ReadVarint64Error, kVarintErrorCases, kBlockSizes) {
memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size); memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size);
ArrayInputStream input(buffer_, kVarintErrorCases_case.size, ArrayInputStream input(buffer_, static_cast<int>(kVarintErrorCases_case.size),
kBlockSizes_case); kBlockSizes_case);
CodedInputStream coded_input(&input); CodedInputStream coded_input(&input);
uint64 value; uint64_t value;
EXPECT_EQ(kVarintErrorCases_case.can_parse, coded_input.ReadVarint64(&value)); EXPECT_EQ(kVarintErrorCases_case.can_parse, coded_input.ReadVarint64(&value));
} }
TEST_2D(CodedStreamTest, ReadVarint64Error_LeavesValueInInitializedState, TEST_2D(CodedStreamTest, ReadVarint64Error_LeavesValueInInitializedState,
kVarintErrorCases, kBlockSizes) { kVarintErrorCases, kBlockSizes) {
memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size); memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size);
ArrayInputStream input(buffer_, kVarintErrorCases_case.size, ArrayInputStream input(buffer_, static_cast<int>(kVarintErrorCases_case.size),
kBlockSizes_case); kBlockSizes_case);
CodedInputStream coded_input(&input); CodedInputStream coded_input(&input);
uint64 value = 0; uint64_t value = 0;
EXPECT_EQ(kVarintErrorCases_case.can_parse, coded_input.ReadVarint64(&value)); EXPECT_EQ(kVarintErrorCases_case.can_parse, coded_input.ReadVarint64(&value));
// While the specific value following a failure is not critical, we do want to // While the specific value following a failure is not critical, we do want to
// ensure that it doesn't get set to an uninitialized value. (This check fails // ensure that it doesn't get set to an uninitialized value. (This check fails
@ -482,7 +485,7 @@ TEST_2D(CodedStreamTest, ReadVarint64Error_LeavesValueInInitializedState,
// VarintSize // VarintSize
struct VarintSizeCase { struct VarintSizeCase {
uint64 value; uint64_t value;
int size; int size;
}; };
@ -509,7 +512,7 @@ TEST_1D(CodedStreamTest, VarintSize32, kVarintSizeCases) {
EXPECT_EQ(kVarintSizeCases_case.size, EXPECT_EQ(kVarintSizeCases_case.size,
CodedOutputStream::VarintSize32( CodedOutputStream::VarintSize32(
static_cast<uint32>(kVarintSizeCases_case.value))); static_cast<uint32_t>(kVarintSizeCases_case.value)));
} }
TEST_1D(CodedStreamTest, VarintSize64, kVarintSizeCases) { TEST_1D(CodedStreamTest, VarintSize64, kVarintSizeCases) {
@ -523,8 +526,8 @@ TEST_F(CodedStreamTest, VarintSize32PowersOfTwo) {
if (i % 7 == 0) { if (i % 7 == 0) {
expected += 1; expected += 1;
} }
EXPECT_EQ(expected, EXPECT_EQ(expected, CodedOutputStream::VarintSize32(
CodedOutputStream::VarintSize32(static_cast<uint32>(0x1u << i))); static_cast<uint32_t>(0x1u << i)));
} }
} }
@ -534,8 +537,7 @@ TEST_F(CodedStreamTest, VarintSize64PowersOfTwo) {
if (i % 7 == 0) { if (i % 7 == 0) {
expected += 1; expected += 1;
} }
EXPECT_EQ(expected, CodedOutputStream::VarintSize64( EXPECT_EQ(expected, CodedOutputStream::VarintSize64(uint64_t{1} << i));
static_cast<uint64>(0x1ull << i)));
} }
} }
@ -543,13 +545,13 @@ TEST_F(CodedStreamTest, VarintSize64PowersOfTwo) {
// Fixed-size int tests // Fixed-size int tests
struct Fixed32Case { struct Fixed32Case {
uint8 bytes[sizeof(uint32)]; // Encoded bytes. uint8_t bytes[sizeof(uint32_t)]; // Encoded bytes.
uint32 value; // Parsed value. uint32_t value; // Parsed value.
}; };
struct Fixed64Case { struct Fixed64Case {
uint8 bytes[sizeof(uint64)]; // Encoded bytes. uint8_t bytes[sizeof(uint64_t)]; // Encoded bytes.
uint64 value; // Parsed value. uint64_t value; // Parsed value.
}; };
inline std::ostream& operator<<(std::ostream& os, const Fixed32Case& c) { inline std::ostream& operator<<(std::ostream& os, const Fixed32Case& c) {
@ -579,12 +581,12 @@ TEST_2D(CodedStreamTest, ReadLittleEndian32, kFixed32Cases, kBlockSizes) {
{ {
CodedInputStream coded_input(&input); CodedInputStream coded_input(&input);
uint32 value; uint32_t value;
EXPECT_TRUE(coded_input.ReadLittleEndian32(&value)); EXPECT_TRUE(coded_input.ReadLittleEndian32(&value));
EXPECT_EQ(kFixed32Cases_case.value, value); EXPECT_EQ(kFixed32Cases_case.value, value);
} }
EXPECT_EQ(sizeof(uint32), input.ByteCount()); EXPECT_EQ(sizeof(uint32_t), input.ByteCount());
} }
TEST_2D(CodedStreamTest, ReadLittleEndian64, kFixed64Cases, kBlockSizes) { TEST_2D(CodedStreamTest, ReadLittleEndian64, kFixed64Cases, kBlockSizes) {
@ -594,12 +596,12 @@ TEST_2D(CodedStreamTest, ReadLittleEndian64, kFixed64Cases, kBlockSizes) {
{ {
CodedInputStream coded_input(&input); CodedInputStream coded_input(&input);
uint64 value; uint64_t value;
EXPECT_TRUE(coded_input.ReadLittleEndian64(&value)); EXPECT_TRUE(coded_input.ReadLittleEndian64(&value));
EXPECT_EQ(kFixed64Cases_case.value, value); EXPECT_EQ(kFixed64Cases_case.value, value);
} }
EXPECT_EQ(sizeof(uint64), input.ByteCount()); EXPECT_EQ(sizeof(uint64_t), input.ByteCount());
} }
TEST_2D(CodedStreamTest, WriteLittleEndian32, kFixed32Cases, kBlockSizes) { TEST_2D(CodedStreamTest, WriteLittleEndian32, kFixed32Cases, kBlockSizes) {
@ -611,11 +613,11 @@ TEST_2D(CodedStreamTest, WriteLittleEndian32, kFixed32Cases, kBlockSizes) {
coded_output.WriteLittleEndian32(kFixed32Cases_case.value); coded_output.WriteLittleEndian32(kFixed32Cases_case.value);
EXPECT_FALSE(coded_output.HadError()); EXPECT_FALSE(coded_output.HadError());
EXPECT_EQ(sizeof(uint32), coded_output.ByteCount()); EXPECT_EQ(sizeof(uint32_t), coded_output.ByteCount());
} }
EXPECT_EQ(sizeof(uint32), output.ByteCount()); EXPECT_EQ(sizeof(uint32_t), output.ByteCount());
EXPECT_EQ(0, memcmp(buffer_, kFixed32Cases_case.bytes, sizeof(uint32))); EXPECT_EQ(0, memcmp(buffer_, kFixed32Cases_case.bytes, sizeof(uint32_t)));
} }
TEST_2D(CodedStreamTest, WriteLittleEndian64, kFixed64Cases, kBlockSizes) { TEST_2D(CodedStreamTest, WriteLittleEndian64, kFixed64Cases, kBlockSizes) {
@ -627,11 +629,11 @@ TEST_2D(CodedStreamTest, WriteLittleEndian64, kFixed64Cases, kBlockSizes) {
coded_output.WriteLittleEndian64(kFixed64Cases_case.value); coded_output.WriteLittleEndian64(kFixed64Cases_case.value);
EXPECT_FALSE(coded_output.HadError()); EXPECT_FALSE(coded_output.HadError());
EXPECT_EQ(sizeof(uint64), coded_output.ByteCount()); EXPECT_EQ(sizeof(uint64_t), coded_output.ByteCount());
} }
EXPECT_EQ(sizeof(uint64), output.ByteCount()); EXPECT_EQ(sizeof(uint64_t), output.ByteCount());
EXPECT_EQ(0, memcmp(buffer_, kFixed64Cases_case.bytes, sizeof(uint64))); EXPECT_EQ(0, memcmp(buffer_, kFixed64Cases_case.bytes, sizeof(uint64_t)));
} }
// Tests using the static methods to read fixed-size values from raw arrays. // Tests using the static methods to read fixed-size values from raw arrays.
@ -639,8 +641,8 @@ TEST_2D(CodedStreamTest, WriteLittleEndian64, kFixed64Cases, kBlockSizes) {
TEST_1D(CodedStreamTest, ReadLittleEndian32FromArray, kFixed32Cases) { TEST_1D(CodedStreamTest, ReadLittleEndian32FromArray, kFixed32Cases) {
memcpy(buffer_, kFixed32Cases_case.bytes, sizeof(kFixed32Cases_case.bytes)); memcpy(buffer_, kFixed32Cases_case.bytes, sizeof(kFixed32Cases_case.bytes));
uint32 value; uint32_t value;
const uint8* end = const uint8_t* end =
CodedInputStream::ReadLittleEndian32FromArray(buffer_, &value); CodedInputStream::ReadLittleEndian32FromArray(buffer_, &value);
EXPECT_EQ(kFixed32Cases_case.value, value); EXPECT_EQ(kFixed32Cases_case.value, value);
EXPECT_TRUE(end == buffer_ + sizeof(value)); EXPECT_TRUE(end == buffer_ + sizeof(value));
@ -649,8 +651,8 @@ TEST_1D(CodedStreamTest, ReadLittleEndian32FromArray, kFixed32Cases) {
TEST_1D(CodedStreamTest, ReadLittleEndian64FromArray, kFixed64Cases) { TEST_1D(CodedStreamTest, ReadLittleEndian64FromArray, kFixed64Cases) {
memcpy(buffer_, kFixed64Cases_case.bytes, sizeof(kFixed64Cases_case.bytes)); memcpy(buffer_, kFixed64Cases_case.bytes, sizeof(kFixed64Cases_case.bytes));
uint64 value; uint64_t value;
const uint8* end = const uint8_t* end =
CodedInputStream::ReadLittleEndian64FromArray(buffer_, &value); CodedInputStream::ReadLittleEndian64FromArray(buffer_, &value);
EXPECT_EQ(kFixed64Cases_case.value, value); EXPECT_EQ(kFixed64Cases_case.value, value);
EXPECT_TRUE(end == buffer_ + sizeof(value)); EXPECT_TRUE(end == buffer_ + sizeof(value));
@ -723,14 +725,14 @@ TEST_1D(CodedStreamTest, ReadStringImpossiblyLarge, kBlockSizes) {
TEST_F(CodedStreamTest, ReadStringImpossiblyLargeFromStringOnStack) { TEST_F(CodedStreamTest, ReadStringImpossiblyLargeFromStringOnStack) {
// Same test as above, except directly use a buffer. This used to cause // Same test as above, except directly use a buffer. This used to cause
// crashes while the above did not. // crashes while the above did not.
uint8 buffer[8]; uint8_t buffer[8];
CodedInputStream coded_input(buffer, 8); CodedInputStream coded_input(buffer, 8);
std::string str; std::string str;
EXPECT_FALSE(coded_input.ReadString(&str, 1 << 30)); EXPECT_FALSE(coded_input.ReadString(&str, 1 << 30));
} }
TEST_F(CodedStreamTest, ReadStringImpossiblyLargeFromStringOnHeap) { TEST_F(CodedStreamTest, ReadStringImpossiblyLargeFromStringOnHeap) {
std::unique_ptr<uint8[]> buffer(new uint8[8]); std::unique_ptr<uint8_t[]> buffer(new uint8_t[8]);
CodedInputStream coded_input(buffer.get(), 8); CodedInputStream coded_input(buffer.get(), 8);
std::string str; std::string str;
EXPECT_FALSE(coded_input.ReadString(&str, 1 << 30)); EXPECT_FALSE(coded_input.ReadString(&str, 1 << 30));
@ -1021,7 +1023,7 @@ TEST_1D(CodedStreamTest, BasicLimit, kBlockSizes) {
CodedInputStream::Limit limit = coded_input.PushLimit(8); CodedInputStream::Limit limit = coded_input.PushLimit(8);
// Read until we hit the limit. // Read until we hit the limit.
uint32 value; uint32_t value;
EXPECT_EQ(8, coded_input.BytesUntilLimit()); EXPECT_EQ(8, coded_input.BytesUntilLimit());
EXPECT_TRUE(coded_input.ReadLittleEndian32(&value)); EXPECT_TRUE(coded_input.ReadLittleEndian32(&value));
EXPECT_EQ(4, coded_input.BytesUntilLimit()); EXPECT_EQ(4, coded_input.BytesUntilLimit());
@ -1052,7 +1054,7 @@ TEST_1D(CodedStreamTest, SmallLimitOnTopOfBigLimit, kBlockSizes) {
EXPECT_EQ(8, coded_input.BytesUntilLimit()); EXPECT_EQ(8, coded_input.BytesUntilLimit());
CodedInputStream::Limit limit2 = coded_input.PushLimit(4); CodedInputStream::Limit limit2 = coded_input.PushLimit(4);
uint32 value; uint32_t value;
// Read until we hit limit2, the top and shortest limit. // Read until we hit limit2, the top and shortest limit.
EXPECT_EQ(4, coded_input.BytesUntilLimit()); EXPECT_EQ(4, coded_input.BytesUntilLimit());
@ -1094,7 +1096,7 @@ TEST_1D(CodedStreamTest, BigLimitOnTopOfSmallLimit, kBlockSizes) {
EXPECT_EQ(4, coded_input.BytesUntilLimit()); EXPECT_EQ(4, coded_input.BytesUntilLimit());
CodedInputStream::Limit limit2 = coded_input.PushLimit(8); CodedInputStream::Limit limit2 = coded_input.PushLimit(8);
uint32 value; uint32_t value;
// Read until we hit limit2. Except, wait! limit1 is shorter, so // Read until we hit limit2. Except, wait! limit1 is shorter, so
// we end up hitting that first, despite having 4 bytes to go on // we end up hitting that first, despite having 4 bytes to go on
@ -1131,7 +1133,7 @@ TEST_F(CodedStreamTest, ExpectAtEnd) {
CodedInputStream::Limit limit = coded_input.PushLimit(4); CodedInputStream::Limit limit = coded_input.PushLimit(4);
uint32 value; uint32_t value;
EXPECT_TRUE(coded_input.ReadLittleEndian32(&value)); EXPECT_TRUE(coded_input.ReadLittleEndian32(&value));
EXPECT_TRUE(coded_input.ExpectAtEnd()); EXPECT_TRUE(coded_input.ExpectAtEnd());
@ -1276,7 +1278,6 @@ TEST_F(CodedStreamTest, RecursionLimit) {
class ReallyBigInputStream : public ZeroCopyInputStream { class ReallyBigInputStream : public ZeroCopyInputStream {
public: public:
ReallyBigInputStream() : backup_amount_(0), buffer_count_(0) {} ReallyBigInputStream() : backup_amount_(0), buffer_count_(0) {}
~ReallyBigInputStream() {}
// implements ZeroCopyInputStream ---------------------------------- // implements ZeroCopyInputStream ----------------------------------
bool Next(const void** data, int* size) override { bool Next(const void** data, int* size) override {
@ -1316,7 +1317,7 @@ class ReallyBigInputStream : public ZeroCopyInputStream {
private: private:
char buffer_[1024]; char buffer_[1024];
int64 buffer_count_; int64_t buffer_count_;
}; };
TEST_F(CodedStreamTest, InputOver2G) { TEST_F(CodedStreamTest, InputOver2G) {

@ -256,7 +256,8 @@
#endif #endif
#if __has_cpp_attribute(clang::musttail) && !defined(__arm__) && \ #if __has_cpp_attribute(clang::musttail) && !defined(__arm__) && \
!defined(_ARCH_PPC) && !defined(__wasm__) && \ !defined(_ARCH_PPC) && !defined(__wasm__) && \
!(defined(_MSC_VER) && defined(_M_IX86)) !(defined(_MSC_VER) && defined(_M_IX86)) && \
!(defined(__NDK_MAJOR__) && __NDK_MAJOR <= 24)
# ifndef PROTO2_OPENSOURCE # ifndef PROTO2_OPENSOURCE
// Compilation fails on ARM32: b/195943306 // Compilation fails on ARM32: b/195943306
// Compilation fails on powerpc64le: b/187985113 // Compilation fails on powerpc64le: b/187985113
@ -861,6 +862,9 @@
#undef TRUE #undef TRUE
#pragma push_macro("FALSE") #pragma push_macro("FALSE")
#undef FALSE #undef FALSE
// Inconvenient macro names from usr/include/sys/syslimits.h in some macOS SDKs.
#pragma push_macro("UID_MAX")
#undef UID_MAX
#endif // __APPLE__ #endif // __APPLE__
#if defined(__clang__) || PROTOBUF_GNUC_MIN(3, 0) || defined(_MSC_VER) #if defined(__clang__) || PROTOBUF_GNUC_MIN(3, 0) || defined(_MSC_VER)
@ -872,9 +876,6 @@
#if defined(__clang__) #if defined(__clang__)
#pragma clang diagnostic push #pragma clang diagnostic push
// TODO(gerbens) ideally we cleanup the code. But a cursory try shows many
// violations. So let's ignore for now.
#pragma clang diagnostic ignored "-Wshorten-64-to-32"
#elif PROTOBUF_GNUC_MIN(3, 0) #elif PROTOBUF_GNUC_MIN(3, 0)
// GCC does not allow disabling diagnostics within an expression: // GCC does not allow disabling diagnostics within an expression:
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60875, so we disable this one // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60875, so we disable this one

@ -143,6 +143,7 @@
#pragma pop_macro("DOMAIN") #pragma pop_macro("DOMAIN")
#pragma pop_macro("TRUE") #pragma pop_macro("TRUE")
#pragma pop_macro("FALSE") #pragma pop_macro("FALSE")
#pragma pop_macro("UID_MAX")
#endif // __APPLE__ #endif // __APPLE__
#if defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER) #if defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER)

@ -64,13 +64,13 @@ bool ParseDelimitedFromZeroCopyStream(MessageLite* message,
bool ParseDelimitedFromCodedStream(MessageLite* message, bool ParseDelimitedFromCodedStream(MessageLite* message,
io::CodedInputStream* input, io::CodedInputStream* input,
bool* clean_eof) { bool* clean_eof) {
if (clean_eof != NULL) *clean_eof = false; if (clean_eof != nullptr) *clean_eof = false;
int start = input->CurrentPosition(); int start = input->CurrentPosition();
// Read the size. // Read the size.
uint32 size; uint32_t size;
if (!input->ReadVarint32(&size)) { if (!input->ReadVarint32(&size)) {
if (clean_eof != NULL) *clean_eof = input->CurrentPosition() == start; if (clean_eof != nullptr) *clean_eof = input->CurrentPosition() == start;
return false; return false;
} }
@ -79,7 +79,7 @@ bool ParseDelimitedFromCodedStream(MessageLite* message,
int position_after_size = input->CurrentPosition(); int position_after_size = input->CurrentPosition();
// Tell the stream not to read beyond that size. // Tell the stream not to read beyond that size.
io::CodedInputStream::Limit limit = input->PushLimit(size); io::CodedInputStream::Limit limit = input->PushLimit(static_cast<int>(size));
// Parse the message. // Parse the message.
if (!message->MergeFromCodedStream(input)) return false; if (!message->MergeFromCodedStream(input)) return false;
@ -105,11 +105,12 @@ bool SerializeDelimitedToCodedStream(const MessageLite& message,
size_t size = message.ByteSizeLong(); size_t size = message.ByteSizeLong();
if (size > INT_MAX) return false; if (size > INT_MAX) return false;
output->WriteVarint32(size); output->WriteVarint32(static_cast<uint32_t>(size));
// Write the content. // Write the content.
uint8* buffer = output->GetDirectBufferForNBytesAndAdvance(size); uint8_t* buffer =
if (buffer != NULL) { output->GetDirectBufferForNBytesAndAdvance(static_cast<int>(size));
if (buffer != nullptr) {
// Optimization: The message fits in one buffer, so use the faster // Optimization: The message fits in one buffer, so use the faster
// direct-to-array serialization path. // direct-to-array serialization path.
message.SerializeWithCachedSizesToArray(buffer); message.SerializeWithCachedSizesToArray(buffer);

@ -116,15 +116,15 @@ std::string FormatNanos(int32_t nanos) {
} }
} }
std::string FormatTime(int64 seconds, int32 nanos) { std::string FormatTime(int64_t seconds, int32_t nanos) {
return ::google::protobuf::internal::FormatTime(seconds, nanos); return ::google::protobuf::internal::FormatTime(seconds, nanos);
} }
bool ParseTime(const std::string& value, int64* seconds, int32* nanos) { bool ParseTime(const std::string& value, int64_t* seconds, int32_t* nanos) {
return ::google::protobuf::internal::ParseTime(value, seconds, nanos); return ::google::protobuf::internal::ParseTime(value, seconds, nanos);
} }
void CurrentTime(int64* seconds, int32* nanos) { void CurrentTime(int64_t* seconds, int32_t* nanos) {
return ::google::protobuf::internal::GetCurrentTime(seconds, nanos); return ::google::protobuf::internal::GetCurrentTime(seconds, nanos);
} }
@ -207,7 +207,7 @@ bool TimeUtil::FromString(const std::string& value, Duration* duration) {
return false; return false;
} }
bool negative = (value[0] == '-'); bool negative = (value[0] == '-');
int sign_length = (negative ? 1 : 0); size_t sign_length = (negative ? 1 : 0);
// Parse the duration value as two integers rather than a float value // Parse the duration value as two integers rather than a float value
// to avoid precision loss. // to avoid precision loss.
std::string seconds_part, nanos_part; std::string seconds_part, nanos_part;
@ -228,7 +228,7 @@ bool TimeUtil::FromString(const std::string& value, Duration* duration) {
if (end != nanos_part.c_str() + nanos_part.length()) { if (end != nanos_part.c_str() + nanos_part.length()) {
return false; return false;
} }
nanos = nanos * Pow(10, 9 - nanos_part.length()); nanos = nanos * Pow(10, static_cast<int>(9 - nanos_part.length()));
if (negative) { if (negative) {
// If a Duration is negative, both seconds and nanos should be negative. // If a Duration is negative, both seconds and nanos should be negative.
seconds = -seconds; seconds = -seconds;
@ -434,9 +434,12 @@ Duration& operator*=(Duration& d, int64_t r) { // NOLINT
} }
Duration& operator*=(Duration& d, double r) { // NOLINT Duration& operator*=(Duration& d, double r) { // NOLINT
double result = (d.seconds() * 1.0 + 1.0 * d.nanos() / kNanosPerSecond) * r; double result =
(static_cast<double>(d.seconds()) + d.nanos() * (1.0 / kNanosPerSecond)) *
r;
int64_t seconds = static_cast<int64_t>(result); int64_t seconds = static_cast<int64_t>(result);
int32_t nanos = static_cast<int32_t>((result - seconds) * kNanosPerSecond); int32_t nanos = static_cast<int32_t>((result - static_cast<double>(seconds)) *
kNanosPerSecond);
// Note that we normalize here not just because nanos can have a different // Note that we normalize here not just because nanos can have a different
// sign from seconds but also that nanos can be any arbitrary value when // sign from seconds but also that nanos can be any arbitrary value when
// overflow happens (i.e., the result is a much larger value than what // overflow happens (i.e., the result is a much larger value than what

@ -40,8 +40,8 @@
#ifdef _MSC_VER #ifdef _MSC_VER
#ifdef _XBOX_ONE #ifdef _XBOX_ONE
struct timeval { struct timeval {
int64 tv_sec; /* seconds */ int64_t tv_sec; /* seconds */
int64 tv_usec; /* and microseconds */ int64_t tv_usec; /* and microseconds */
}; };
#else #else
#include <winsock2.h> #include <winsock2.h>

Loading…
Cancel
Save