5 Commits

Author SHA1 Message Date
  Chris Kennelly d326c1d6da Prepare to make many APIs [[nodiscard]]. 11 hours ago
  Thomas Van Lenten eade3d4c54 [ObjC] Revise tag parsing to have a 5 byte limit. 11 hours ago
  Protobuf Team Bot 4c2f2727bc Automated Code Change 13 hours ago
  Protobuf Team Bot 2d9cbdc589 Add support for moving lazy fields in static reflection message movers. 18 hours ago
  Protobuf Team Bot 4459a20205 Support more chars in type URLs in the Python text-format parser. 20 hours ago
30 changed files with 490 additions and 128 deletions
Split View
  1. +5
    -4
      benchmarks/benchmark.cc
  2. +2
    -2
      benchmarks/gen_protobuf_binary_cc.py
  3. +0
    -2
      conformance/failure_list_objc.txt
  4. +3
    -1
      java/core/src/main/java/com/google/protobuf/MapField.java
  5. +2
    -1
      lua/upbc.cc
  6. +17
    -6
      objectivec/GPBCodedInputStream.m
  7. +222
    -32
      python/google/protobuf/internal/text_format_test.py
  8. +8
    -4
      python/google/protobuf/proto_api.cc
  9. +4
    -2
      python/google/protobuf/pyext/descriptor.cc
  10. +4
    -2
      python/google/protobuf/pyext/message_module.cc
  11. +109
    -27
      python/google/protobuf/text_format.py
  12. +4
    -2
      src/google/protobuf/compiler/csharp/csharp_field_base.cc
  13. +23
    -0
      src/google/protobuf/extension_set.h
  14. +1
    -0
      src/google/protobuf/extension_set_unittest.cc
  15. +2
    -0
      src/google/protobuf/generated_message_reflection_unittest.cc
  16. +13
    -0
      src/google/protobuf/generated_message_util.h
  17. +10
    -5
      src/google/protobuf/io/coded_stream.cc
  18. +16
    -8
      src/google/protobuf/io/coded_stream_unittest.cc
  19. +6
    -6
      src/google/protobuf/io/test_zero_copy_stream_test.cc
  20. +4
    -2
      src/google/protobuf/io/zero_copy_stream_impl_lite.cc
  21. +4
    -2
      src/google/protobuf/json/internal/untyped_message.cc
  22. +3
    -2
      src/google/protobuf/lite_unittest.cc
  23. +8
    -4
      src/google/protobuf/message_lite.cc
  24. +1
    -1
      src/google/protobuf/message_unittest.inc
  25. +3
    -0
      src/google/protobuf/no_field_presence_test.cc
  26. +4
    -2
      src/google/protobuf/parse_context.cc
  27. +6
    -5
      src/google/protobuf/proto3_arena_unittest.cc
  28. +2
    -2
      src/google/protobuf/wire_format_unittest.h
  29. +2
    -2
      upb/util/def_to_proto_test.cc
  30. +2
    -2
      upb/util/def_to_proto_test.h

+ 5
- 4
benchmarks/benchmark.cc View File

@@ -328,9 +328,10 @@ BENCHMARK_TEMPLATE(BM_Parse_Proto2, FileDescSV, InitBlock, Alias);

static void BM_SerializeDescriptor_Proto2(benchmark::State& state) {
upb_benchmark::FileDescriptorProto proto;
proto.ParseFromString(absl::string_view(descriptor.data, descriptor.size));
(void)proto.ParseFromString(
absl::string_view(descriptor.data, descriptor.size));
for (auto _ : state) {
proto.SerializePartialToArray(buf, sizeof(buf));
(void)proto.SerializePartialToArray(buf, sizeof(buf));
benchmark::DoNotOptimize(buf);
}
state.SetBytesProcessed(state.iterations() * descriptor.size);
@@ -420,7 +421,7 @@ BENCHMARK(BM_JsonParse_Upb);
static void BM_JsonParse_Proto2(benchmark::State& state) {
protobuf::FileDescriptorProto proto;
absl::string_view input(descriptor.data, descriptor.size);
proto.ParseFromString(input);
(void)proto.ParseFromString(input);
std::string json;
ABSL_CHECK_OK(google::protobuf::json::MessageToJsonString(proto, &json));
for (auto _ : state) {
@@ -461,7 +462,7 @@ BENCHMARK(BM_JsonSerialize_Upb);
static void BM_JsonSerialize_Proto2(benchmark::State& state) {
protobuf::FileDescriptorProto proto;
absl::string_view input(descriptor.data, descriptor.size);
proto.ParseFromString(input);
(void)proto.ParseFromString(input);
std::string json;
for (auto _ : state) {
json.clear();


+ 2
- 2
benchmarks/gen_protobuf_binary_cc.py View File

@@ -54,8 +54,8 @@ def RefMessage(name):
print('''
{{
{name} proto;
proto.ParseFromArray(buf, 0);
proto.SerializePartialToArray(&buf[0], 0);
(void)proto.ParseFromArray(buf, 0);
(void)proto.SerializePartialToArray(&buf[0], 0);
}}
'''.format(name=name))



+ 0
- 2
conformance/failure_list_objc.txt View File

@@ -1,4 +1,2 @@
# JSON input or output tests are skipped (in conformance_objc.m) as mobile
# platforms don't support JSON wire format to avoid code bloat.

Required.*.ProtobufInput.BadTag_OverlongVarint # Should have failed to parse, but didn't.

+ 3
- 1
java/core/src/main/java/com/google/protobuf/MapField.java View File

@@ -260,7 +260,9 @@ public class MapField<K, V> extends MapFieldReflectionAccessor implements Mutabi
return isMutable;
}

/* (non-Javadoc)
/**
* (non-Javadoc)
*
* @see com.google.protobuf.MutabilityOracle#ensureMutable()
*/
@Override


+ 2
- 1
lua/upbc.cc View File

@@ -99,7 +99,8 @@ bool LuaGenerator::Generate(const protobuf::FileDescriptor* file,
protobuf::FileDescriptorProto file_proto;
file->CopyTo(&file_proto);
std::string file_data;
file_proto.SerializeToString(&file_data);
// TODO: Remove this suppression.
(void)file_proto.SerializeToString(&file_data);

printer.Print("local descriptor = table.concat({\n");
absl::string_view data(file_data);


+ 17
- 6
objectivec/GPBCodedInputStream.m View File

@@ -206,22 +206,33 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
return 0;
}

uint64_t rawTag = (uint64_t)ReadRawVarint64(state);
state->lastTag = (int32_t)rawTag;
// Following _upb_Decoder_DecodeLongTag logic, fail if this is >32bit value.
if (rawTag > (uint64_t)UINT32_MAX) {
// The conformance tests now limit things to ensue the varint for a tag fits in 5 bytes. The logic
// for this parse is based on _upb_WireReader_ReadLongTag.
uint64_t rawTag = 0;
BOOL finishedParse = NO;
for (int i = 0; i < 5; i++) {
uint64_t byte = (uint64_t)ReadRawByte(state);
rawTag |= (byte & 0x7F) << (i * 7);
if ((byte & 0x80) == 0) {
finishedParse = YES;
break;
}
}
if (!finishedParse || (rawTag > (uint64_t)UINT32_MAX)) {
GPBRaiseStreamError(GPBCodedInputStreamErrorInvalidTag, @"Invalid tag");
}
uint32_t tag = (uint32_t)rawTag;

// Tags have to include a valid wireformat.
if (!GPBWireFormatIsValidTag(state->lastTag)) {
if (!GPBWireFormatIsValidTag(tag)) {
GPBRaiseStreamError(GPBCodedInputStreamErrorInvalidTag, @"Invalid wireformat in tag.");
}
// Zero is not a valid field number.
if (GPBWireFormatGetTagFieldNumber(state->lastTag) == 0) {
if (GPBWireFormatGetTagFieldNumber(tag) == 0) {
GPBRaiseStreamError(GPBCodedInputStreamErrorInvalidTag,
@"A zero field number on the wire is invalid.");
}
state->lastTag = (int32_t)tag;
return state->lastTag;
}



+ 222
- 32
python/google/protobuf/internal/text_format_test.py View File

@@ -1741,26 +1741,26 @@ class Proto2Tests(TextFormatBase):

# Fail if invalid Any message type url inside unknown extensions.
message = any_test_pb2.TestAny()
text = ('any_value {\n'
' [type.googleapis.com.invalid/google.protobuf.internal.TestAny] {\n'
' [unknown_extension] {\n'
' str: "string"\n'
' any_value {\n'
' [type.googleapis.com/proto2_unittest.OneString] {\n'
' data: "string"\n'
' }\n'
' }\n'
' }\n'
' }\n'
'}\n'
'int32_value: 123')
self.assertRaisesRegex(
text = (
'any_value {\n'
' [invalid@prefix/google.protobuf.internal.TestAny] {\n'
' [unknown_extension] {\n'
' str: "string"\n'
' any_value {\n'
' [type.googleapis.com/proto2_unittest.OneString] {\n'
' data: "string"\n'
' }\n'
' }\n'
' }\n'
' }\n'
'}\n'
'int32_value: 123'
)
with self.assertRaisesRegex(
text_format.ParseError,
'[type.googleapis.com.invalid/google.protobuf.internal.TestAny]',
text_format.Parse,
text,
message,
allow_unknown_extension=True)
'[invalid@prefix/google.protobuf.internal.TestAny]',
):
text_format.Parse(text, message, allow_unknown_extension=True)

def testParseBadIdentifier(self):
message = unittest_pb2.TestAllTypes()
@@ -1885,7 +1885,7 @@ class Proto2Tests(TextFormatBase):
self.assertEqual(5, message.map_int32_foreign_message[111].c)


class Proto3Tests(unittest.TestCase):
class Proto3Tests(parameterized.TestCase):

def testPrintMessageExpandAny(self):
packed_message = unittest_pb2.OneString()
@@ -1893,13 +1893,15 @@ class Proto3Tests(unittest.TestCase):
message = any_test_pb2.TestAny()
message.any_value.Pack(packed_message)
self.assertEqual(
text_format.MessageToString(message,
descriptor_pool=descriptor_pool.Default()),
text_format.MessageToString(
message, descriptor_pool=descriptor_pool.Default()
),
'any_value {\n'
' [type.googleapis.com/proto2_unittest.OneString] {\n'
' data: "string"\n'
' }\n'
'}\n')
'}\n',
)

def testPrintStructInAny(self):
packed_message = struct_pb2.Struct()
@@ -2084,17 +2086,205 @@ class Proto3Tests(unittest.TestCase):
message.any_value.Unpack(packed_message)
self.assertEqual('string', packed_message.data)

def testMergeAlternativeUrl(self):
@parameterized.parameters(
{
'any_name': '[domain.com/proto2_unittest.OneString]',
'type_url': 'domain.com/proto2_unittest.OneString',
},
# Multiple slashes in prefix
{
'any_name': '[domain.com/path/proto2_unittest.OneString]',
'type_url': 'domain.com/path/proto2_unittest.OneString',
},
{
'any_name': '[domain.com///path//proto2_unittest.OneString]',
'type_url': 'domain.com///path//proto2_unittest.OneString',
},
# Special characters in prefix
{
'any_name': '[domain.com/-.~_!$&()*+,;=/proto2_unittest.OneString]',
'type_url': 'domain.com/-.~_!$&()*+,;=/proto2_unittest.OneString',
},
# Percent escapes in prefix
{
'any_name': (
'[percent.escapes/%0a%1B%2c%3D%4e%F5%A6%b7%C8%f9/proto2_unittest.OneString]'
),
'type_url': (
'percent.escapes/%0a%1B%2c%3D%4e%F5%A6%b7%C8%f9/proto2_unittest.OneString'
),
},
# Whitespace and comments (should be ignored between [])
{
'any_name': '[ domain . com / proto2_ unittest. One String ]',
'type_url': 'domain.com/proto2_unittest.OneString',
},
{
'any_name': (
'[ \t\n\r\f\v domain.com/pr \t\n\r\f\v oto2_unittest.OneString'
' \t\n\r\f\v ]'
),
'type_url': 'domain.com/proto2_unittest.OneString',
},
{
'any_name': (
'[ # comment\n domain.com/pr # comment\n oto2_unittest.One String'
' # comment\n ]'
),
'type_url': 'domain.com/proto2_unittest.OneString',
},
)
def testMergeExpandedAnyTypeUrls(self, *, any_name, type_url):
message = any_test_pb2.TestAny()
text = ('any_value {\n'
' [type.otherapi.com/proto2_unittest.OneString] {\n'
' data: "string"\n'
' }\n'
'}\n')
text = f'any_value {{\n {any_name} {{\n data: "string"\n }}\n }}'

text_format.Merge(text, message)
packed_message = unittest_pb2.OneString()
self.assertEqual('type.otherapi.com/proto2_unittest.OneString',
message.any_value.type_url)
self.assertEqual(type_url, message.any_value.type_url)

@parameterized.parameters(
# General error cases
{
'any_name': '[',
'error_msg': '2:4 : \' [ {\': Expected "]"',
},
{
'any_name': '[]',
'error_msg': '2:5 : \' [] {\': Type URL does not contain "/"',
},
{
'any_name': '[.type]',
'error_msg': '2:10 : \' [.type] {\': Type URL does not contain "/"',
},
# Prefix error cases
{
'any_name': '[/]',
'error_msg': "2:6 : ' [/] {': Type URL prefix is empty.",
},
{
'any_name': '[/proto2_unittest.OneString]',
'error_msg': (
"2:31 : ' [/proto2_unittest.OneString] {': "
'Type URL prefix is empty'
),
},
{
'any_name': '[/domain.com/proto2_unittest.OneString]',
'error_msg': (
"2:42 : ' [/domain.com/proto2_unittest.OneString] {': "
'Type URL prefix starts with "/"'
),
},
# Special characters in prefix
{
'any_name': '[domain.com/?/proto2_unittest.OneString]',
'error_msg': (
"2:14 : ' [domain.com/?/proto2_unittest.OneString] {':"
' Expected "]"'
),
},
{
'any_name': '[domain.com/:/proto2_unittest.OneString]',
'error_msg': (
"2:14 : ' [domain.com/:/proto2_unittest.OneString] {':"
' Expected "]"'
),
},
{
'any_name': '[domain.com/@/proto2_unittest.OneString]',
'error_msg': (
"2:14 : ' [domain.com/@/proto2_unittest.OneString] {': "
'Expected "]".'
),
},
{
'any_name': '[domain.com/@/proto2_unittest.OneString]',
'error_msg': (
"2:14 : ' [domain.com/@/proto2_unittest.OneString] {':"
' Expected "]"'
),
},
# Percent escapes in prefix
{
'any_name': '[percent.escapes/%/proto2_unittest.OneString]',
'error_msg': (
"2:48 : ' [percent.escapes/%/proto2_unittest.OneString] {':"
' Invalid percent escape, got "%".'
),
},
{
'any_name': '[percent.escapes/%G/proto2_unittest.OneString]',
'error_msg': (
"2:49 : ' [percent.escapes/%G/proto2_unittest.OneString] {':"
' Invalid percent escape, got "%G".'
),
},
{
'any_name': '[percent.escapes/%aG/proto2_unittest.OneString]',
'error_msg': (
"2:50 : ' [percent.escapes/%aG/proto2_unittest.OneString] {':"
' Invalid percent escape, got "%aG".'
),
},
# Invalid type names
{
'any_name': '[domain.com/]',
'error_msg': (
'2:16 : \' [domain.com/] {\': Expected type name, got "".'
),
},
{
'any_name': '[domain.com/.]',
'error_msg': (
'2:17 : \' [domain.com/.] {\': Expected type name, got ".".'
),
},
{
'any_name': '[domain.com/.OneString]',
'error_msg': (
"2:26 : ' [domain.com/.OneString] {': "
'Expected type name, got ".OneString".'
),
},
{
'any_name': '[domain.com/proto2_unittest.]',
'error_msg': (
"2:32 : ' [domain.com/proto2_unittest.] {': "
'Expected type name, got "proto2_unittest.".'
),
},
{
'any_name': '[domain.com/5type]',
'error_msg': (
"2:21 : ' [domain.com/5type] {': "
'Expected type name, got "5type".'
),
},
{
'any_name': '[domain.com/!]',
'error_msg': (
'2:17 : \' [domain.com/!] {\': Expected type name, got "!".'
),
},
{
'any_name': '[domain.com/my_?_type]',
'error_msg': '2:17 : \' [domain.com/my_?_type] {\': Expected "]".',
},
{
'any_name': '[domain.com/my.:type]',
'error_msg': '2:17 : \' [domain.com/my.:type] {\': Expected "]".',
},
{
'any_name': '[domain.com/my.type@]',
'error_msg': '2:21 : \' [domain.com/my.type@] {\': Expected "]".',
},
)
def testMergeFailsOnInvalidExpandedAnyTypeUrls(self, *, any_name, error_msg):
message = any_test_pb2.TestAny()
text = 'any_value {\n %s {\n data: "string"\n }\n }' % any_name

with self.assertRaises(text_format.ParseError) as e:
text_format.Merge(text, message)
self.assertIn(error_msg, str(e.exception))

def testMergeExpandedAnyDescriptorPoolMissingType(self):
message = any_test_pb2.TestAny()


+ 8
- 4
python/google/protobuf/proto_api.cc View File

@@ -46,7 +46,8 @@ PythonMessageMutator::~PythonMessageMutator() {
// check.
if (!PyErr_Occurred() && owned_msg_ != nullptr) {
std::string wire;
message_->SerializePartialToString(&wire);
// TODO: Remove this suppression.
(void)message_->SerializePartialToString(&wire);
PyObject* py_wire = PyBytes_FromStringAndSize(
wire.data(), static_cast<Py_ssize_t>(wire.size()));
PyObject* parse =
@@ -113,20 +114,23 @@ bool PythonConstMessagePointer::NotChanged() {
// serialize result may still diff between languages. So parse to
// another c++ message for compare.
std::unique_ptr<google::protobuf::Message> parsed_msg(owned_msg_->New());
parsed_msg->ParsePartialFromString(
// TODO: Remove this suppression.
(void)parsed_msg->ParsePartialFromString(
absl::string_view(data, static_cast<int>(len)));
std::string wire_other;
google::protobuf::io::StringOutputStream stream_other(&wire_other);
google::protobuf::io::CodedOutputStream output_other(&stream_other);
output_other.SetSerializationDeterministic(true);
parsed_msg->SerializePartialToCodedStream(&output_other);
// TODO: Remove this suppression.
(void)parsed_msg->SerializePartialToCodedStream(&output_other);
output_other.Trim();

std::string wire;
google::protobuf::io::StringOutputStream stream(&wire);
google::protobuf::io::CodedOutputStream output(&stream);
output.SetSerializationDeterministic(true);
owned_msg_->SerializePartialToCodedStream(&output);
// TODO: Remove this suppression.
(void)owned_msg_->SerializePartialToCodedStream(&output);
output.Trim();

if (wire == wire_other) {


+ 4
- 2
python/google/protobuf/pyext/descriptor.cc View File

@@ -228,7 +228,8 @@ bool Reparse(PyMessageFactory* message_factory, const Message& from,
Message* to) {
// Reparse message.
std::string serialized;
from.SerializeToString(&serialized);
// TODO: Remove this suppression.
(void)from.SerializeToString(&serialized);
io::CodedInputStream input(
reinterpret_cast<const uint8_t*>(serialized.c_str()), serialized.size());
input.SetExtensionRegistry(message_factory->pool->pool,
@@ -1490,7 +1491,8 @@ static PyObject* GetSerializedPb(PyFileDescriptor* self, void* closure) {
FileDescriptorProto file_proto;
_GetDescriptor(self)->CopyTo(&file_proto);
std::string contents;
file_proto.SerializePartialToString(&contents);
// TODO: Remove this suppression.
(void)file_proto.SerializePartialToString(&contents);
self->serialized_pb = PyBytes_FromStringAndSize(
contents.c_str(), static_cast<size_t>(contents.size()));
if (self->serialized_pb == nullptr) {


+ 4
- 2
python/google/protobuf/pyext/message_module.cc View File

@@ -285,8 +285,10 @@ absl::StatusOr<google::protobuf::Message*> CreateNewMessage(PyObject* py_msg) {
bool CopyToOwnedMsg(google::protobuf::Message** copy, const google::protobuf::Message& message) {
*copy = message.New();
std::string wire;
message.SerializePartialToString(&wire);
(*copy)->ParsePartialFromString(wire);
// TODO: Remove this suppression.
(void)message.SerializePartialToString(&wire);
// TODO: Remove this suppression.
(void)(*copy)->ParsePartialFromString(wire);
return true;
}



+ 109
- 27
python/google/protobuf/text_format.py View File

@@ -44,6 +44,8 @@ _INTEGER_CHECKERS = (type_checkers.Uint32ValueChecker(),
_FLOAT_INFINITY = re.compile('-?inf(?:inity)?f?$', re.IGNORECASE)
_FLOAT_NAN = re.compile('nanf?$', re.IGNORECASE)
_FLOAT_OCTAL_PREFIX = re.compile('-?0[0-9]+')
_PERCENT_ENCODING = re.compile(r'^%[\da-fA-F][\da-fA-F]$')
_TYPE_NAME = re.compile(r'^[^\d\W]\w*(\.[^\d\W]\w*)*$')
_QUOTES = frozenset(("'", '"'))
_ANY_FULL_TYPE_NAME = 'google.protobuf.Any'
_DEBUG_STRING_SILENT_MARKER = '\t '
@@ -322,8 +324,10 @@ def _BuildMessageFromTypeName(type_name, descriptor_pool):
# pylint: disable=g-import-not-at-top
if descriptor_pool is None:
from google.protobuf import descriptor_pool as pool_mod

descriptor_pool = pool_mod.Default()
from google.protobuf import message_factory

try:
message_descriptor = descriptor_pool.FindMessageTypeByName(type_name)
except KeyError:
@@ -850,10 +854,12 @@ class _Parser(object):
if (message_descriptor.full_name == _ANY_FULL_TYPE_NAME and
tokenizer.TryConsume('[')):
type_url_prefix, packed_type_name = self._ConsumeAnyTypeUrl(tokenizer)
tokenizer.Consume(']')
tokenizer.TryConsume(':')
self._DetectSilentMarker(tokenizer, message_descriptor.full_name,
type_url_prefix + '/' + packed_type_name)
self._DetectSilentMarker(
tokenizer,
message_descriptor.full_name,
type_url_prefix + '/' + packed_type_name,
)
if tokenizer.TryConsume('<'):
expanded_any_end_token = '>'
else:
@@ -874,9 +880,11 @@ class _Parser(object):
self._MergeField(tokenizer, expanded_any_sub_message)
deterministic = False

message.Pack(expanded_any_sub_message,
type_url_prefix=type_url_prefix,
deterministic=deterministic)
message.Pack(
expanded_any_sub_message,
type_url_prefix=type_url_prefix + '/',
deterministic=deterministic,
)
return

if tokenizer.TryConsume('['):
@@ -988,19 +996,59 @@ class _Parser(object):
self._LogSilentMarker(immediate_message_type, field_name)

def _ConsumeAnyTypeUrl(self, tokenizer):
"""Consumes a google.protobuf.Any type URL and returns the type name."""
# Consume "type.googleapis.com/".
prefix = [tokenizer.ConsumeIdentifier()]
tokenizer.Consume('.')
prefix.append(tokenizer.ConsumeIdentifier())
tokenizer.Consume('.')
prefix.append(tokenizer.ConsumeIdentifier())
tokenizer.Consume('/')
# Consume the fully-qualified type name.
name = [tokenizer.ConsumeIdentifier()]
while tokenizer.TryConsume('.'):
name.append(tokenizer.ConsumeIdentifier())
return '.'.join(prefix), '.'.join(name)
"""Consumes a google.protobuf.Any type URL.

Assumes the caller has already consumed the opening [ and consumes up to the
closing ].

Args:
tokenizer: A tokenizer to parse the type URL.

Returns:
A tuple of type URL prefix (without trailing slash) and type name.
"""
# Consume all tokens with valid URL characters until ]. Whitespace and
# comments are ignored/skipped by the Tokenizer.
tokens = []
last_slash = -1
while True:
try:
tokens.append(tokenizer.ConsumeUrlChars())
continue
except ParseError:
pass
if tokenizer.TryConsume('/'):
last_slash = len(tokens)
tokens.append('/')
else:
tokenizer.Consume(']')
break

if last_slash == -1:
raise tokenizer.ParseError('Type URL does not contain "/".')

prefix = ''.join(tokens[:last_slash])
name = ''.join(tokens[last_slash + 1 :])

if not prefix:
raise tokenizer.ParseError('Type URL prefix is empty.')
if prefix.startswith('/'):
raise tokenizer.ParseError('Type URL prefix starts with "/".')

# Check for invalid percent encodings. '%' needs to be followed by exactly
# two valid hexadecimal digits.
for i, char in enumerate(prefix):
if char == '%' and not _PERCENT_ENCODING.match(prefix[i : i + 3]):
raise tokenizer.ParseError(
f'Invalid percent escape, got "{prefix[i : i + 3]}".'
)

# After the last slash we expect a valid type name, not just any sequence of
# URL characters.
if not _TYPE_NAME.match(name):
raise tokenizer.ParseError('Expected type name, got "%s".' % name)

return prefix, name

def _MergeMessageField(self, tokenizer, message, field):
"""Merges a single scalar field into a message.
@@ -1261,17 +1309,26 @@ class Tokenizer(object):
_WHITESPACE = re.compile(r'\s+')
_COMMENT = re.compile(r'(\s*#.*$)', re.MULTILINE)
_WHITESPACE_OR_COMMENT = re.compile(r'(\s|(#.*$))+', re.MULTILINE)
_TOKEN = re.compile('|'.join([
r'[a-zA-Z_][0-9a-zA-Z_+-]*', # an identifier
r'([0-9+-]|(\.[0-9]))[0-9a-zA-Z_.+-]*', # a number
] + [ # quoted str for each quote mark
# Avoid backtracking! https://stackoverflow.com/a/844267
r'{qt}[^{qt}\n\\]*((\\.)+[^{qt}\n\\]*)*({qt}|\\?$)'.format(qt=mark)
for mark in _QUOTES
]))
_TOKEN = re.compile(
'|'.join(
[
r'[a-zA-Z_][0-9a-zA-Z_+-]*', # an identifier
r'([0-9+-]|(\.[0-9]))[0-9a-zA-Z_.+-]*', # a number
]
+ [ # quoted str for each quote mark
# Avoid backtracking! https://stackoverflow.com/a/844267
r'{qt}[^{qt}\n\\]*((\\.)+[^{qt}\n\\]*)*({qt}|\\?$)'.format(
qt=mark
)
for mark in _QUOTES
]
)
)

_IDENTIFIER = re.compile(r'[^\d\W]\w*')
_IDENTIFIER_OR_NUMBER = re.compile(r'\w+')
# Accepted URL characters (excluding "/")
_URL_CHARS = re.compile(r'^[0-9a-zA-Z-.~_ !$&()*+,;=%]+$')

def __init__(self, lines, skip_comments=True):
self._position = 0
@@ -1551,6 +1608,31 @@ class Tokenizer(object):
self.NextToken()
return result

def ConsumeUrlChars(self):
"""Consumes a token containing valid URL characters.

Excludes '/' so that it can be treated specially as a delimiter.

Returns:
The next token containing one or more URL characters.

Raises:
ParseError: If the next token contains unaccepted URL characters.
"""
if not self._URL_CHARS.match(self.token):
raise self.ParseError('Expected URL character(s), got "%s"' % self.token)

result = self.token
self.NextToken()
return result

def TryConsumeUrlChars(self):
try:
self.ConsumeUrlChars()
return True
except ParseError:
return False

def ParseErrorPreviousToken(self, message):
"""Creates and *returns* a ParseError for the previously read token.



+ 4
- 2
src/google/protobuf/compiler/csharp/csharp_field_base.cc View File

@@ -42,7 +42,8 @@ void FieldGeneratorBase::SetCommonFieldVariables(
}
uint tag = internal::WireFormat::MakeTag(descriptor_);
uint8_t tag_array[5];
io::CodedOutputStream::WriteTagToArray(tag, tag_array);
// TODO: Remove this suppression.
(void)io::CodedOutputStream::WriteTagToArray(tag, tag_array);
std::string tag_bytes = absl::StrCat(tag_array[0]);
for (int i = 1; i < part_tag_size; i++) {
absl::StrAppend(&tag_bytes, ", ", tag_array[i]);
@@ -56,7 +57,8 @@ void FieldGeneratorBase::SetCommonFieldVariables(
tag = internal::WireFormatLite::MakeTag(
descriptor_->number(),
internal::WireFormatLite::WIRETYPE_END_GROUP);
io::CodedOutputStream::WriteTagToArray(tag, tag_array);
// TODO: Remove this suppression.
(void)io::CodedOutputStream::WriteTagToArray(tag, tag_array);
tag_bytes = absl::StrCat(tag_array[0]);
for (int i = 1; i < part_tag_size; i++) {
absl::StrAppend(&tag_bytes, ", ", tag_array[i]);


+ 23
- 0
src/google/protobuf/extension_set.h View File

@@ -639,6 +639,14 @@ class PROTOBUF_EXPORT ExtensionSet {
return extension != nullptr && extension->is_lazy;
}

// Returns a pointer to the LazyField for the given extension number, or
// nullptr if the extension is not lazy.
// If the extension does not exist, it is created as a lazy extension.
// This function returns nullptr if lazy parsing is not supported, if the
// extension exists but is not lazy, or if the extension is not a message
// type.
LazyField* TryGetLazyField(Arena* arena, int number, FieldType type);

private:
template <typename Type>
friend class PrimitiveTypeTraits;
@@ -742,6 +750,8 @@ class PROTOBUF_EXPORT ExtensionSet {
io::EpsCopyOutputStream* stream) const = 0;


virtual LazyField* GetUnderlyingField() = 0;

private:
virtual void UnusedKeyMethod(); // Dummy key method to avoid weak vtable.
};
@@ -1868,6 +1878,19 @@ class ExtensionIdentifier {
typename TypeTraits::InitType default_value_;
};

template <typename ExtendeeType, typename TypeTraitsType,
internal::FieldType field_type, bool is_packed>
auto TryGetLazyMessageFromExtensionSet(
Arena* arena,
const google::protobuf::internal::ExtensionIdentifier<
ExtendeeType, TypeTraitsType, field_type, is_packed>& extension,
ExtensionSet& set) {
static_assert(std::is_base_of_v<
MessageLite,
std::decay_t<typename TypeTraitsType::Singular::ConstType>>);
return set.TryGetLazyField(arena, extension.number(), field_type);
}

// -------------------------------------------------------------------
// Generated accessors



+ 1
- 0
src/google/protobuf/extension_set_unittest.cc View File

@@ -1808,6 +1808,7 @@ TEST(ExtensionSetTest, MoveExtensionWithDynamicDescriptor) {
}



TEST_P(FindExtensionTest,
FindExtensionInfoFromFieldNumber_FindExistingExtension) {
ExtensionInfo extension_info;


+ 2
- 0
src/google/protobuf/generated_message_reflection_unittest.cc View File

@@ -1432,7 +1432,9 @@ TEST(GeneratedMessageReflectionTest, ArenaReleaseOneofMessageTest) {

TEST(GeneratedMessageReflectionTest, UsageErrors) {
unittest::TestAllTypes message;
#ifndef NDEBUG
unittest::ForeignMessage foreign;
#endif
const Reflection* reflection = message.GetReflection();
const Descriptor* descriptor = message.GetDescriptor();



+ 13
- 0
src/google/protobuf/generated_message_util.h View File

@@ -401,6 +401,19 @@ constexpr absl::optional<uintptr_t> EncodePlacementArenaOffsets(
// message classes without making them public. This is useful for highly
// optimized code paths that need to access internals.
struct PrivateAccess {
template <typename T, int number>
static constexpr bool IsLazyField() {
constexpr auto l =
[](auto& msg) -> decltype(msg._lazy_internal_mutable(
std::integral_constant<int, number>{})) {};
return std::is_invocable_v<decltype(l), T&>;
}

template <int number, typename T>
static auto& MutableLazy(T& msg) {
return msg._lazy_internal_mutable(std::integral_constant<int, number>{});
}

template <typename T>
static auto& GetExtensionSet(T& msg) {
return msg._impl_._extensions_;


+ 10
- 5
src/google/protobuf/io/coded_stream.cc View File

@@ -214,7 +214,8 @@ bool CodedInputStream::SkipFallback(int count, int original_buffer_size) {
// We hit the limit. Skip up to it then fail.
if (bytes_until_limit > 0) {
total_bytes_read_ = closest_limit;
input_->Skip(bytes_until_limit);
// TODO: Remove this suppression.
(void)input_->Skip(bytes_until_limit);
}
return false;
}
@@ -337,7 +338,8 @@ bool CodedInputStream::ReadCord(absl::Cord* output, int size) {
const int available = closest_limit - total_bytes_read_;
if (ABSL_PREDICT_FALSE(size > available)) {
total_bytes_read_ = closest_limit;
input_->ReadCord(output, available);
// TODO: Remove this suppression.
(void)input_->ReadCord(output, available);
return false;
}
total_bytes_read_ += size;
@@ -359,7 +361,8 @@ bool CodedInputStream::ReadLittleEndian16Fallback(uint16_t* value) {
if (!ReadRaw(bytes, kSize)) return false;
ptr = bytes;
}
ReadLittleEndian16FromArray(ptr, value);
// TODO: Remove this suppression.
(void)ReadLittleEndian16FromArray(ptr, value);
return true;
}

@@ -377,7 +380,8 @@ bool CodedInputStream::ReadLittleEndian32Fallback(uint32_t* value) {
if (!ReadRaw(bytes, kSize)) return false;
ptr = bytes;
}
ReadLittleEndian32FromArray(ptr, value);
// TODO: Remove this suppression.
(void)ReadLittleEndian32FromArray(ptr, value);
return true;
}

@@ -395,7 +399,8 @@ bool CodedInputStream::ReadLittleEndian64Fallback(uint64_t* value) {
if (!ReadRaw(bytes, kSize)) return false;
ptr = bytes;
}
ReadLittleEndian64FromArray(ptr, value);
// TODO: Remove this suppression.
(void)ReadLittleEndian64FromArray(ptr, value);
return true;
}



+ 16
- 8
src/google/protobuf/io/coded_stream_unittest.cc View File

@@ -179,7 +179,8 @@ TEST_F(CodedStreamTest, EmptyInputBeforeEos) {
int count_;
} in;
CodedInputStream input(&in);
input.ReadTagNoLastTag();
// TODO: Remove this suppression.
(void)input.ReadTagNoLastTag();
EXPECT_TRUE(input.ConsumedEntireMessage());
}

@@ -200,7 +201,8 @@ TEST_P(VarintCases, ExpectTag) {
// Read one byte to force coded_input.Refill() to be called. Otherwise,
// ExpectTag() will return a false negative.
uint8_t dummy;
coded_input.ReadRaw(&dummy, 1);
// TODO: Remove this suppression.
(void)coded_input.ReadRaw(&dummy, 1);
EXPECT_EQ((uint)'\0', (uint)dummy);

uint32_t expected_value = static_cast<uint32_t>(kVarintCases_case.value);
@@ -831,7 +833,8 @@ TEST_P(BlockSizes, ReadStringReservesMemoryOnPushedLimit) {

{
CodedInputStream coded_input(&input);
coded_input.PushLimit(sizeof(buffer_));
// TODO: Remove this suppression.
(void)coded_input.PushLimit(sizeof(buffer_));

std::string str;
EXPECT_TRUE(coded_input.ReadString(&str, strlen(kRawBytes)));
@@ -876,7 +879,8 @@ TEST_F(CodedStreamTest, ReadStringNoReservationSizeIsNegative) {

{
CodedInputStream coded_input(&input);
coded_input.PushLimit(sizeof(buffer_));
// TODO: Remove this suppression.
(void)coded_input.PushLimit(sizeof(buffer_));

std::string str;
EXPECT_FALSE(coded_input.ReadString(&str, -1));
@@ -896,7 +900,8 @@ TEST_F(CodedStreamTest, ReadStringNoReservationSizeIsLarge) {

{
CodedInputStream coded_input(&input);
coded_input.PushLimit(sizeof(buffer_));
// TODO: Remove this suppression.
(void)coded_input.PushLimit(sizeof(buffer_));

std::string str;
EXPECT_FALSE(coded_input.ReadString(&str, 1 << 30));
@@ -913,7 +918,8 @@ TEST_F(CodedStreamTest, ReadStringNoReservationSizeIsOverTheLimit) {

{
CodedInputStream coded_input(&input);
coded_input.PushLimit(16);
// TODO: Remove this suppression.
(void)coded_input.PushLimit(16);

std::string str;
EXPECT_FALSE(coded_input.ReadString(&str, strlen(kRawBytes)));
@@ -954,7 +960,8 @@ TEST_F(CodedStreamTest,

{
CodedInputStream coded_input(&input);
coded_input.PushLimit(sizeof(buffer_));
// TODO: Remove this suppression.
(void)coded_input.PushLimit(sizeof(buffer_));
coded_input.SetTotalBytesLimit(16);

std::string str;
@@ -976,7 +983,8 @@ TEST_F(CodedStreamTest,

{
CodedInputStream coded_input(&input);
coded_input.PushLimit(16);
// TODO: Remove this suppression.
(void)coded_input.PushLimit(16);
coded_input.SetTotalBytesLimit(sizeof(buffer_));
EXPECT_EQ(sizeof(buffer_), coded_input.BytesUntilTotalBytesLimit());



+ 6
- 6
src/google/protobuf/io/test_zero_copy_stream_test.cc View File

@@ -62,8 +62,8 @@ TEST(TestZeroCopyInputStreamTest, NextChecksPreconditions) {
std::make_unique<TestZeroCopyInputStream>(std::vector<std::string>{});
const void* data;
int size;
EXPECT_DEATH(stream->Next(nullptr, &size), "data must not be null");
EXPECT_DEATH(stream->Next(&data, nullptr), "size must not be null");
EXPECT_DEATH((void)stream->Next(nullptr, &size), "data must not be null");
EXPECT_DEATH((void)stream->Next(&data, nullptr), "size must not be null");
}
#endif // GTEST_HAS_DEATH_TEST

@@ -119,7 +119,7 @@ TEST(TestZeroCopyInputStreamTest, BackUpChecksPreconditions) {
"The last call was not a successful Next\\(\\)");
EXPECT_THAT(CallNext(*stream), Optional(Eq("C")));
EXPECT_THAT(CallNext(*stream), Optional(Eq("D")));
stream->Skip(1);
(void)stream->Skip(1);
EXPECT_DEATH(stream->BackUp(0),
"The last call was not a successful Next\\(\\)");
EXPECT_THAT(CallNext(*stream), Optional(Eq("FG")));
@@ -168,7 +168,7 @@ TEST(TestZeroCopyInputStreamTest, SkipWorks) {
TEST(TestZeroCopyInputStreamTest, SkipChecksPreconditions) {
std::unique_ptr<ZeroCopyInputStream> stream =
std::make_unique<TestZeroCopyInputStream>(std::vector<std::string>{});
EXPECT_DEATH(stream->Skip(-1), "count must not be negative");
EXPECT_DEATH((void)stream->Skip(-1), "count must not be negative");
}
#endif // GTEST_HAS_DEATH_TEST

@@ -207,8 +207,8 @@ TEST(TestZeroCopyOutputStreamTest, NextChecksPreconditions) {
std::make_unique<TestZeroCopyOutputStream>(empty);
void* data;
int size;
EXPECT_DEATH(stream->Next(nullptr, &size), "data must not be null");
EXPECT_DEATH(stream->Next(&data, nullptr), "size must not be null");
EXPECT_DEATH((void)stream->Next(nullptr, &size), "data must not be null");
EXPECT_DEATH((void)stream->Next(&data, nullptr), "size must not be null");
}
#endif // GTEST_HAS_DEATH_TEST



+ 4
- 2
src/google/protobuf/io/zero_copy_stream_impl_lite.cc View File

@@ -443,7 +443,8 @@ void LimitingInputStream::BackUp(int count) {
bool LimitingInputStream::Skip(int count) {
if (count > limit_) {
if (limit_ < 0) return false;
input_->Skip(limit_);
// TODO: Remove this suppression.
(void)input_->Skip(limit_);
limit_ = 0;
return false;
} else {
@@ -468,7 +469,8 @@ bool LimitingInputStream::ReadCord(absl::Cord* cord, int count) {
limit_ -= count;
return true;
}
input_->ReadCord(cord, limit_);
// TODO: Remove this suppression.
(void)input_->ReadCord(cord, limit_);
limit_ = 0;
return false;
}


+ 4
- 2
src/google/protobuf/json/internal/untyped_message.cc View File

@@ -256,7 +256,8 @@ absl::Status UntypedMessage::Decode(io::CodedInputStream& stream,
if (!stream.ReadVarint32(&x)) {
return MakeUnexpectedEofError();
}
stream.Skip(x);
// TODO: Remove this suppression.
(void)stream.Skip(x);
continue;
}
case WireFormatLite::WIRETYPE_START_GROUP: {
@@ -516,7 +517,8 @@ absl::Status UntypedMessage::DecodeDelimited(io::CodedInputStream& stream,
break;
}
}
stream.DecrementRecursionDepthAndPopLimit(limit);
// TODO: Remove this suppression.
(void)stream.DecrementRecursionDepthAndPopLimit(limit);
return absl::OkStatus();
}



+ 3
- 2
src/google/protobuf/lite_unittest.cc View File

@@ -1399,8 +1399,9 @@ TEST(LiteTest, DynamicCastMessageInvalidReferenceType) {
CastType1 test_type_1;
const MessageLite& test_type_1_pointer_const_ref = test_type_1;
#if defined(ABSL_HAVE_EXCEPTIONS)
EXPECT_THROW(DynamicCastMessage<CastType2>(test_type_1_pointer_const_ref),
std::bad_cast);
EXPECT_THROW(
(void)DynamicCastMessage<CastType2>(test_type_1_pointer_const_ref),
std::bad_cast);
#elif defined(GTEST_HAS_DEATH_TEST)
ASSERT_DEATH(
(void)DynamicCastMessage<CastType2>(test_type_1_pointer_const_ref),


+ 8
- 4
src/google/protobuf/message_lite.cc View File

@@ -289,7 +289,8 @@ class ZeroCopyCodedInputStream : public io::ZeroCopyInputStream {
explicit ZeroCopyCodedInputStream(io::CodedInputStream* cis) : cis_(cis) {}
bool Next(const void** data, int* size) final {
if (!cis_->GetDirectBufferPointer(data, size)) return false;
cis_->Skip(*size);
// TODO: Remove this suppression.
(void)cis_->Skip(*size);
return true;
}
void BackUp(int count) final { cis_->Advance(-count); }
@@ -479,7 +480,8 @@ inline uint8_t* SerializeToArrayImpl(const MessageLite& msg, uint8_t* target,
&stream, io::CodedOutputStream::IsDefaultSerializationDeterministic(),
&ptr);
ptr = msg._InternalSerialize(ptr, &out);
out.Trim(ptr);
// TODO: Remove this suppression.
(void)out.Trim(ptr);
ABSL_DCHECK(!out.HadError() && stream.ByteCount() == size);
return target + size;
} else {
@@ -549,7 +551,8 @@ bool MessageLite::SerializePartialToZeroCopyStream(
output, io::CodedOutputStream::IsDefaultSerializationDeterministic(),
&target);
target = _InternalSerialize(target, &stream);
stream.Trim(target);
// TODO: Remove this suppression.
(void)stream.Trim(target);
if (stream.HadError()) return false;
return true;
}
@@ -690,7 +693,8 @@ bool MessageLite::AppendPartialToString(absl::Cord* output) const {
target, static_cast<int>(available.size()), &output_stream,
io::CodedOutputStream::IsDefaultSerializationDeterministic(), &target);
target = _InternalSerialize(target, &out);
out.Trim(target);
// TODO: Remove this suppression.
(void)out.Trim(target);
if (out.HadError()) return false;
*output = output_stream.Consume();
ABSL_DCHECK_EQ(output->size(), total_size);


+ 1
- 1
src/google/protobuf/message_unittest.inc View File

@@ -861,7 +861,7 @@ TEST(MESSAGE_TEST_NAME, DynamicCastMessageInvalidReferenceType) {
UNITTEST::TestAllTypes test_all_types;
const MessageLite& test_all_types_pointer_const_ref = test_all_types;
#if defined(ABSL_HAVE_EXCEPTIONS)
EXPECT_THROW(DynamicCastMessage<UNITTEST::TestRequired>(
EXPECT_THROW((void)DynamicCastMessage<UNITTEST::TestRequired>(
test_all_types_pointer_const_ref),
std::bad_cast);
#else


+ 3
- 0
src/google/protobuf/no_field_presence_test.cc View File

@@ -312,6 +312,7 @@ TEST(NoFieldPresenceTest, CopyTwiceDefaultStringFieldTest) {

dst = src;
dst = src;
(void)dst;
}

TEST(NoFieldPresenceTest, CopyTwiceAllocatedStringFieldTest) {
@@ -325,6 +326,7 @@ TEST(NoFieldPresenceTest, CopyTwiceAllocatedStringFieldTest) {

dst = src;
dst = src;
(void)dst;
}

TEST(NoFieldPresenceTest, CopyTwiceEmptyStringFieldTest) {
@@ -339,6 +341,7 @@ TEST(NoFieldPresenceTest, CopyTwiceEmptyStringFieldTest) {

dst = src;
dst = src;
(void)dst;
}

class NoFieldPresenceSwapFieldTest : public testing::Test {


+ 4
- 2
src/google/protobuf/parse_context.cc View File

@@ -698,7 +698,8 @@ class UnknownFieldLiteParserHelper {
if (unknown_ == nullptr) return;
WriteVarint(num * 8 + 1, unknown_);
char buffer[8];
io::CodedOutputStream::WriteLittleEndian64ToArray(
// TODO: Remove this suppression.
(void)io::CodedOutputStream::WriteLittleEndian64ToArray(
value, reinterpret_cast<uint8_t*>(buffer));
unknown_->append(buffer, 8);
}
@@ -724,7 +725,8 @@ class UnknownFieldLiteParserHelper {
if (unknown_ == nullptr) return;
WriteVarint(num * 8 + 5, unknown_);
char buffer[4];
io::CodedOutputStream::WriteLittleEndian32ToArray(
// TODO: Remove this suppression.
(void)io::CodedOutputStream::WriteLittleEndian32ToArray(
value, reinterpret_cast<uint8_t*>(buffer));
unknown_->append(buffer, 4);
}


+ 6
- 5
src/google/protobuf/proto3_arena_unittest.cc View File

@@ -162,12 +162,13 @@ TEST(Proto3ArenaTest, GetArenaWithUnknown) {

// Tests arena-allocated message and submessages.
auto* arena_message1 = Arena::Create<TestAllTypes>(&arena);
arena_message1->GetReflection()->MutableUnknownFields(arena_message1);
(void)arena_message1->GetReflection()->MutableUnknownFields(arena_message1);
auto* arena_submessage1 = arena_message1->mutable_optional_foreign_message();
arena_submessage1->GetReflection()->MutableUnknownFields(arena_submessage1);
(void)arena_submessage1->GetReflection()->MutableUnknownFields(
arena_submessage1);
auto* arena_repeated_submessage1 =
arena_message1->add_repeated_foreign_message();
arena_repeated_submessage1->GetReflection()->MutableUnknownFields(
(void)arena_repeated_submessage1->GetReflection()->MutableUnknownFields(
arena_repeated_submessage1);
EXPECT_EQ(&arena, arena_message1->GetArena());
EXPECT_EQ(&arena, arena_submessage1->GetArena());
@@ -179,10 +180,10 @@ TEST(Proto3ArenaTest, GetArenaWithUnknown) {
arena_message2->mutable_repeated_foreign_message()->AddAllocated(
new ForeignMessage());
auto* submessage2 = arena_message2->mutable_optional_foreign_message();
submessage2->GetReflection()->MutableUnknownFields(submessage2);
(void)submessage2->GetReflection()->MutableUnknownFields(submessage2);
auto* repeated_submessage2 =
arena_message2->mutable_repeated_foreign_message(0);
repeated_submessage2->GetReflection()->MutableUnknownFields(
(void)repeated_submessage2->GetReflection()->MutableUnknownFields(
repeated_submessage2);
EXPECT_EQ(nullptr, submessage2->GetArena());
EXPECT_EQ(nullptr, repeated_submessage2->GetArena());


+ 2
- 2
src/google/protobuf/wire_format_unittest.h View File

@@ -779,7 +779,7 @@ TYPED_TEST_P(WireFormatTest, ParseMessageSetWithDeepRecReverseOrder) {
m->set_i(i);
mset = m->mutable_recursive();
}
message_set.ByteSizeLong();
EXPECT_GT(message_set.ByteSizeLong(), 0);
// Serialize with reverse payload tag order
io::StringOutputStream output_stream(&data);
io::CodedOutputStream coded_output(&output_stream);
@@ -834,7 +834,7 @@ TYPED_TEST_P(WireFormatTest, ParseFailMalformedMessageSetReverseOrder) {
// SerializeReverseOrder() assumes "recursive" is always present.
m->mutable_recursive();

message_set.ByteSizeLong();
EXPECT_GT(message_set.ByteSizeLong(), 0);

// Serialize with reverse payload tag order
io::StringOutputStream output_stream(&data);


+ 2
- 2
upb/util/def_to_proto_test.cc View File

@@ -39,7 +39,7 @@ const google::protobuf::Descriptor* AddMessageDescriptor(upb::MessageDefPtr msgd
const char* buf =
google_protobuf_FileDescriptorProto_serialize(upb_proto, tmp_arena.ptr(), &size);
google::protobuf::FileDescriptorProto google_proto;
google_proto.ParseFromString(absl::string_view(buf, size));
EXPECT_TRUE(google_proto.ParseFromString(absl::string_view(buf, size)));
const google::protobuf::FileDescriptor* file_desc = pool->BuildFile(google_proto);
EXPECT_TRUE(file_desc != nullptr);
return pool->FindMessageTypeByName(msgdef.full_name());
@@ -60,7 +60,7 @@ std::unique_ptr<google::protobuf::Message> ToProto(const upb_Message* msg,
upb_EncodeStatus status = upb_Encode(msg, upb_MessageDef_MiniTable(msgdef), 0,
arena.ptr(), &buf, &size);
EXPECT_EQ(status, kUpb_EncodeStatus_Ok);
google_msg->ParseFromString(absl::string_view(buf, size));
EXPECT_TRUE(google_msg->ParseFromString(absl::string_view(buf, size)));
return google_msg;
}



+ 2
- 2
upb/util/def_to_proto_test.h View File

@@ -65,7 +65,7 @@ static void AddFile(google::protobuf::FileDescriptorProto& file, upb::DefPool* p
google::protobuf::FileDescriptorProto normalized_file;
file_desc->CopyTo(&normalized_file);
std::string serialized;
normalized_file.SerializeToString(&serialized);
(void)normalized_file.SerializeToString(&serialized);
upb::Arena arena;
upb::Status status;
google_protobuf_FileDescriptorProto* proto = google_protobuf_FileDescriptorProto_parse(
@@ -100,7 +100,7 @@ static void AddFile(google::protobuf::FileDescriptorProto& file, upb::DefPool* p
// it may or may not be accepted, since upb does not perform as much
// validation as proto2. However it must not crash.
std::string serialized;
file.SerializeToString(&serialized);
(void)file.SerializeToString(&serialized);
upb::Arena arena;
upb::Status status;
google_protobuf_FileDescriptorProto* proto = google_protobuf_FileDescriptorProto_parse(


Loading…
Cancel
Save
Baidu
map