PROTOBUF_SYNC_PIPER
pull/8902/head
Adam Cozzette 4 years ago
parent 4eed0dab5a
commit f78fefc1ff
  1. 4
      CHANGES.txt
  2. 44
      java/core/src/main/java/com/google/protobuf/CodedInputStream.java
  3. 8
      java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java
  4. 15
      java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java
  5. 24
      java/util/src/test/java/com/google/protobuf/util/FieldMaskUtilTest.java
  6. 1
      protobuf_version.bzl
  7. 4
      src/google/protobuf/any.cc
  8. 2
      src/google/protobuf/any.pb.cc
  9. 6
      src/google/protobuf/api.pb.cc
  10. 2
      src/google/protobuf/arena_unittest.cc
  11. 14
      src/google/protobuf/arenastring.h
  12. 2
      src/google/protobuf/compiler/cpp/cpp_message.cc
  13. 5
      src/google/protobuf/compiler/java/java_string_field.cc
  14. 7
      src/google/protobuf/compiler/parser.cc
  15. 8
      src/google/protobuf/compiler/plugin.pb.cc
  16. 50
      src/google/protobuf/descriptor.cc
  17. 36
      src/google/protobuf/descriptor.h
  18. 54
      src/google/protobuf/descriptor.pb.cc
  19. 16
      src/google/protobuf/descriptor_database.cc
  20. 6
      src/google/protobuf/descriptor_database.h
  21. 7
      src/google/protobuf/descriptor_unittest.cc
  22. 2
      src/google/protobuf/duration.pb.cc
  23. 18
      src/google/protobuf/dynamic_message.cc
  24. 32
      src/google/protobuf/dynamic_message_unittest.cc
  25. 119
      src/google/protobuf/extension_set.cc
  26. 57
      src/google/protobuf/extension_set.h
  27. 12
      src/google/protobuf/extension_set_heavy.cc
  28. 16
      src/google/protobuf/extension_set_unittest.cc
  29. 2
      src/google/protobuf/field_mask.pb.cc
  30. 28
      src/google/protobuf/generated_message_reflection.cc
  31. 76
      src/google/protobuf/generated_message_reflection_unittest.cc
  32. 4
      src/google/protobuf/generated_message_table_driven.cc
  33. 2
      src/google/protobuf/generated_message_table_driven_lite.cc
  34. 26
      src/google/protobuf/generated_message_table_driven_lite.h
  35. 8
      src/google/protobuf/generated_message_util.cc
  36. 4
      src/google/protobuf/implicit_weak_message.h
  37. 10
      src/google/protobuf/inlined_string_field.h
  38. 2
      src/google/protobuf/io/coded_stream.cc
  39. 3
      src/google/protobuf/io/coded_stream.h
  40. 53
      src/google/protobuf/io/tokenizer.cc
  41. 27
      src/google/protobuf/io/tokenizer.h
  42. 114
      src/google/protobuf/io/tokenizer_unittest.cc
  43. 2
      src/google/protobuf/map_entry_lite.h
  44. 10
      src/google/protobuf/map_field.cc
  45. 8
      src/google/protobuf/map_field.h
  46. 8
      src/google/protobuf/map_field_inl.h
  47. 6
      src/google/protobuf/map_field_lite.h
  48. 4
      src/google/protobuf/map_field_test.cc
  49. 8
      src/google/protobuf/map_test.inc
  50. 6
      src/google/protobuf/map_type_handler.h
  51. 14
      src/google/protobuf/message.cc
  52. 2
      src/google/protobuf/message_lite.cc
  53. 4
      src/google/protobuf/message_lite.h
  54. 4
      src/google/protobuf/message_unittest.inc
  55. 2
      src/google/protobuf/metadata_lite.h
  56. 2
      src/google/protobuf/port_def.inc
  57. 2
      src/google/protobuf/preserve_unknown_enum_test.cc
  58. 12
      src/google/protobuf/reflection.h
  59. 28
      src/google/protobuf/repeated_field.cc
  60. 89
      src/google/protobuf/repeated_field.h
  61. 4
      src/google/protobuf/repeated_field_reflection_unittest.cc
  62. 8
      src/google/protobuf/repeated_field_unittest.cc
  63. 2
      src/google/protobuf/source_context.pb.cc
  64. 6
      src/google/protobuf/struct.pb.cc
  65. 6
      src/google/protobuf/text_format.cc
  66. 11
      src/google/protobuf/text_format.h
  67. 10
      src/google/protobuf/text_format_unittest.cc
  68. 2
      src/google/protobuf/timestamp.pb.cc
  69. 10
      src/google/protobuf/type.pb.cc
  70. 20
      src/google/protobuf/unknown_field_set_unittest.cc
  71. 34
      src/google/protobuf/wire_format.cc
  72. 18
      src/google/protobuf/wire_format.h
  73. 15
      src/google/protobuf/wire_format_lite.cc
  74. 11
      src/google/protobuf/wire_format_lite.h
  75. 18
      src/google/protobuf/wrappers.pb.cc

@ -33,6 +33,10 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript)
* Replace toArray implementation with toJSON.
2021-06-04 version 3.17.3 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript)
Python
* Note: This is the last release to support Python 2.7. Future releases will
require Python >= 3.5.
C++
* Introduce FieldAccessListener.
* Stop emitting boilerplate {Copy/Merge}From in each ProtoBuf class

@ -87,7 +87,7 @@ public abstract class CodedInputStream {
throw new IllegalArgumentException("bufferSize must be > 0");
}
if (input == null) {
// TODO(nathanmittler): Ideally we should throw here. This is done for backward compatibility.
// Ideally we would throw here. This is done for backward compatibility.
return newInstance(EMPTY_BYTE_ARRAY);
}
return new StreamDecoder(input, bufferSize);
@ -1146,7 +1146,7 @@ public abstract class CodedInputStream {
final byte[] buffer = this.buffer;
pos = tempPos + FIXED32_SIZE;
return (((buffer[tempPos] & 0xff))
return ((buffer[tempPos] & 0xff)
| ((buffer[tempPos + 1] & 0xff) << 8)
| ((buffer[tempPos + 2] & 0xff) << 16)
| ((buffer[tempPos + 3] & 0xff) << 24));
@ -1162,7 +1162,7 @@ public abstract class CodedInputStream {
final byte[] buffer = this.buffer;
pos = tempPos + FIXED64_SIZE;
return (((buffer[tempPos] & 0xffL))
return ((buffer[tempPos] & 0xffL)
| ((buffer[tempPos + 1] & 0xffL) << 8)
| ((buffer[tempPos + 2] & 0xffL) << 16)
| ((buffer[tempPos + 3] & 0xffL) << 24)
@ -1871,7 +1871,7 @@ public abstract class CodedInputStream {
}
pos = tempPos + FIXED32_SIZE;
return (((UnsafeUtil.getByte(tempPos) & 0xff))
return ((UnsafeUtil.getByte(tempPos) & 0xff)
| ((UnsafeUtil.getByte(tempPos + 1) & 0xff) << 8)
| ((UnsafeUtil.getByte(tempPos + 2) & 0xff) << 16)
| ((UnsafeUtil.getByte(tempPos + 3) & 0xff) << 24));
@ -1886,7 +1886,7 @@ public abstract class CodedInputStream {
}
pos = tempPos + FIXED64_SIZE;
return (((UnsafeUtil.getByte(tempPos) & 0xffL))
return ((UnsafeUtil.getByte(tempPos) & 0xffL)
| ((UnsafeUtil.getByte(tempPos + 1) & 0xffL) << 8)
| ((UnsafeUtil.getByte(tempPos + 2) & 0xffL) << 16)
| ((UnsafeUtil.getByte(tempPos + 3) & 0xffL) << 24)
@ -2014,11 +2014,16 @@ public abstract class CodedInputStream {
int prevPos = buffer.position();
int prevLimit = buffer.limit();
try {
// Casts to Buffer here are required for Java 8 compatibility
// no matter what tricorder tells you. see
// https://issues.apache.org/jira/browse/MRESOLVER-85
((Buffer) buffer).position(bufferPos(begin));
((Buffer) buffer).limit(bufferPos(end));
return buffer.slice();
} catch (IllegalArgumentException e) {
throw InvalidProtocolBufferException.truncatedMessage();
InvalidProtocolBufferException ex = InvalidProtocolBufferException.truncatedMessage();
ex.initCause(e);
throw ex;
} finally {
((Buffer) buffer).position(prevPos);
((Buffer) buffer).limit(prevLimit);
@ -2660,7 +2665,7 @@ public abstract class CodedInputStream {
final byte[] buffer = this.buffer;
pos = tempPos + FIXED32_SIZE;
return (((buffer[tempPos] & 0xff))
return ((buffer[tempPos] & 0xff)
| ((buffer[tempPos + 1] & 0xff) << 8)
| ((buffer[tempPos + 2] & 0xff) << 16)
| ((buffer[tempPos + 3] & 0xff) << 24));
@ -2987,7 +2992,7 @@ public abstract class CodedInputStream {
// by allocating and reading only a small chunk at a time, so that the
// malicious message must actually *be* extremely large to cause
// problems. Meanwhile, we limit the allowed size of a message elsewhere.
final List<byte[]> chunks = new ArrayList<byte[]>();
final List<byte[]> chunks = new ArrayList<>();
while (sizeLeft > 0) {
// TODO(nathanmittler): Consider using a value larger than DEFAULT_BUFFER_SIZE.
@ -3134,16 +3139,16 @@ public abstract class CodedInputStream {
*/
private static final class IterableDirectByteBufferDecoder extends CodedInputStream {
/** The object that need to decode. */
private Iterable<ByteBuffer> input;
private final Iterable<ByteBuffer> input;
/** The {@link Iterator} with type {@link ByteBuffer} of {@code input} */
private Iterator<ByteBuffer> iterator;
private final Iterator<ByteBuffer> iterator;
/** The current ByteBuffer; */
private ByteBuffer currentByteBuffer;
/**
* If {@code true}, indicates that all the buffer are backing a {@link ByteString} and are
* If {@code true}, indicates that all the buffers are backing a {@link ByteString} and are
* therefore considered to be an immutable input source.
*/
private boolean immutable;
private final boolean immutable;
/**
* If {@code true}, indicates that calls to read {@link ByteString} or {@code byte[]}
* <strong>may</strong> return slices of the underlying buffer, rather than copies.
@ -3516,8 +3521,7 @@ public abstract class CodedInputStream {
currentByteBufferPos += size;
return result;
} else {
byte[] bytes;
bytes = new byte[size];
byte[] bytes = new byte[size];
UnsafeUtil.copyMemory(currentByteBufferPos, bytes, 0, size);
currentByteBufferPos += size;
return ByteString.wrap(bytes);
@ -3738,7 +3742,7 @@ public abstract class CodedInputStream {
if (currentRemaining() >= FIXED32_SIZE) {
long tempPos = currentByteBufferPos;
currentByteBufferPos += FIXED32_SIZE;
return (((UnsafeUtil.getByte(tempPos) & 0xff))
return ((UnsafeUtil.getByte(tempPos) & 0xff)
| ((UnsafeUtil.getByte(tempPos + 1) & 0xff) << 8)
| ((UnsafeUtil.getByte(tempPos + 2) & 0xff) << 16)
| ((UnsafeUtil.getByte(tempPos + 3) & 0xff) << 24));
@ -3754,7 +3758,7 @@ public abstract class CodedInputStream {
if (currentRemaining() >= FIXED64_SIZE) {
long tempPos = currentByteBufferPos;
currentByteBufferPos += FIXED64_SIZE;
return (((UnsafeUtil.getByte(tempPos) & 0xffL))
return ((UnsafeUtil.getByte(tempPos) & 0xffL)
| ((UnsafeUtil.getByte(tempPos + 1) & 0xffL) << 8)
| ((UnsafeUtil.getByte(tempPos + 2) & 0xffL) << 16)
| ((UnsafeUtil.getByte(tempPos + 3) & 0xffL) << 24)
@ -3875,11 +3879,6 @@ public abstract class CodedInputStream {
* Try to get raw bytes from {@code input} with the size of {@code length} and copy to {@code
* bytes} array. If the size is bigger than the number of remaining bytes in the input, then
* throw {@code truncatedMessage} exception.
*
* @param bytes
* @param offset
* @param length
* @throws IOException
*/
private void readRawBytesTo(byte[] bytes, int offset, final int length) throws IOException {
if (length >= 0 && length <= remaining()) {
@ -3966,6 +3965,9 @@ public abstract class CodedInputStream {
int prevPos = currentByteBuffer.position();
int prevLimit = currentByteBuffer.limit();
try {
// casts to Buffer here are required for Java 8 compatibility
// no matter what tricorder tells you. see
// https://issues.apache.org/jira/browse/MRESOLVER-85
((Buffer) currentByteBuffer).position(begin);
((Buffer) currentByteBuffer).limit(end);
return currentByteBuffer.slice();

@ -3068,6 +3068,14 @@ public abstract class GeneratedMessageV3 extends AbstractMessage
return (Extension<MessageType, T>) extension;
}
protected static boolean isStringEmpty(final Object value) {
if (value instanceof String) {
return ((String) value).isEmpty();
} else {
return ((ByteString) value).isEmpty();
}
}
protected static int computeStringSize(final int fieldNumber, final Object value) {
if (value instanceof String) {
return CodedOutputStream.computeStringSize(fieldNumber, (String) value);

@ -400,19 +400,12 @@ public final class FieldMaskUtil {
}
/**
* Returns the result of merging the given proto with the given mask and a default instance.
*/
public static <P extends Message> P trim(FieldMask mask, P source) {
return trim(mask, source, new MergeOptions());
}
/**
* Returns the result of merging the given proto with the given mask and a default instance.
* Returns the result of keeping only the masked fields of the given proto.
*/
@SuppressWarnings("unchecked")
public static <P extends Message> P trim(FieldMask mask, P source, MergeOptions options) {
Message.Builder destination = source.newBuilderForType();
merge(mask, source, destination, options);
public static <P extends Message> P trim(FieldMask mask, P source) {
Message.Builder destination = source.newBuilderForType();
merge(mask, source, destination);
return (P) destination.build();
}
}

@ -288,4 +288,28 @@ public class FieldMaskUtilTest {
FieldMaskUtil.merge(FieldMaskUtil.fromString("payload"), source, builder);
assertThat(builder.getPayload().getOptionalInt32()).isEqualTo(1234);
}
@Test
public void testTrim() throws Exception {
NestedTestAllTypes source =
NestedTestAllTypes.newBuilder()
.setPayload(
TestAllTypes.newBuilder()
.setOptionalInt32(1234)
.setOptionalString("1234")
.setOptionalBool(true))
.build();
FieldMask mask =
FieldMaskUtil.fromStringList(
ImmutableList.of("payload.optional_int32", "payload.optional_string"));
NestedTestAllTypes actual = FieldMaskUtil.trim(mask, source);
assertThat(actual)
.isEqualTo(
NestedTestAllTypes.newBuilder()
.setPayload(
TestAllTypes.newBuilder().setOptionalInt32(1234).setOptionalString("1234"))
.build());
}
}

@ -0,0 +1 @@
PROTOBUF_VERSION = '3.17.3'

@ -70,9 +70,9 @@ bool GetAnyFieldDescriptors(const Message& message,
}
*type_url_field = descriptor->FindFieldByNumber(1);
*value_field = descriptor->FindFieldByNumber(2);
return (*type_url_field != NULL &&
return (*type_url_field != nullptr &&
(*type_url_field)->type() == FieldDescriptor::TYPE_STRING &&
*value_field != NULL &&
*value_field != nullptr &&
(*value_field)->type() == FieldDescriptor::TYPE_BYTES);
}

@ -124,7 +124,7 @@ Any::Any(const Any& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.Any)
}
void Any::SharedCtor() {
inline void Any::SharedCtor() {
type_url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
value_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}

@ -218,7 +218,7 @@ Api::Api(const Api& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.Api)
}
void Api::SharedCtor() {
inline void Api::SharedCtor() {
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
version_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
@ -631,7 +631,7 @@ Method::Method(const Method& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.Method)
}
void Method::SharedCtor() {
inline void Method::SharedCtor() {
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
request_type_url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
response_type_url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
@ -1022,7 +1022,7 @@ Mixin::Mixin(const Mixin& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.Mixin)
}
void Mixin::SharedCtor() {
inline void Mixin::SharedCtor() {
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
root_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}

@ -1151,7 +1151,7 @@ TEST(ArenaTest, RepeatedFieldOnArena) {
// Fill some repeated fields on the arena to test for leaks. Also verify no
// memory allocations.
RepeatedField<int32> repeated_int32(&arena);
RepeatedField<int32_t> repeated_int32(&arena);
RepeatedPtrField<TestAllTypes> repeated_message(&arena);
for (int i = 0; i < 100; i++) {
repeated_int32.Add(42);

@ -142,7 +142,7 @@ static_assert(std::is_trivial<TaggedPtr<std::string>>::value,
// free()/destructor-call list) as appropriate.
//
// - Pointer set to 'DonatedString' tag (LSB is 1): points to a std::string
// instance with a buffer on the arena (arena != NULL, always, in this case).
// instance with a buffer on the arena (arena is never nullptr in this case).
//
// For fields with a non-empty string default value, there are three distinct
// states:
@ -158,7 +158,7 @@ static_assert(std::is_trivial<TaggedPtr<std::string>>::value,
// free()/destructor-call list) as appropriate.
//
// - Pointer set to 'DonatedString' tag (LSB is 1): points to a std::string
// instance with a buffer on the arena (arena != NULL, always, in this case).
// instance with a buffer on the arena (arena is never nullptr in this case).
//
// Generated code and reflection code both ensure that ptr_ is never null for
// fields with an empty default.
@ -240,8 +240,8 @@ struct PROTOBUF_EXPORT ArenaStringPtr {
std::string* Mutable(const LazyString& default_value, ::google::protobuf::Arena* arena);
// Release returns a std::string* instance that is heap-allocated and is not
// Own()'d by any arena. If the field is not set, this returns NULL. The
// caller retains ownership. Clears this field back to NULL state. Used to
// Own()'d by any arena. If the field is not set, this returns nullptr. The
// caller retains ownership. Clears this field back to nullptr state. Used to
// implement release_<field>() methods on generated classes.
PROTOBUF_MUST_USE_RESULT std::string* Release(
const std::string* default_value, ::google::protobuf::Arena* arena);
@ -276,9 +276,9 @@ struct PROTOBUF_EXPORT ArenaStringPtr {
// string default.
void ClearNonDefaultToEmpty();
// Clears content, but keeps allocated std::string if arena != NULL, to avoid
// the overhead of heap operations. After this returns, the content (as seen
// by the user) will always be equal to |default_value|.
// Clears content, but keeps allocated std::string if arena != nullptr, to
// avoid the overhead of heap operations. After this returns, the content
// (as seen by the user) will always be equal to |default_value|.
void ClearToDefault(const LazyString& default_value, ::google::protobuf::Arena* arena);
// Called from generated code / reflection runtime only. Resets value to point

@ -2799,7 +2799,7 @@ void MessageGenerator::GenerateSharedConstructorCode(io::Printer* printer) {
if (HasSimpleBaseClass(descriptor_, options_)) return;
Formatter format(printer, variables_);
format("void $classname$::SharedCtor() {\n");
format("inline void $classname$::SharedCtor() {\n");
std::vector<bool> processed(optimized_order_.size(), false);
GenerateConstructorBody(printer, processed, false);

@ -80,6 +80,9 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
" if (value == null) {\n"
" throw new NullPointerException();\n"
" }\n";
(*variables)["isStringEmpty"] = "com.google.protobuf.GeneratedMessage" +
GeneratedCodeVersionSuffix() +
".isStringEmpty";
(*variables)["writeString"] = "com.google.protobuf.GeneratedMessage" +
GeneratedCodeVersionSuffix() + ".writeString";
(*variables)["computeStringSize"] = "com.google.protobuf.GeneratedMessage" +
@ -117,7 +120,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
(*variables)["clear_has_field_bit_builder"] = "";
(*variables)["is_field_present_message"] =
"!get" + (*variables)["capitalized_name"] + "Bytes().isEmpty()";
"!" + (*variables)["isStringEmpty"] + "(" + (*variables)["name"] + "_)";
}
// For repeated builders, one bit is used for whether the array is immutable.

@ -1518,6 +1518,13 @@ bool Parser::ParseOption(Message* options,
AddError("Unexpected end of stream while parsing option value.");
return false;
case io::Tokenizer::TYPE_WHITESPACE:
case io::Tokenizer::TYPE_NEWLINE:
GOOGLE_CHECK(!input_->report_whitespace() && !input_->report_newlines())
<< "Whitespace tokens were not requested.";
GOOGLE_LOG(FATAL) << "Tokenizer reported whitespace.";
return false;
case io::Tokenizer::TYPE_IDENTIFIER: {
value_location.AddPath(
UninterpretedOption::kIdentifierValueFieldNumber);

@ -258,7 +258,7 @@ Version::Version(const Version& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.Version)
}
void Version::SharedCtor() {
inline void Version::SharedCtor() {
suffix_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&major_) - reinterpret_cast<char*>(this)),
@ -581,7 +581,7 @@ CodeGeneratorRequest::CodeGeneratorRequest(const CodeGeneratorRequest& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.CodeGeneratorRequest)
}
void CodeGeneratorRequest::SharedCtor() {
inline void CodeGeneratorRequest::SharedCtor() {
parameter_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
compiler_version_ = nullptr;
}
@ -937,7 +937,7 @@ CodeGeneratorResponse_File::CodeGeneratorResponse_File(const CodeGeneratorRespon
// @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.CodeGeneratorResponse.File)
}
void CodeGeneratorResponse_File::SharedCtor() {
inline void CodeGeneratorResponse_File::SharedCtor() {
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
insertion_point_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
content_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
@ -1280,7 +1280,7 @@ CodeGeneratorResponse::CodeGeneratorResponse(const CodeGeneratorResponse& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.CodeGeneratorResponse)
}
void CodeGeneratorResponse::SharedCtor() {
inline void CodeGeneratorResponse::SharedCtor() {
error_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
supported_features_ = uint64_t{0u};
}

@ -2826,7 +2826,12 @@ bool RetrieveOptions(int depth, const Message& options,
DynamicMessageFactory factory;
std::unique_ptr<Message> dynamic_options(
factory.GetPrototype(option_descriptor)->New());
if (dynamic_options->ParseFromString(options.SerializeAsString())) {
std::string serialized = options.SerializeAsString();
io::CodedInputStream input(
reinterpret_cast<const uint8_t*>(serialized.c_str()),
serialized.size());
input.SetExtensionRegistry(pool, &factory);
if (dynamic_options->ParseFromCodedStream(&input)) {
return RetrieveOptionsAssumingRightPool(depth, *dynamic_options,
option_entries);
} else {
@ -5942,11 +5947,23 @@ void DescriptorBuilder::CrossLinkMessage(Descriptor* message,
}
// Must go through oneof_decls_ array to get a non-const version of the
// OneofDescriptor.
++message->oneof_decls_[oneof_decl->index()].field_count_;
auto& out_oneof_decl = message->oneof_decls_[oneof_decl->index()];
if (out_oneof_decl.field_count_ == 0) {
out_oneof_decl.fields_ = message->field(i);
}
if (!had_errors_) {
// Verify that they are contiguous.
// This is assumed by OneofDescriptor::field(i).
// But only if there are no errors.
GOOGLE_CHECK_EQ(out_oneof_decl.fields_ + out_oneof_decl.field_count_,
message->field(i));
}
++out_oneof_decl.field_count_;
}
}
// Then allocate the arrays.
// Then verify the sizes.
for (int i = 0; i < message->oneof_decl_count(); i++) {
OneofDescriptor* oneof_decl = &message->oneof_decls_[i];
@ -5956,27 +5973,11 @@ void DescriptorBuilder::CrossLinkMessage(Descriptor* message,
"Oneof must have at least one field.");
}
oneof_decl->fields_ = tables_->AllocateArray<const FieldDescriptor*>(
oneof_decl->field_count_);
oneof_decl->field_count_ = 0;
if (oneof_decl->options_ == nullptr) {
oneof_decl->options_ = &OneofOptions::default_instance();
}
}
// Then fill them in.
for (int i = 0; i < message->field_count(); i++) {
const OneofDescriptor* oneof_decl = message->field(i)->containing_oneof();
if (oneof_decl != nullptr) {
OneofDescriptor* mutable_oneof_decl =
&message->oneof_decls_[oneof_decl->index()];
message->fields_[i].index_in_oneof_ = mutable_oneof_decl->field_count_;
mutable_oneof_decl->fields_[mutable_oneof_decl->field_count_++] =
message->field(i);
}
}
for (int i = 0; i < message->field_count(); i++) {
const FieldDescriptor* field = message->field(i);
if (field->proto3_optional_) {
@ -6529,7 +6530,7 @@ void DescriptorBuilder::ValidateMessageOptions(Descriptor* message,
const int64_t max_extension_range =
static_cast<int64_t>(message->options().message_set_wire_format()
? kint32max
? std::numeric_limits<int32_t>::max()
: FieldDescriptor::kMaxNumber);
for (int i = 0; i < message->extension_range_count(); ++i) {
if (message->extension_range(i)->end > max_extension_range + 1) {
@ -7319,7 +7320,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue(
case FieldDescriptor::CPPTYPE_INT32:
if (uninterpreted_option_->has_positive_int_value()) {
if (uninterpreted_option_->positive_int_value() >
static_cast<uint64_t>(kint32max)) {
static_cast<uint64_t>(std::numeric_limits<int32_t>::max())) {
return AddValueError("Value out of range for int32 option \"" +
option_field->full_name() + "\".");
} else {
@ -7329,7 +7330,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue(
}
} else if (uninterpreted_option_->has_negative_int_value()) {
if (uninterpreted_option_->negative_int_value() <
static_cast<int64_t>(kint32min)) {
static_cast<int64_t>(std::numeric_limits<int32_t>::min())) {
return AddValueError("Value out of range for int32 option \"" +
option_field->full_name() + "\".");
} else {
@ -7346,7 +7347,7 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue(
case FieldDescriptor::CPPTYPE_INT64:
if (uninterpreted_option_->has_positive_int_value()) {
if (uninterpreted_option_->positive_int_value() >
static_cast<uint64_t>(kint64max)) {
static_cast<uint64_t>(std::numeric_limits<int64_t>::max())) {
return AddValueError("Value out of range for int64 option \"" +
option_field->full_name() + "\".");
} else {
@ -7366,7 +7367,8 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue(
case FieldDescriptor::CPPTYPE_UINT32:
if (uninterpreted_option_->has_positive_int_value()) {
if (uninterpreted_option_->positive_int_value() > kuint32max) {
if (uninterpreted_option_->positive_int_value() >
std::numeric_limits<uint32_t>::max()) {
return AddValueError("Value out of range for uint32 option \"" +
option_field->name() + "\".");
} else {

@ -905,19 +905,19 @@ class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase {
// Returns true if this is a map message type.
bool is_map_message_type() const;
bool has_default_value_;
bool proto3_optional_;
bool has_default_value_ : 1;
bool proto3_optional_ : 1;
// Whether the user has specified the json_name field option in the .proto
// file.
bool has_json_name_;
bool is_extension_;
bool has_json_name_ : 1;
bool is_extension_ : 1;
bool is_oneof_ : 1;
// Actually a `Type`, but stored as uint8_t to save space.
mutable uint8_t type_;
// Actually a `Label` but stored as uint8_t to save space.
uint8_t label_;
uint8_t label_ : 2;
bool is_oneof_ : 1;
// Actually a `Type`, but stored as uint8_t to save space.
mutable uint8_t type_;
// Logically:
// all_names_ = [name, full_name, lower, camel, json]
@ -929,14 +929,15 @@ class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase {
uint8_t lowercase_name_index_ : 2;
uint8_t camelcase_name_index_ : 2;
uint8_t json_name_index_ : 3;
// Sadly, `number_` located here to reduce padding. Unrelated to all_names_
// and its indices above.
int number_;
const std::string* all_names_;
const FileDescriptor* file_;
internal::LazyInitData* type_once_;
static void TypeOnceInit(const FieldDescriptor* to_init);
void InternalTypeOnceInit() const;
int number_;
int index_in_oneof_;
const Descriptor* containing_type_;
union {
const OneofDescriptor* containing_oneof;
@ -1048,8 +1049,8 @@ class PROTOBUF_EXPORT OneofDescriptor : private internal::SymbolBase {
// all_names_ = [name, full_name]
const std::string* all_names_;
const Descriptor* containing_type_;
const FieldDescriptor** fields_;
const OneofOptions* options_;
const FieldDescriptor* fields_;
// IMPORTANT: If you add a new field, make sure to search for all instances
// of Allocate<OneofDescriptor>() and AllocateArray<OneofDescriptor>()
@ -2096,7 +2097,6 @@ PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, file, const FileDescriptor*)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, number, int)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, is_extension, bool)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, containing_type, const Descriptor*)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, index_in_oneof, int)
PROTOBUF_DEFINE_OPTIONS_ACCESSOR(FieldDescriptor, FieldOptions)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, has_default_value, bool)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, has_json_name, bool)
@ -2112,6 +2112,7 @@ PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, default_value_string)
PROTOBUF_DEFINE_NAME_ACCESSOR(OneofDescriptor)
PROTOBUF_DEFINE_ACCESSOR(OneofDescriptor, containing_type, const Descriptor*)
PROTOBUF_DEFINE_ACCESSOR(OneofDescriptor, field_count, int)
PROTOBUF_DEFINE_ARRAY_ACCESSOR(OneofDescriptor, field, const FieldDescriptor*)
PROTOBUF_DEFINE_OPTIONS_ACCESSOR(OneofDescriptor, OneofOptions)
PROTOBUF_DEFINE_NAME_ACCESSOR(EnumDescriptor)
@ -2233,6 +2234,11 @@ inline const OneofDescriptor* FieldDescriptor::containing_oneof() const {
return is_oneof_ ? scope_.containing_oneof : nullptr;
}
inline int FieldDescriptor::index_in_oneof() const {
GOOGLE_DCHECK(is_oneof_);
return static_cast<int>(this - scope_.containing_oneof->field(0));
}
inline const Descriptor* FieldDescriptor::extension_scope() const {
GOOGLE_CHECK(is_extension_);
return scope_.extension_scope;
@ -2390,12 +2396,6 @@ inline FileDescriptor::Syntax FileDescriptor::syntax() const {
return static_cast<Syntax>(syntax_);
}
// Can't use PROTOBUF_DEFINE_ARRAY_ACCESSOR because fields_ is actually an array
// of pointers rather than the usual array of objects.
inline const FieldDescriptor* OneofDescriptor::field(int index) const {
return fields_[index];
}
} // namespace protobuf
} // namespace google

@ -1282,7 +1282,7 @@ FileDescriptorSet::FileDescriptorSet(const FileDescriptorSet& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.FileDescriptorSet)
}
void FileDescriptorSet::SharedCtor() {
inline void FileDescriptorSet::SharedCtor() {
}
FileDescriptorSet::~FileDescriptorSet() {
@ -1532,7 +1532,7 @@ FileDescriptorProto::FileDescriptorProto(const FileDescriptorProto& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.FileDescriptorProto)
}
void FileDescriptorProto::SharedCtor() {
inline void FileDescriptorProto::SharedCtor() {
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
package_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
syntax_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
@ -2159,7 +2159,7 @@ DescriptorProto_ExtensionRange::DescriptorProto_ExtensionRange(const DescriptorP
// @@protoc_insertion_point(copy_constructor:google.protobuf.DescriptorProto.ExtensionRange)
}
void DescriptorProto_ExtensionRange::SharedCtor() {
inline void DescriptorProto_ExtensionRange::SharedCtor() {
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&options_) - reinterpret_cast<char*>(this)),
0, static_cast<size_t>(reinterpret_cast<char*>(&end_) -
@ -2430,7 +2430,7 @@ DescriptorProto_ReservedRange::DescriptorProto_ReservedRange(const DescriptorPro
// @@protoc_insertion_point(copy_constructor:google.protobuf.DescriptorProto.ReservedRange)
}
void DescriptorProto_ReservedRange::SharedCtor() {
inline void DescriptorProto_ReservedRange::SharedCtor() {
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&start_) - reinterpret_cast<char*>(this)),
0, static_cast<size_t>(reinterpret_cast<char*>(&end_) -
@ -2695,7 +2695,7 @@ DescriptorProto::DescriptorProto(const DescriptorProto& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.DescriptorProto)
}
void DescriptorProto::SharedCtor() {
inline void DescriptorProto::SharedCtor() {
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
options_ = nullptr;
}
@ -3206,7 +3206,7 @@ ExtensionRangeOptions::ExtensionRangeOptions(const ExtensionRangeOptions& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.ExtensionRangeOptions)
}
void ExtensionRangeOptions::SharedCtor() {
inline void ExtensionRangeOptions::SharedCtor() {
}
ExtensionRangeOptions::~ExtensionRangeOptions() {
@ -3481,7 +3481,7 @@ FieldDescriptorProto::FieldDescriptorProto(const FieldDescriptorProto& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.FieldDescriptorProto)
}
void FieldDescriptorProto::SharedCtor() {
inline void FieldDescriptorProto::SharedCtor() {
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
extendee_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
type_name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
@ -4073,7 +4073,7 @@ OneofDescriptorProto::OneofDescriptorProto(const OneofDescriptorProto& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.OneofDescriptorProto)
}
void OneofDescriptorProto::SharedCtor() {
inline void OneofDescriptorProto::SharedCtor() {
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
options_ = nullptr;
}
@ -4330,7 +4330,7 @@ EnumDescriptorProto_EnumReservedRange::EnumDescriptorProto_EnumReservedRange(con
// @@protoc_insertion_point(copy_constructor:google.protobuf.EnumDescriptorProto.EnumReservedRange)
}
void EnumDescriptorProto_EnumReservedRange::SharedCtor() {
inline void EnumDescriptorProto_EnumReservedRange::SharedCtor() {
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&start_) - reinterpret_cast<char*>(this)),
0, static_cast<size_t>(reinterpret_cast<char*>(&end_) -
@ -4585,7 +4585,7 @@ EnumDescriptorProto::EnumDescriptorProto(const EnumDescriptorProto& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.EnumDescriptorProto)
}
void EnumDescriptorProto::SharedCtor() {
inline void EnumDescriptorProto::SharedCtor() {
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
options_ = nullptr;
}
@ -4959,7 +4959,7 @@ EnumValueDescriptorProto::EnumValueDescriptorProto(const EnumValueDescriptorProt
// @@protoc_insertion_point(copy_constructor:google.protobuf.EnumValueDescriptorProto)
}
void EnumValueDescriptorProto::SharedCtor() {
inline void EnumValueDescriptorProto::SharedCtor() {
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&options_) - reinterpret_cast<char*>(this)),
@ -5263,7 +5263,7 @@ ServiceDescriptorProto::ServiceDescriptorProto(const ServiceDescriptorProto& fro
// @@protoc_insertion_point(copy_constructor:google.protobuf.ServiceDescriptorProto)
}
void ServiceDescriptorProto::SharedCtor() {
inline void ServiceDescriptorProto::SharedCtor() {
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
options_ = nullptr;
}
@ -5589,7 +5589,7 @@ MethodDescriptorProto::MethodDescriptorProto(const MethodDescriptorProto& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.MethodDescriptorProto)
}
void MethodDescriptorProto::SharedCtor() {
inline void MethodDescriptorProto::SharedCtor() {
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
input_type_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
output_type_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
@ -6096,7 +6096,7 @@ FileOptions::FileOptions(const FileOptions& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.FileOptions)
}
void FileOptions::SharedCtor() {
inline void FileOptions::SharedCtor() {
java_package_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
java_outer_classname_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
go_package_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
@ -7029,7 +7029,7 @@ MessageOptions::MessageOptions(const MessageOptions& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.MessageOptions)
}
void MessageOptions::SharedCtor() {
inline void MessageOptions::SharedCtor() {
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&message_set_wire_format_) - reinterpret_cast<char*>(this)),
0, static_cast<size_t>(reinterpret_cast<char*>(&map_entry_) -
@ -7375,7 +7375,7 @@ FieldOptions::FieldOptions(const FieldOptions& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.FieldOptions)
}
void FieldOptions::SharedCtor() {
inline void FieldOptions::SharedCtor() {
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&ctype_) - reinterpret_cast<char*>(this)),
0, static_cast<size_t>(reinterpret_cast<char*>(&jstype_) -
@ -7759,7 +7759,7 @@ OneofOptions::OneofOptions(const OneofOptions& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.OneofOptions)
}
void OneofOptions::SharedCtor() {
inline void OneofOptions::SharedCtor() {
}
OneofOptions::~OneofOptions() {
@ -7976,7 +7976,7 @@ EnumOptions::EnumOptions(const EnumOptions& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.EnumOptions)
}
void EnumOptions::SharedCtor() {
inline void EnumOptions::SharedCtor() {
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&allow_alias_) - reinterpret_cast<char*>(this)),
0, static_cast<size_t>(reinterpret_cast<char*>(&deprecated_) -
@ -8259,7 +8259,7 @@ EnumValueOptions::EnumValueOptions(const EnumValueOptions& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.EnumValueOptions)
}
void EnumValueOptions::SharedCtor() {
inline void EnumValueOptions::SharedCtor() {
deprecated_ = false;
}
@ -8503,7 +8503,7 @@ ServiceOptions::ServiceOptions(const ServiceOptions& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.ServiceOptions)
}
void ServiceOptions::SharedCtor() {
inline void ServiceOptions::SharedCtor() {
deprecated_ = false;
}
@ -8752,7 +8752,7 @@ MethodOptions::MethodOptions(const MethodOptions& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.MethodOptions)
}
void MethodOptions::SharedCtor() {
inline void MethodOptions::SharedCtor() {
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&deprecated_) - reinterpret_cast<char*>(this)),
0, static_cast<size_t>(reinterpret_cast<char*>(&idempotency_level_) -
@ -9051,7 +9051,7 @@ UninterpretedOption_NamePart::UninterpretedOption_NamePart(const UninterpretedOp
// @@protoc_insertion_point(copy_constructor:google.protobuf.UninterpretedOption.NamePart)
}
void UninterpretedOption_NamePart::SharedCtor() {
inline void UninterpretedOption_NamePart::SharedCtor() {
name_part_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
is_extension_ = false;
}
@ -9342,7 +9342,7 @@ UninterpretedOption::UninterpretedOption(const UninterpretedOption& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.UninterpretedOption)
}
void UninterpretedOption::SharedCtor() {
inline void UninterpretedOption::SharedCtor() {
identifier_value_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
string_value_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
aggregate_value_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
@ -9770,7 +9770,7 @@ SourceCodeInfo_Location::SourceCodeInfo_Location(const SourceCodeInfo_Location&
// @@protoc_insertion_point(copy_constructor:google.protobuf.SourceCodeInfo.Location)
}
void SourceCodeInfo_Location::SharedCtor() {
inline void SourceCodeInfo_Location::SharedCtor() {
leading_comments_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
trailing_comments_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}
@ -10138,7 +10138,7 @@ SourceCodeInfo::SourceCodeInfo(const SourceCodeInfo& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.SourceCodeInfo)
}
void SourceCodeInfo::SharedCtor() {
inline void SourceCodeInfo::SharedCtor() {
}
SourceCodeInfo::~SourceCodeInfo() {
@ -10342,7 +10342,7 @@ GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation(const GeneratedCodeIn
// @@protoc_insertion_point(copy_constructor:google.protobuf.GeneratedCodeInfo.Annotation)
}
void GeneratedCodeInfo_Annotation::SharedCtor() {
inline void GeneratedCodeInfo_Annotation::SharedCtor() {
source_file_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&begin_) - reinterpret_cast<char*>(this)),
@ -10652,7 +10652,7 @@ GeneratedCodeInfo::GeneratedCodeInfo(const GeneratedCodeInfo& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.GeneratedCodeInfo)
}
void GeneratedCodeInfo::SharedCtor() {
inline void GeneratedCodeInfo::SharedCtor() {
}
GeneratedCodeInfo::~GeneratedCodeInfo() {

@ -381,7 +381,7 @@ bool SimpleDescriptorDatabase::FindAllFileNames(
bool SimpleDescriptorDatabase::MaybeCopy(const FileDescriptorProto* file,
FileDescriptorProto* output) {
if (file == NULL) return false;
if (file == nullptr) return false;
output->CopyFrom(*file);
return true;
}
@ -583,7 +583,7 @@ bool EncodedDescriptorDatabase::FindFileContainingSymbol(
bool EncodedDescriptorDatabase::FindNameOfFileContainingSymbol(
const std::string& symbol_name, std::string* output) {
auto encoded_file = index_->FindSymbol(symbol_name);
if (encoded_file.first == NULL) return false;
if (encoded_file.first == nullptr) return false;
// Optimization: The name should be the first field in the encoded message.
// Try to just read it directly.
@ -871,7 +871,7 @@ bool EncodedDescriptorDatabase::FindAllFileNames(
bool EncodedDescriptorDatabase::MaybeParse(
std::pair<const void*, int> encoded_file, FileDescriptorProto* output) {
if (encoded_file.first == NULL) return false;
if (encoded_file.first == nullptr) return false;
return output->ParseFromArray(encoded_file.first, encoded_file.second);
}
@ -893,7 +893,7 @@ DescriptorPoolDatabase::~DescriptorPoolDatabase() {}
bool DescriptorPoolDatabase::FindFileByName(const std::string& filename,
FileDescriptorProto* output) {
const FileDescriptor* file = pool_.FindFileByName(filename);
if (file == NULL) return false;
if (file == nullptr) return false;
output->Clear();
file->CopyTo(output);
return true;
@ -902,7 +902,7 @@ bool DescriptorPoolDatabase::FindFileByName(const std::string& filename,
bool DescriptorPoolDatabase::FindFileContainingSymbol(
const std::string& symbol_name, FileDescriptorProto* output) {
const FileDescriptor* file = pool_.FindFileContainingSymbol(symbol_name);
if (file == NULL) return false;
if (file == nullptr) return false;
output->Clear();
file->CopyTo(output);
return true;
@ -912,11 +912,11 @@ bool DescriptorPoolDatabase::FindFileContainingExtension(
const std::string& containing_type, int field_number,
FileDescriptorProto* output) {
const Descriptor* extendee = pool_.FindMessageTypeByName(containing_type);
if (extendee == NULL) return false;
if (extendee == nullptr) return false;
const FieldDescriptor* extension =
pool_.FindExtensionByNumber(extendee, field_number);
if (extension == NULL) return false;
if (extension == nullptr) return false;
output->Clear();
extension->file()->CopyTo(output);
@ -926,7 +926,7 @@ bool DescriptorPoolDatabase::FindFileContainingExtension(
bool DescriptorPoolDatabase::FindAllExtensionNumbers(
const std::string& extendee_type, std::vector<int>* output) {
const Descriptor* extendee = pool_.FindMessageTypeByName(extendee_type);
if (extendee == NULL) return false;
if (extendee == nullptr) return false;
std::vector<const FieldDescriptor*> extensions;
pool_.FindAllExtensions(extendee, &extensions);

@ -268,7 +268,7 @@ class PROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase {
DescriptorIndex<const FileDescriptorProto*> index_;
std::vector<std::unique_ptr<const FileDescriptorProto>> files_to_delete_;
// If file is non-NULL, copy it into *output and return true, otherwise
// If file is non-nullptr, copy it into *output and return true, otherwise
// return false.
bool MaybeCopy(const FileDescriptorProto* file, FileDescriptorProto* output);
@ -320,8 +320,8 @@ class PROTOBUF_EXPORT EncodedDescriptorDatabase : public DescriptorDatabase {
std::unique_ptr<DescriptorIndex> index_;
std::vector<void*> files_to_delete_;
// If encoded_file.first is non-NULL, parse the data into *output and return
// true, otherwise return false.
// If encoded_file.first is non-nullptr, parse the data into *output and
// return true, otherwise return false.
bool MaybeParse(std::pair<const void*, int> encoded_file,
FileDescriptorProto* output);

@ -3173,6 +3173,13 @@ TEST(CustomOptions, OptionLocations) {
TEST(CustomOptions, OptionTypes) {
const MessageOptions* options = nullptr;
constexpr int32_t kint32min = std::numeric_limits<int32_t>::min();
constexpr int32_t kint32max = std::numeric_limits<int32_t>::max();
constexpr uint32_t kuint32max = std::numeric_limits<uint32_t>::max();
constexpr int64_t kint64min = std::numeric_limits<int64_t>::min();
constexpr int64_t kint64max = std::numeric_limits<int64_t>::max();
constexpr uint64_t kuint64max = std::numeric_limits<uint64_t>::max();
options =
&protobuf_unittest::CustomOptionMinIntegerValues::descriptor()->options();
EXPECT_EQ(false, options->GetExtension(protobuf_unittest::bool_opt));

@ -100,7 +100,7 @@ Duration::Duration(const Duration& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.Duration)
}
void Duration::SharedCtor() {
inline void Duration::SharedCtor() {
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&seconds_) - reinterpret_cast<char*>(this)),
0, static_cast<size_t>(reinterpret_cast<char*>(&nanos_) -

@ -450,7 +450,7 @@ void DynamicMessage::SharedCtor(bool lock_factory) {
case FieldDescriptor::CPPTYPE_MESSAGE: {
if (!field->is_repeated()) {
new (field_ptr) Message*(NULL);
new (field_ptr) Message*(nullptr);
} else {
if (IsMapFieldInApi(field)) {
// We need to lock in most cases to avoid data racing. Only not lock
@ -499,7 +499,7 @@ void DynamicMessage::SharedCtor(bool lock_factory) {
bool DynamicMessage::is_prototype() const {
return type_info_->prototype == this ||
// If type_info_->prototype is NULL, then we must be constructing
// If type_info_->prototype is nullptr, then we must be constructing
// the prototype now, which means we must be the prototype.
type_info_->prototype == nullptr;
}
@ -546,7 +546,7 @@ DynamicMessage::~DynamicMessage() {
// from reflection.
const std::string* default_value = nullptr;
reinterpret_cast<ArenaStringPtr*>(field_ptr)->Destroy(
default_value, NULL);
default_value, nullptr);
break;
}
}
@ -606,14 +606,14 @@ DynamicMessage::~DynamicMessage() {
type_info_->offsets[i]))
->GetPointer();
reinterpret_cast<ArenaStringPtr*>(field_ptr)->Destroy(default_value,
NULL);
nullptr);
break;
}
}
} else if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
if (!is_prototype()) {
Message* message = *reinterpret_cast<Message**>(field_ptr);
if (message != NULL) {
if (message != nullptr) {
delete message;
}
}
@ -645,10 +645,10 @@ void DynamicMessage::CrossLinkPrototypes() {
}
}
Message* DynamicMessage::New() const { return New(NULL); }
Message* DynamicMessage::New() const { return New(nullptr); }
Message* DynamicMessage::New(Arena* arena) const {
if (arena != NULL) {
if (arena != nullptr) {
void* new_base = Arena::CreateArray<char>(arena, type_info_->size);
memset(new_base, 0, type_info_->size);
return new (new_base) DynamicMessage(type_info_, arena);
@ -701,7 +701,7 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock(
}
const TypeInfo** target = &prototypes_[type];
if (*target != NULL) {
if (*target != nullptr) {
// Already exists.
return (*target)->prototype;
}
@ -710,7 +710,7 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock(
*target = type_info;
type_info->type = type;
type_info->pool = (pool_ == NULL) ? type->file()->pool() : pool_;
type_info->pool = (pool_ == nullptr) ? type->file()->pool() : pool_;
type_info->factory = this;
// We need to construct all the structures passed to Reflection's constructor.

@ -92,33 +92,33 @@ class DynamicMessageTest : public ::testing::TestWithParam<bool> {
proto2_nofieldpresence_unittest::TestAllTypes::descriptor()->file()->CopyTo(
&unittest_no_field_presence_file);
ASSERT_TRUE(pool_.BuildFile(unittest_import_public_file) != NULL);
ASSERT_TRUE(pool_.BuildFile(unittest_import_file) != NULL);
ASSERT_TRUE(pool_.BuildFile(unittest_file) != NULL);
ASSERT_TRUE(pool_.BuildFile(unittest_no_field_presence_file) != NULL);
ASSERT_TRUE(pool_.BuildFile(unittest_import_public_file) != nullptr);
ASSERT_TRUE(pool_.BuildFile(unittest_import_file) != nullptr);
ASSERT_TRUE(pool_.BuildFile(unittest_file) != nullptr);
ASSERT_TRUE(pool_.BuildFile(unittest_no_field_presence_file) != nullptr);
descriptor_ = pool_.FindMessageTypeByName("protobuf_unittest.TestAllTypes");
ASSERT_TRUE(descriptor_ != NULL);
ASSERT_TRUE(descriptor_ != nullptr);
prototype_ = factory_.GetPrototype(descriptor_);
extensions_descriptor_ =
pool_.FindMessageTypeByName("protobuf_unittest.TestAllExtensions");
ASSERT_TRUE(extensions_descriptor_ != NULL);
ASSERT_TRUE(extensions_descriptor_ != nullptr);
extensions_prototype_ = factory_.GetPrototype(extensions_descriptor_);
packed_descriptor_ =
pool_.FindMessageTypeByName("protobuf_unittest.TestPackedTypes");
ASSERT_TRUE(packed_descriptor_ != NULL);
ASSERT_TRUE(packed_descriptor_ != nullptr);
packed_prototype_ = factory_.GetPrototype(packed_descriptor_);
oneof_descriptor_ =
pool_.FindMessageTypeByName("protobuf_unittest.TestOneof2");
ASSERT_TRUE(oneof_descriptor_ != NULL);
ASSERT_TRUE(oneof_descriptor_ != nullptr);
oneof_prototype_ = factory_.GetPrototype(oneof_descriptor_);
proto3_descriptor_ = pool_.FindMessageTypeByName(
"proto2_nofieldpresence_unittest.TestAllTypes");
ASSERT_TRUE(proto3_descriptor_ != NULL);
ASSERT_TRUE(proto3_descriptor_ != nullptr);
proto3_prototype_ = factory_.GetPrototype(proto3_descriptor_);
}
};
@ -145,7 +145,7 @@ TEST_P(DynamicMessageTest, IndependentOffsets) {
// one to a unique value then checking that they all still have those
// unique values (i.e. they don't stomp each other).
Arena arena;
Message* message = prototype_->New(GetParam() ? &arena : NULL);
Message* message = prototype_->New(GetParam() ? &arena : nullptr);
TestUtil::ReflectionTester reflection_tester(descriptor_);
reflection_tester.SetAllFieldsViaReflection(message);
@ -159,7 +159,7 @@ TEST_P(DynamicMessageTest, IndependentOffsets) {
TEST_P(DynamicMessageTest, Extensions) {
// Check that extensions work.
Arena arena;
Message* message = extensions_prototype_->New(GetParam() ? &arena : NULL);
Message* message = extensions_prototype_->New(GetParam() ? &arena : nullptr);
TestUtil::ReflectionTester reflection_tester(extensions_descriptor_);
reflection_tester.SetAllFieldsViaReflection(message);
@ -173,7 +173,7 @@ TEST_P(DynamicMessageTest, Extensions) {
TEST_P(DynamicMessageTest, PackedFields) {
// Check that packed fields work properly.
Arena arena;
Message* message = packed_prototype_->New(GetParam() ? &arena : NULL);
Message* message = packed_prototype_->New(GetParam() ? &arena : nullptr);
TestUtil::ReflectionTester reflection_tester(packed_descriptor_);
reflection_tester.SetPackedFieldsViaReflection(message);
@ -187,7 +187,7 @@ TEST_P(DynamicMessageTest, PackedFields) {
TEST_P(DynamicMessageTest, Oneof) {
// Check that oneof fields work properly.
Arena arena;
Message* message = oneof_prototype_->New(GetParam() ? &arena : NULL);
Message* message = oneof_prototype_->New(GetParam() ? &arena : nullptr);
// Check default values.
const Descriptor* descriptor = message->GetDescriptor();
@ -258,7 +258,7 @@ TEST_P(DynamicMessageTest, SpaceUsed) {
// to test very much here. Just make sure it appears to be working.
Arena arena;
Message* message = prototype_->New(GetParam() ? &arena : NULL);
Message* message = prototype_->New(GetParam() ? &arena : nullptr);
TestUtil::ReflectionTester reflection_tester(descriptor_);
size_t initial_space_used = message->SpaceUsedLong();
@ -300,8 +300,8 @@ TEST_F(DynamicMessageTest, Proto3) {
desc->FindFieldByName("optional_int32");
const FieldDescriptor* optional_msg =
desc->FindFieldByName("optional_nested_message");
EXPECT_TRUE(optional_int32 != NULL);
EXPECT_TRUE(optional_msg != NULL);
EXPECT_TRUE(optional_int32 != nullptr);
EXPECT_TRUE(optional_msg != nullptr);
EXPECT_EQ(false, refl->HasField(*message, optional_int32));
refl->SetInt32(message, optional_int32, 42);

@ -142,7 +142,7 @@ ExtensionFinder::~ExtensionFinder() {}
bool GeneratedExtensionFinder::Find(int number, ExtensionInfo* output) {
const ExtensionInfo* extension = FindRegisteredExtension(extendee_, number);
if (extension == NULL) {
if (extension == nullptr) {
return false;
} else {
*output = *extension;
@ -204,12 +204,12 @@ ExtensionSet::ExtensionSet(Arena* arena)
flat_capacity_(0),
flat_size_(0),
map_{flat_capacity_ == 0
? NULL
? nullptr
: Arena::CreateArray<KeyValue>(arena_, flat_capacity_)} {}
ExtensionSet::~ExtensionSet() {
// Deletes all allocated extensions.
if (arena_ == NULL) {
if (arena_ == nullptr) {
ForEach([](int /* number */, Extension& ext) { ext.Free(); });
if (PROTOBUF_PREDICT_FALSE(is_large())) {
delete map_.large;
@ -263,12 +263,12 @@ int ExtensionSet::NumExtensions() const {
int ExtensionSet::ExtensionSize(int number) const {
const Extension* ext = FindOrNull(number);
return ext == NULL ? 0 : ext->GetSize();
return ext == nullptr ? 0 : ext->GetSize();
}
FieldType ExtensionSet::ExtensionType(int number) const {
const Extension* ext = FindOrNull(number);
if (ext == NULL) {
if (ext == nullptr) {
GOOGLE_LOG(DFATAL) << "Don't lookup extension types if they aren't present (1). ";
return 0;
}
@ -280,7 +280,7 @@ FieldType ExtensionSet::ExtensionType(int number) const {
void ExtensionSet::ClearExtension(int number) {
Extension* ext = FindOrNull(number);
if (ext == NULL) return;
if (ext == nullptr) return;
ext->Clear();
}
@ -305,7 +305,7 @@ enum { REPEATED_FIELD, OPTIONAL_FIELD };
LOWERCASE ExtensionSet::Get##CAMELCASE(int number, LOWERCASE default_value) \
const { \
const Extension* extension = FindOrNull(number); \
if (extension == NULL || extension->is_cleared) { \
if (extension == nullptr || extension->is_cleared) { \
return default_value; \
} else { \
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL_FIELD, UPPERCASE); \
@ -316,7 +316,7 @@ enum { REPEATED_FIELD, OPTIONAL_FIELD };
const LOWERCASE& ExtensionSet::GetRef##CAMELCASE( \
int number, const LOWERCASE& default_value) const { \
const Extension* extension = FindOrNull(number); \
if (extension == NULL || extension->is_cleared) { \
if (extension == nullptr || extension->is_cleared) { \
return default_value; \
} else { \
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL_FIELD, UPPERCASE); \
@ -343,7 +343,7 @@ enum { REPEATED_FIELD, OPTIONAL_FIELD };
LOWERCASE ExtensionSet::GetRepeated##CAMELCASE(int number, int index) \
const { \
const Extension* extension = FindOrNull(number); \
GOOGLE_CHECK(extension != NULL) << "Index out-of-bounds (field is empty)."; \
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; \
GOOGLE_DCHECK_TYPE(*extension, REPEATED_FIELD, UPPERCASE); \
return extension->repeated_##LOWERCASE##_value->Get(index); \
} \
@ -351,7 +351,7 @@ enum { REPEATED_FIELD, OPTIONAL_FIELD };
const LOWERCASE& ExtensionSet::GetRefRepeated##CAMELCASE(int number, \
int index) const { \
const Extension* extension = FindOrNull(number); \
GOOGLE_CHECK(extension != NULL) << "Index out-of-bounds (field is empty)."; \
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; \
GOOGLE_DCHECK_TYPE(*extension, REPEATED_FIELD, UPPERCASE); \
return extension->repeated_##LOWERCASE##_value->Get(index); \
} \
@ -359,7 +359,7 @@ enum { REPEATED_FIELD, OPTIONAL_FIELD };
void ExtensionSet::SetRepeated##CAMELCASE(int number, int index, \
LOWERCASE value) { \
Extension* extension = FindOrNull(number); \
GOOGLE_CHECK(extension != NULL) << "Index out-of-bounds (field is empty)."; \
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty)."; \
GOOGLE_DCHECK_TYPE(*extension, REPEATED_FIELD, UPPERCASE); \
extension->repeated_##LOWERCASE##_value->Set(index, value); \
} \
@ -396,7 +396,7 @@ PRIMITIVE_ACCESSORS(BOOL, bool, Bool)
const void* ExtensionSet::GetRawRepeatedField(int number,
const void* default_value) const {
const Extension* extension = FindOrNull(number);
if (extension == NULL) {
if (extension == nullptr) {
return default_value;
}
// We assume that all the RepeatedField<>* pointers have the same
@ -470,7 +470,7 @@ void* ExtensionSet::MutableRawRepeatedField(int number, FieldType field_type,
// the don't already exist; instead, just GOOGLE_CHECK-fails.
void* ExtensionSet::MutableRawRepeatedField(int number) {
Extension* extension = FindOrNull(number);
GOOGLE_CHECK(extension != NULL) << "Extension not found.";
GOOGLE_CHECK(extension != nullptr) << "Extension not found.";
// We assume that all the RepeatedField<>* pointers have the same
// size and alignment within the anonymous union in Extension.
return extension->repeated_int32_t_value;
@ -481,7 +481,7 @@ void* ExtensionSet::MutableRawRepeatedField(int number) {
int ExtensionSet::GetEnum(int number, int default_value) const {
const Extension* extension = FindOrNull(number);
if (extension == NULL || extension->is_cleared) {
if (extension == nullptr || extension->is_cleared) {
// Not present. Return the default value.
return default_value;
} else {
@ -560,7 +560,7 @@ void ExtensionSet::AddEnum(int number, FieldType type, bool packed, int value,
const std::string& ExtensionSet::GetString(
int number, const std::string& default_value) const {
const Extension* extension = FindOrNull(number);
if (extension == NULL || extension->is_cleared) {
if (extension == nullptr || extension->is_cleared) {
// Not present. Return the default value.
return default_value;
} else {
@ -587,14 +587,14 @@ std::string* ExtensionSet::MutableString(int number, FieldType type,
const std::string& ExtensionSet::GetRepeatedString(int number,
int index) const {
const Extension* extension = FindOrNull(number);
GOOGLE_CHECK(extension != NULL) << "Index out-of-bounds (field is empty).";
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty).";
GOOGLE_DCHECK_TYPE(*extension, REPEATED_FIELD, STRING);
return extension->repeated_string_value->Get(index);
}
std::string* ExtensionSet::MutableRepeatedString(int number, int index) {
Extension* extension = FindOrNull(number);
GOOGLE_CHECK(extension != NULL) << "Index out-of-bounds (field is empty).";
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty).";
GOOGLE_DCHECK_TYPE(*extension, REPEATED_FIELD, STRING);
return extension->repeated_string_value->Mutable(index);
}
@ -621,13 +621,13 @@ std::string* ExtensionSet::AddString(int number, FieldType type,
const MessageLite& ExtensionSet::GetMessage(
int number, const MessageLite& default_value) const {
const Extension* extension = FindOrNull(number);
if (extension == NULL) {
if (extension == nullptr) {
// Not present. Return the default value.
return default_value;
} else {
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL_FIELD, MESSAGE);
if (extension->is_lazy) {
return extension->lazymessage_value->GetMessage(default_value);
return extension->lazymessage_value->GetMessage(default_value, arena_);
} else {
return *extension->message_value;
}
@ -670,7 +670,7 @@ MessageLite* ExtensionSet::MutableMessage(int number, FieldType type,
void ExtensionSet::SetAllocatedMessage(int number, FieldType type,
const FieldDescriptor* descriptor,
MessageLite* message) {
if (message == NULL) {
if (message == nullptr) {
ClearExtension(number);
return;
}
@ -685,9 +685,9 @@ void ExtensionSet::SetAllocatedMessage(int number, FieldType type,
extension->is_lazy = false;
if (message_arena == arena_) {
extension->message_value = message;
} else if (message_arena == NULL) {
} else if (message_arena == nullptr) {
extension->message_value = message;
arena_->Own(message); // not NULL because not equal to message_arena
arena_->Own(message); // not nullptr because not equal to message_arena
} else {
extension->message_value = message->New(arena_);
extension->message_value->CheckTypeAndMergeFrom(*message);
@ -697,14 +697,14 @@ void ExtensionSet::SetAllocatedMessage(int number, FieldType type,
if (extension->is_lazy) {
extension->lazymessage_value->SetAllocatedMessage(message);
} else {
if (arena_ == NULL) {
if (arena_ == nullptr) {
delete extension->message_value;
}
if (message_arena == arena_) {
extension->message_value = message;
} else if (message_arena == NULL) {
} else if (message_arena == nullptr) {
extension->message_value = message;
arena_->Own(message); // not NULL because not equal to message_arena
arena_->Own(message); // not nullptr because not equal to message_arena
} else {
extension->message_value = message->New(arena_);
extension->message_value->CheckTypeAndMergeFrom(*message);
@ -717,7 +717,7 @@ void ExtensionSet::SetAllocatedMessage(int number, FieldType type,
void ExtensionSet::UnsafeArenaSetAllocatedMessage(
int number, FieldType type, const FieldDescriptor* descriptor,
MessageLite* message) {
if (message == NULL) {
if (message == nullptr) {
ClearExtension(number);
return;
}
@ -733,7 +733,7 @@ void ExtensionSet::UnsafeArenaSetAllocatedMessage(
if (extension->is_lazy) {
extension->lazymessage_value->UnsafeArenaSetAllocatedMessage(message);
} else {
if (arena_ == NULL) {
if (arena_ == nullptr) {
delete extension->message_value;
}
extension->message_value = message;
@ -745,19 +745,19 @@ void ExtensionSet::UnsafeArenaSetAllocatedMessage(
MessageLite* ExtensionSet::ReleaseMessage(int number,
const MessageLite& prototype) {
Extension* extension = FindOrNull(number);
if (extension == NULL) {
// Not present. Return NULL.
return NULL;
if (extension == nullptr) {
// Not present. Return nullptr.
return nullptr;
} else {
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL_FIELD, MESSAGE);
MessageLite* ret = NULL;
MessageLite* ret = nullptr;
if (extension->is_lazy) {
ret = extension->lazymessage_value->ReleaseMessage(prototype);
if (arena_ == NULL) {
ret = extension->lazymessage_value->ReleaseMessage(prototype, arena_);
if (arena_ == nullptr) {
delete extension->lazymessage_value;
}
} else {
if (arena_ == NULL) {
if (arena_ == nullptr) {
ret = extension->message_value;
} else {
// ReleaseMessage() always returns a heap-allocated message, and we are
@ -774,15 +774,16 @@ MessageLite* ExtensionSet::ReleaseMessage(int number,
MessageLite* ExtensionSet::UnsafeArenaReleaseMessage(
int number, const MessageLite& prototype) {
Extension* extension = FindOrNull(number);
if (extension == NULL) {
// Not present. Return NULL.
return NULL;
if (extension == nullptr) {
// Not present. Return nullptr.
return nullptr;
} else {
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL_FIELD, MESSAGE);
MessageLite* ret = NULL;
MessageLite* ret = nullptr;
if (extension->is_lazy) {
ret = extension->lazymessage_value->UnsafeArenaReleaseMessage(prototype);
if (arena_ == NULL) {
ret = extension->lazymessage_value->UnsafeArenaReleaseMessage(prototype,
arena_);
if (arena_ == nullptr) {
delete extension->lazymessage_value;
}
} else {
@ -800,14 +801,14 @@ MessageLite* ExtensionSet::UnsafeArenaReleaseMessage(
const MessageLite& ExtensionSet::GetRepeatedMessage(int number,
int index) const {
const Extension* extension = FindOrNull(number);
GOOGLE_CHECK(extension != NULL) << "Index out-of-bounds (field is empty).";
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty).";
GOOGLE_DCHECK_TYPE(*extension, REPEATED_FIELD, MESSAGE);
return extension->repeated_message_value->Get(index);
}
MessageLite* ExtensionSet::MutableRepeatedMessage(int number, int index) {
Extension* extension = FindOrNull(number);
GOOGLE_CHECK(extension != NULL) << "Index out-of-bounds (field is empty).";
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty).";
GOOGLE_DCHECK_TYPE(*extension, REPEATED_FIELD, MESSAGE);
return extension->repeated_message_value->Mutable(index);
}
@ -831,7 +832,7 @@ MessageLite* ExtensionSet::AddMessage(int number, FieldType type,
MessageLite* result = reinterpret_cast<internal::RepeatedPtrFieldBase*>(
extension->repeated_message_value)
->AddFromCleared<GenericTypeHandler<MessageLite>>();
if (result == NULL) {
if (result == nullptr) {
result = prototype.New(arena_);
extension->repeated_message_value->AddAllocated(result);
}
@ -847,7 +848,7 @@ MessageLite* ExtensionSet::AddMessage(int number, FieldType type,
void ExtensionSet::RemoveLast(int number) {
Extension* extension = FindOrNull(number);
GOOGLE_CHECK(extension != NULL) << "Index out-of-bounds (field is empty).";
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty).";
GOOGLE_DCHECK(extension->is_repeated);
switch (cpp_type(extension->type)) {
@ -886,7 +887,7 @@ void ExtensionSet::RemoveLast(int number) {
MessageLite* ExtensionSet::ReleaseLast(int number) {
Extension* extension = FindOrNull(number);
GOOGLE_CHECK(extension != NULL) << "Index out-of-bounds (field is empty).";
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty).";
GOOGLE_DCHECK(extension->is_repeated);
GOOGLE_DCHECK(cpp_type(extension->type) == WireFormatLite::CPPTYPE_MESSAGE);
return extension->repeated_message_value->ReleaseLast();
@ -902,7 +903,7 @@ MessageLite* ExtensionSet::UnsafeArenaReleaseLast(int number) {
void ExtensionSet::SwapElements(int number, int index1, int index2) {
Extension* extension = FindOrNull(number);
GOOGLE_CHECK(extension != NULL) << "Index out-of-bounds (field is empty).";
GOOGLE_CHECK(extension != nullptr) << "Index out-of-bounds (field is empty).";
GOOGLE_DCHECK(extension->is_repeated);
switch (cpp_type(extension->type)) {
@ -978,13 +979,14 @@ void ExtensionSet::MergeFrom(const ExtensionSet& other) {
other.map_.large->end()));
}
}
other.ForEach([this](int number, const Extension& ext) {
this->InternalExtensionMergeFrom(number, ext);
other.ForEach([this, &other](int number, const Extension& ext) {
this->InternalExtensionMergeFrom(number, ext, other.arena_);
});
}
void ExtensionSet::InternalExtensionMergeFrom(
int number, const Extension& other_extension) {
void ExtensionSet::InternalExtensionMergeFrom(int number,
const Extension& other_extension,
Arena* other_arena) {
if (other_extension.is_repeated) {
Extension* extension;
bool is_new =
@ -1037,7 +1039,7 @@ void ExtensionSet::InternalExtensionMergeFrom(
reinterpret_cast<internal::RepeatedPtrFieldBase*>(
extension->repeated_message_value)
->AddFromCleared<GenericTypeHandler<MessageLite>>();
if (target == NULL) {
if (target == nullptr) {
target = other_message.New(arena_);
extension->repeated_message_value->AddAllocated(target);
}
@ -1100,7 +1102,7 @@ void ExtensionSet::InternalExtensionMergeFrom(
} else {
extension->message_value->CheckTypeAndMergeFrom(
other_extension.lazymessage_value->GetMessage(
*extension->message_value));
*extension->message_value, other_arena));
}
} else {
if (extension->is_lazy) {
@ -1169,18 +1171,19 @@ void ExtensionSet::SwapExtension(ExtensionSet* other, int number) {
// We do it this way to reuse the copy-across-arenas logic already
// implemented in ExtensionSet's MergeFrom.
ExtensionSet temp;
temp.InternalExtensionMergeFrom(number, *other_ext);
temp.InternalExtensionMergeFrom(number, *other_ext, other->GetArena());
Extension* temp_ext = temp.FindOrNull(number);
other_ext->Clear();
other->InternalExtensionMergeFrom(number, *this_ext);
other->InternalExtensionMergeFrom(number, *this_ext, this->GetArena());
this_ext->Clear();
InternalExtensionMergeFrom(number, *temp_ext);
InternalExtensionMergeFrom(number, *temp_ext, temp.GetArena());
} else if (this_ext == nullptr) {
InternalExtensionMergeFrom(number, *other_ext);
InternalExtensionMergeFrom(number, *other_ext, other->GetArena());
if (other->GetArena() == nullptr) other_ext->Free();
other->Erase(number);
} else {
other->InternalExtensionMergeFrom(number, *this_ext);
other->InternalExtensionMergeFrom(number, *this_ext, this->GetArena());
if (GetArena() == nullptr) this_ext->Free();
Erase(number);
}
@ -1892,7 +1895,7 @@ const ExtensionSet::Extension* ExtensionSet::FindOrNullInLargeMap(
if (it != map_.large->end()) {
return &it->second;
}
return NULL;
return nullptr;
}
ExtensionSet::Extension* ExtensionSet::FindOrNull(int key) {

@ -109,7 +109,7 @@ struct ExtensionInfo {
type(type_param),
is_repeated(isrepeated),
is_packed(ispacked),
descriptor(NULL) {}
descriptor(nullptr) {}
const MessageLite* message;
int number;
@ -133,7 +133,7 @@ struct ExtensionInfo {
};
// The descriptor for this extension, if one exists and is known. May be
// NULL. Must not be NULL if the descriptor for the extension does not
// nullptr. Must not be nullptr if the descriptor for the extension does not
// live in the same pool as the descriptor for the containing type.
const FieldDescriptor* descriptor;
};
@ -262,7 +262,7 @@ class PROTOBUF_EXPORT ExtensionSet {
const MessageLite& GetMessage(int number, const Descriptor* message_type,
MessageFactory* factory) const;
// |descriptor| may be NULL so long as it is known that the descriptor for
// |descriptor| may be nullptr so long as it is known that the descriptor for
// the extension lives in the same pool as the descriptor for the containing
// type.
#define desc const FieldDescriptor* descriptor // avoid line wrapping
@ -282,7 +282,7 @@ class PROTOBUF_EXPORT ExtensionSet {
MessageFactory* factory);
// Adds the given message to the ExtensionSet, taking ownership of the
// message object. Existing message with the same number will be deleted.
// If "message" is NULL, this is equivalent to "ClearExtension(number)".
// If "message" is nullptr, this is equivalent to "ClearExtension(number)".
void SetAllocatedMessage(int number, FieldType type,
const FieldDescriptor* descriptor,
MessageLite* message);
@ -576,16 +576,16 @@ class PROTOBUF_EXPORT ExtensionSet {
virtual ~LazyMessageExtension() {}
virtual LazyMessageExtension* New(Arena* arena) const = 0;
virtual const MessageLite& GetMessage(
const MessageLite& prototype) const = 0;
virtual const MessageLite& GetMessage(const MessageLite& prototype,
Arena* arena) const = 0;
virtual MessageLite* MutableMessage(const MessageLite& prototype,
Arena* arena) = 0;
virtual void SetAllocatedMessage(MessageLite* message) = 0;
virtual void UnsafeArenaSetAllocatedMessage(MessageLite* message) = 0;
virtual PROTOBUF_MUST_USE_RESULT MessageLite* ReleaseMessage(
const MessageLite& prototype) = 0;
virtual MessageLite* UnsafeArenaReleaseMessage(
const MessageLite& prototype) = 0;
const MessageLite& prototype, Arena* arena) = 0;
virtual MessageLite* UnsafeArenaReleaseMessage(const MessageLite& prototype,
Arena* arena) = 0;
virtual bool IsInitialized() const = 0;
@ -667,8 +667,8 @@ class PROTOBUF_EXPORT ExtensionSet {
mutable int cached_size;
// The descriptor for this extension, if one exists and is known. May be
// NULL. Must not be NULL if the descriptor for the extension does not
// live in the same pool as the descriptor for the containing type.
// nullptr. Must not be nullptr if the descriptor for the extension does
// not live in the same pool as the descriptor for the containing type.
const FieldDescriptor* descriptor;
// Some helper methods for operations on a single Extension.
@ -769,7 +769,8 @@ class PROTOBUF_EXPORT ExtensionSet {
}
// Merges existing Extension from other_extension
void InternalExtensionMergeFrom(int number, const Extension& other_extension);
void InternalExtensionMergeFrom(int number, const Extension& other_extension,
Arena* other_arena);
// Returns true and fills field_number and extension if extension is found.
// Note to support packed repeated field compatibility, it also fills whether
@ -1084,7 +1085,7 @@ class PROTOBUF_EXPORT RepeatedPrimitiveDefaults {
template <> \
inline void PrimitiveTypeTraits<TYPE>::Set(int number, FieldType field_type, \
TYPE value, ExtensionSet* set) { \
set->Set##METHOD(number, field_type, value, NULL); \
set->Set##METHOD(number, field_type, value, nullptr); \
} \
\
template <> \
@ -1106,7 +1107,7 @@ class PROTOBUF_EXPORT RepeatedPrimitiveDefaults {
inline void RepeatedPrimitiveTypeTraits<TYPE>::Add( \
int number, FieldType field_type, bool is_packed, TYPE value, \
ExtensionSet* set) { \
set->Add##METHOD(number, field_type, is_packed, value, NULL); \
set->Add##METHOD(number, field_type, is_packed, value, nullptr); \
} \
template <> \
inline const RepeatedField<TYPE>* \
@ -1132,7 +1133,7 @@ class PROTOBUF_EXPORT RepeatedPrimitiveDefaults {
RepeatedPrimitiveTypeTraits<TYPE>::MutableRepeated( \
int number, FieldType field_type, bool is_packed, ExtensionSet* set) { \
return reinterpret_cast<RepeatedField<TYPE>*>( \
set->MutableRawRepeatedField(number, field_type, is_packed, NULL)); \
set->MutableRawRepeatedField(number, field_type, is_packed, nullptr)); \
}
PROTOBUF_DEFINE_PRIMITIVE_TYPE(int32_t, Int32)
@ -1165,11 +1166,11 @@ class PROTOBUF_EXPORT StringTypeTraits {
}
static inline void Set(int number, FieldType field_type,
const std::string& value, ExtensionSet* set) {
set->SetString(number, field_type, value, NULL);
set->SetString(number, field_type, value, nullptr);
}
static inline std::string* Mutable(int number, FieldType field_type,
ExtensionSet* set) {
return set->MutableString(number, field_type, NULL);
return set->MutableString(number, field_type, nullptr);
}
template <typename ExtendeeT>
static void Register(int number, FieldType type, bool is_packed) {
@ -1207,11 +1208,11 @@ class PROTOBUF_EXPORT RepeatedStringTypeTraits {
}
static inline void Add(int number, FieldType field_type, bool /*is_packed*/,
const std::string& value, ExtensionSet* set) {
set->AddString(number, field_type, value, NULL);
set->AddString(number, field_type, value, nullptr);
}
static inline std::string* Add(int number, FieldType field_type,
ExtensionSet* set) {
return set->AddString(number, field_type, NULL);
return set->AddString(number, field_type, nullptr);
}
static inline const RepeatedPtrField<std::string>& GetRepeated(
int number, const ExtensionSet& set) {
@ -1222,7 +1223,7 @@ class PROTOBUF_EXPORT RepeatedStringTypeTraits {
static inline RepeatedPtrField<std::string>* MutableRepeated(
int number, FieldType field_type, bool is_packed, ExtensionSet* set) {
return reinterpret_cast<RepeatedPtrField<std::string>*>(
set->MutableRawRepeatedField(number, field_type, is_packed, NULL));
set->MutableRawRepeatedField(number, field_type, is_packed, nullptr));
}
static const RepeatedFieldType* GetDefaultRepeatedField();
@ -1262,7 +1263,7 @@ class EnumTypeTraits {
static inline void Set(int number, FieldType field_type, ConstType value,
ExtensionSet* set) {
GOOGLE_DCHECK(IsValid(value));
set->SetEnum(number, field_type, value, NULL);
set->SetEnum(number, field_type, value, nullptr);
}
template <typename ExtendeeT>
static void Register(int number, FieldType type, bool is_packed) {
@ -1296,7 +1297,7 @@ class RepeatedEnumTypeTraits {
static inline void Add(int number, FieldType field_type, bool is_packed,
ConstType value, ExtensionSet* set) {
GOOGLE_DCHECK(IsValid(value));
set->AddEnum(number, field_type, is_packed, value, NULL);
set->AddEnum(number, field_type, is_packed, value, nullptr);
}
static inline const RepeatedField<Type>& GetRepeated(
int number, const ExtensionSet& set) {
@ -1316,7 +1317,7 @@ class RepeatedEnumTypeTraits {
bool is_packed,
ExtensionSet* set) {
return reinterpret_cast<RepeatedField<Type>*>(
set->MutableRawRepeatedField(number, field_type, is_packed, NULL));
set->MutableRawRepeatedField(number, field_type, is_packed, nullptr));
}
static const RepeatedFieldType* GetDefaultRepeatedField() {
@ -1361,16 +1362,16 @@ class MessageTypeTraits {
static inline MutableType Mutable(int number, FieldType field_type,
ExtensionSet* set) {
return static_cast<Type*>(set->MutableMessage(
number, field_type, Type::default_instance(), NULL));
number, field_type, Type::default_instance(), nullptr));
}
static inline void SetAllocated(int number, FieldType field_type,
MutableType message, ExtensionSet* set) {
set->SetAllocatedMessage(number, field_type, NULL, message);
set->SetAllocatedMessage(number, field_type, nullptr, message);
}
static inline void UnsafeArenaSetAllocated(int number, FieldType field_type,
MutableType message,
ExtensionSet* set) {
set->UnsafeArenaSetAllocatedMessage(number, field_type, NULL, message);
set->UnsafeArenaSetAllocatedMessage(number, field_type, nullptr, message);
}
static inline PROTOBUF_MUST_USE_RESULT MutableType
Release(int number, FieldType /* field_type */, ExtensionSet* set) {
@ -1422,7 +1423,7 @@ class RepeatedMessageTypeTraits {
static inline MutableType Add(int number, FieldType field_type,
ExtensionSet* set) {
return static_cast<Type*>(
set->AddMessage(number, field_type, Type::default_instance(), NULL));
set->AddMessage(number, field_type, Type::default_instance(), nullptr));
}
static inline const RepeatedPtrField<Type>& GetRepeated(
int number, const ExtensionSet& set) {
@ -1439,7 +1440,7 @@ class RepeatedMessageTypeTraits {
bool is_packed,
ExtensionSet* set) {
return reinterpret_cast<RepeatedPtrField<Type>*>(
set->MutableRawRepeatedField(number, field_type, is_packed, NULL));
set->MutableRawRepeatedField(number, field_type, is_packed, nullptr));
}
static const RepeatedFieldType* GetDefaultRepeatedField();

@ -157,7 +157,7 @@ const MessageLite& ExtensionSet::GetMessage(int number,
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL, MESSAGE);
if (extension->is_lazy) {
return extension->lazymessage_value->GetMessage(
*factory->GetPrototype(message_type));
*factory->GetPrototype(message_type), arena_);
} else {
return *extension->message_value;
}
@ -194,14 +194,14 @@ MessageLite* ExtensionSet::ReleaseMessage(const FieldDescriptor* descriptor,
MessageFactory* factory) {
Extension* extension = FindOrNull(descriptor->number());
if (extension == nullptr) {
// Not present. Return NULL.
// Not present. Return nullptr.
return nullptr;
} else {
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL, MESSAGE);
MessageLite* ret = nullptr;
if (extension->is_lazy) {
ret = extension->lazymessage_value->ReleaseMessage(
*factory->GetPrototype(descriptor->message_type()));
*factory->GetPrototype(descriptor->message_type()), arena_);
if (arena_ == nullptr) {
delete extension->lazymessage_value;
}
@ -222,14 +222,14 @@ MessageLite* ExtensionSet::UnsafeArenaReleaseMessage(
const FieldDescriptor* descriptor, MessageFactory* factory) {
Extension* extension = FindOrNull(descriptor->number());
if (extension == nullptr) {
// Not present. Return NULL.
// Not present. Return nullptr.
return nullptr;
} else {
GOOGLE_DCHECK_TYPE(*extension, OPTIONAL, MESSAGE);
MessageLite* ret = nullptr;
if (extension->is_lazy) {
ret = extension->lazymessage_value->UnsafeArenaReleaseMessage(
*factory->GetPrototype(descriptor->message_type()));
*factory->GetPrototype(descriptor->message_type()), arena_);
if (arena_ == nullptr) {
delete extension->lazymessage_value;
}
@ -313,7 +313,7 @@ bool DescriptorPoolExtensionFinder::Find(int number, ExtensionInfo* output) {
output->message_info.prototype =
factory_->GetPrototype(extension->message_type());
GOOGLE_CHECK(output->message_info.prototype != nullptr)
<< "Extension factory's GetPrototype() returned NULL for extension: "
<< "Extension factory's GetPrototype() returned nullptr; extension: "
<< extension->full_name();
} else if (extension->cpp_type() == FieldDescriptor::CPPTYPE_ENUM) {
output->enum_validity_check.func = ValidateEnumUsingDescriptor;

@ -170,9 +170,9 @@ TEST(ExtensionSetTest, SetAllocatedExtension) {
message.SetAllocatedExtension(unittest::optional_foreign_message_extension,
new unittest::ForeignMessage());
// SetAllocatedExtension with a NULL parameter is equivalent to ClearExtenion.
// SetAllocatedExtension with nullptr is equivalent to ClearExtenion.
message.SetAllocatedExtension(unittest::optional_foreign_message_extension,
NULL);
nullptr);
EXPECT_FALSE(
message.HasExtension(unittest::optional_foreign_message_extension));
}
@ -204,7 +204,7 @@ TEST(ExtensionSetTest, ReleaseExtension) {
unittest::TestMessageSetExtension1::message_set_extension);
released_extension = message.ReleaseExtension(
unittest::TestMessageSetExtension1::message_set_extension);
EXPECT_TRUE(released_extension != NULL);
EXPECT_TRUE(released_extension != nullptr);
delete released_extension;
}
@ -457,7 +457,7 @@ TEST(ExtensionSetTest, SwapExtensionBothFullWithArena) {
message2->SetExtension(unittest::optional_int32_extension, 101);
TestUtil::ExpectAllExtensionsSet(*message1);
TestUtil::ExpectAllExtensionsSet(*message2);
arena2.reset(NULL);
arena2.reset(nullptr);
TestUtil::ExpectAllExtensionsSet(*message1);
// Test corner cases, when one is empty and other is not.
Arena arena3, arena4;
@ -1205,7 +1205,7 @@ TEST(ExtensionSetTest, DynamicExtensions) {
// Now build the file, using the generated pool as an underlay.
DescriptorPool dynamic_pool(DescriptorPool::generated_pool());
const FileDescriptor* file = dynamic_pool.BuildFile(dynamic_proto);
ASSERT_TRUE(file != NULL);
ASSERT_TRUE(file != nullptr);
DynamicMessageFactory dynamic_factory(&dynamic_pool);
dynamic_factory.SetDelegateToGeneratedFactory(true);
@ -1292,7 +1292,7 @@ TEST(ExtensionSetTest, DynamicExtensions) {
{
const FieldDescriptor* message_extension =
file->FindExtensionByName("message_extension");
ASSERT_TRUE(message_extension != NULL);
ASSERT_TRUE(message_extension != nullptr);
const Message& sub_message =
message.GetReflection()->GetMessage(message, message_extension);
const unittest::ForeignMessage* typed_sub_message =
@ -1301,7 +1301,7 @@ TEST(ExtensionSetTest, DynamicExtensions) {
#else
static_cast<const unittest::ForeignMessage*>(&sub_message);
#endif
ASSERT_TRUE(typed_sub_message != NULL);
ASSERT_TRUE(typed_sub_message != nullptr);
EXPECT_EQ(456, typed_sub_message->c());
}
@ -1310,7 +1310,7 @@ TEST(ExtensionSetTest, DynamicExtensions) {
{
const FieldDescriptor* dynamic_message_extension =
file->FindExtensionByName("dynamic_message_extension");
ASSERT_TRUE(dynamic_message_extension != NULL);
ASSERT_TRUE(dynamic_message_extension != nullptr);
const Message& parent = unittest::TestAllExtensions::default_instance();
const Message& sub_message = parent.GetReflection()->GetMessage(
parent, dynamic_message_extension, &dynamic_factory);

@ -97,7 +97,7 @@ FieldMask::FieldMask(const FieldMask& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.FieldMask)
}
void FieldMask::SharedCtor() {
inline void FieldMask::SharedCtor() {
}
FieldMask::~FieldMask() {

@ -2626,19 +2626,19 @@ void Reflection::ClearOneof(Message* message,
}
}
#define HANDLE_TYPE(TYPE, CPPTYPE, CTYPE) \
template <> \
const RepeatedField<TYPE>& Reflection::GetRepeatedFieldInternal<TYPE>( \
const Message& message, const FieldDescriptor* field) const { \
return *static_cast<RepeatedField<TYPE>*>(MutableRawRepeatedField( \
const_cast<Message*>(&message), field, CPPTYPE, CTYPE, NULL)); \
} \
\
template <> \
RepeatedField<TYPE>* Reflection::MutableRepeatedFieldInternal<TYPE>( \
Message * message, const FieldDescriptor* field) const { \
return static_cast<RepeatedField<TYPE>*>( \
MutableRawRepeatedField(message, field, CPPTYPE, CTYPE, NULL)); \
#define HANDLE_TYPE(TYPE, CPPTYPE, CTYPE) \
template <> \
const RepeatedField<TYPE>& Reflection::GetRepeatedFieldInternal<TYPE>( \
const Message& message, const FieldDescriptor* field) const { \
return *static_cast<RepeatedField<TYPE>*>(MutableRawRepeatedField( \
const_cast<Message*>(&message), field, CPPTYPE, CTYPE, nullptr)); \
} \
\
template <> \
RepeatedField<TYPE>* Reflection::MutableRepeatedFieldInternal<TYPE>( \
Message * message, const FieldDescriptor* field) const { \
return static_cast<RepeatedField<TYPE>*>( \
MutableRawRepeatedField(message, field, CPPTYPE, CTYPE, nullptr)); \
}
HANDLE_TYPE(int32_t, FieldDescriptor::CPPTYPE_INT32, -1);
@ -2657,7 +2657,7 @@ void* Reflection::MutableRawRepeatedString(Message* message,
bool is_string) const {
return MutableRawRepeatedField(message, field,
FieldDescriptor::CPPTYPE_STRING,
FieldOptions::STRING, NULL);
FieldOptions::STRING, nullptr);
}
// Template implementations of basic accessors. Inline because each

@ -83,7 +83,7 @@ namespace {
const FieldDescriptor* F(const std::string& name) {
const FieldDescriptor* result =
unittest::TestAllTypes::descriptor()->FindFieldByName(name);
GOOGLE_CHECK(result != NULL);
GOOGLE_CHECK(result != nullptr);
return result;
}
@ -710,13 +710,14 @@ TEST(GeneratedMessageReflectionTest, FindExtensionTypeByNumber) {
reflection->FindKnownExtensionByNumber(extension2->number()));
// Non-existent extension.
EXPECT_TRUE(reflection->FindKnownExtensionByNumber(62341) == NULL);
EXPECT_TRUE(reflection->FindKnownExtensionByNumber(62341) == nullptr);
// Extensions of TestAllExtensions should not show up as extensions of
// other types.
EXPECT_TRUE(unittest::TestAllTypes::default_instance()
.GetReflection()
->FindKnownExtensionByNumber(extension1->number()) == NULL);
->FindKnownExtensionByNumber(extension1->number()) ==
nullptr);
}
TEST(GeneratedMessageReflectionTest, FindKnownExtensionByName) {
@ -736,13 +737,14 @@ TEST(GeneratedMessageReflectionTest, FindKnownExtensionByName) {
reflection->FindKnownExtensionByName(extension2->full_name()));
// Non-existent extension.
EXPECT_TRUE(reflection->FindKnownExtensionByName("no_such_ext") == NULL);
EXPECT_TRUE(reflection->FindKnownExtensionByName("no_such_ext") == nullptr);
// Extensions of TestAllExtensions should not show up as extensions of
// other types.
EXPECT_TRUE(unittest::TestAllTypes::default_instance()
.GetReflection()
->FindKnownExtensionByName(extension1->full_name()) == NULL);
->FindKnownExtensionByName(extension1->full_name()) ==
nullptr);
}
@ -755,11 +757,11 @@ TEST(GeneratedMessageReflectionTest, SetAllocatedMessageTest) {
reflection_tester.SetAllFieldsViaReflection(&from_message1);
reflection_tester.SetAllFieldsViaReflection(&from_message2);
// Before moving fields, we expect the nested messages to be NULL.
// Before moving fields, we expect the nested messages to be nullptr.
reflection_tester.ExpectMessagesReleasedViaReflection(
&to_message, TestUtil::ReflectionTester::IS_NULL);
// After fields are moved we should get non-NULL releases.
// After fields are moved we should get non-nullptr releases.
reflection_tester.SetAllocatedOptionalMessageFieldsToMessageViaReflection(
&from_message1, &to_message);
reflection_tester.ExpectMessagesReleasedViaReflection(
@ -772,7 +774,7 @@ TEST(GeneratedMessageReflectionTest, SetAllocatedMessageTest) {
&to_message, TestUtil::ReflectionTester::NOT_NULL);
// After SetAllocatedOptionalMessageFieldsToNullViaReflection() we expect the
// releases to be NULL again.
// releases to be nullptr again.
reflection_tester.SetAllocatedOptionalMessageFieldsToNullViaReflection(
&to_message);
reflection_tester.ExpectMessagesReleasedViaReflection(
@ -790,11 +792,11 @@ TEST(GeneratedMessageReflectionTest, SetAllocatedMessageOnArenaTest) {
reflection_tester.SetAllFieldsViaReflection(&from_message1);
reflection_tester.SetAllFieldsViaReflection(&from_message2);
// Before moving fields, we expect the nested messages to be NULL.
// Before moving fields, we expect the nested messages to be nullptr.
reflection_tester.ExpectMessagesReleasedViaReflection(
to_message, TestUtil::ReflectionTester::IS_NULL);
// After fields are moved we should get non-NULL releases.
// After fields are moved we should get non-nullptr releases.
reflection_tester.SetAllocatedOptionalMessageFieldsToMessageViaReflection(
&from_message1, to_message);
reflection_tester.ExpectMessagesReleasedViaReflection(
@ -807,7 +809,7 @@ TEST(GeneratedMessageReflectionTest, SetAllocatedMessageOnArenaTest) {
to_message, TestUtil::ReflectionTester::NOT_NULL);
// After SetAllocatedOptionalMessageFieldsToNullViaReflection() we expect the
// releases to be NULL again.
// releases to be nullptr again.
reflection_tester.SetAllocatedOptionalMessageFieldsToNullViaReflection(
to_message);
reflection_tester.ExpectMessagesReleasedViaReflection(
@ -823,11 +825,11 @@ TEST(GeneratedMessageReflectionTest, SetAllocatedExtensionMessageTest) {
reflection_tester.SetAllFieldsViaReflection(&from_message1);
reflection_tester.SetAllFieldsViaReflection(&from_message2);
// Before moving fields, we expect the nested messages to be NULL.
// Before moving fields, we expect the nested messages to be nullptr.
reflection_tester.ExpectMessagesReleasedViaReflection(
&to_message, TestUtil::ReflectionTester::IS_NULL);
// After fields are moved we should get non-NULL releases.
// After fields are moved we should get non-nullptr releases.
reflection_tester.SetAllocatedOptionalMessageFieldsToMessageViaReflection(
&from_message1, &to_message);
reflection_tester.ExpectMessagesReleasedViaReflection(
@ -840,7 +842,7 @@ TEST(GeneratedMessageReflectionTest, SetAllocatedExtensionMessageTest) {
&to_message, TestUtil::ReflectionTester::NOT_NULL);
// After SetAllocatedOptionalMessageFieldsToNullViaReflection() we expect the
// releases to be NULL again.
// releases to be nullptr again.
reflection_tester.SetAllocatedOptionalMessageFieldsToNullViaReflection(
&to_message);
reflection_tester.ExpectMessagesReleasedViaReflection(
@ -858,11 +860,11 @@ TEST(GeneratedMessageReflectionTest, SetAllocatedExtensionMessageOnArenaTest) {
reflection_tester.SetAllFieldsViaReflection(&from_message1);
reflection_tester.SetAllFieldsViaReflection(&from_message2);
// Before moving fields, we expect the nested messages to be NULL.
// Before moving fields, we expect the nested messages to be nullptr.
reflection_tester.ExpectMessagesReleasedViaReflection(
to_message, TestUtil::ReflectionTester::IS_NULL);
// After fields are moved we should get non-NULL releases.
// After fields are moved we should get non-nullptr releases.
reflection_tester.SetAllocatedOptionalMessageFieldsToMessageViaReflection(
&from_message1, to_message);
reflection_tester.ExpectMessagesReleasedViaReflection(
@ -875,7 +877,7 @@ TEST(GeneratedMessageReflectionTest, SetAllocatedExtensionMessageOnArenaTest) {
to_message, TestUtil::ReflectionTester::NOT_NULL);
// After SetAllocatedOptionalMessageFieldsToNullViaReflection() we expect the
// releases to be NULL again.
// releases to be nullptr again.
reflection_tester.SetAllocatedOptionalMessageFieldsToNullViaReflection(
to_message);
reflection_tester.ExpectMessagesReleasedViaReflection(
@ -1027,10 +1029,10 @@ TEST(GeneratedMessageReflectionTest, SetAllocatedOneofMessageTest) {
Message* released = reflection->ReleaseMessage(
&to_message, descriptor->FindFieldByName("foo_lazy_message"));
EXPECT_TRUE(released == NULL);
EXPECT_TRUE(released == nullptr);
released = reflection->ReleaseMessage(
&to_message, descriptor->FindFieldByName("foo_message"));
EXPECT_TRUE(released == NULL);
EXPECT_TRUE(released == nullptr);
TestUtil::ReflectionTester::SetOneofViaReflection(&from_message1);
TestUtil::ReflectionTester::ExpectOneofSetViaReflection(from_message1);
@ -1043,7 +1045,7 @@ TEST(GeneratedMessageReflectionTest, SetAllocatedOneofMessageTest) {
(void)sub_message; // unused in somce configurations
released = reflection->ReleaseMessage(
&to_message, descriptor->FindFieldByName("foo_lazy_message"));
EXPECT_TRUE(released != NULL);
EXPECT_TRUE(released != nullptr);
EXPECT_EQ(&sub_message, released);
delete released;
@ -1061,7 +1063,7 @@ TEST(GeneratedMessageReflectionTest, SetAllocatedOneofMessageTest) {
(void)sub_message2; // unused in somce configurations
released = reflection->ReleaseMessage(
&to_message, descriptor->FindFieldByName("foo_message"));
EXPECT_TRUE(released != NULL);
EXPECT_TRUE(released != nullptr);
EXPECT_EQ(&sub_message2, released);
delete released;
}
@ -1077,10 +1079,10 @@ TEST(GeneratedMessageReflectionTest, SetAllocatedOneofMessageOnArenaTest) {
Message* released = reflection->ReleaseMessage(
to_message, descriptor->FindFieldByName("foo_lazy_message"));
EXPECT_TRUE(released == NULL);
EXPECT_TRUE(released == nullptr);
released = reflection->ReleaseMessage(
to_message, descriptor->FindFieldByName("foo_message"));
EXPECT_TRUE(released == NULL);
EXPECT_TRUE(released == nullptr);
TestUtil::ReflectionTester::SetOneofViaReflection(&from_message1);
TestUtil::ReflectionTester::ExpectOneofSetViaReflection(from_message1);
@ -1092,7 +1094,7 @@ TEST(GeneratedMessageReflectionTest, SetAllocatedOneofMessageOnArenaTest) {
*to_message, descriptor->FindFieldByName("foo_lazy_message"));
released = reflection->ReleaseMessage(
to_message, descriptor->FindFieldByName("foo_lazy_message"));
EXPECT_TRUE(released != NULL);
EXPECT_TRUE(released != nullptr);
// Since sub_message is arena allocated, releasing it results in copying it
// into new heap-allocated memory.
EXPECT_NE(&sub_message, released);
@ -1111,7 +1113,7 @@ TEST(GeneratedMessageReflectionTest, SetAllocatedOneofMessageOnArenaTest) {
*to_message, descriptor->FindFieldByName("foo_message"));
released = reflection->ReleaseMessage(
to_message, descriptor->FindFieldByName("foo_message"));
EXPECT_TRUE(released != NULL);
EXPECT_TRUE(released != nullptr);
// Since sub_message2 is arena allocated, releasing it results in copying it
// into new heap-allocated memory.
EXPECT_NE(&sub_message2, released);
@ -1123,11 +1125,11 @@ TEST(GeneratedMessageReflectionTest, ReleaseMessageTest) {
TestUtil::ReflectionTester reflection_tester(
unittest::TestAllTypes::descriptor());
// When nothing is set, we expect all released messages to be NULL.
// When nothing is set, we expect all released messages to be nullptr.
reflection_tester.ExpectMessagesReleasedViaReflection(
&message, TestUtil::ReflectionTester::IS_NULL);
// After fields are set we should get non-NULL releases.
// After fields are set we should get non-nullptr releases.
reflection_tester.SetAllFieldsViaReflection(&message);
reflection_tester.ExpectMessagesReleasedViaReflection(
&message, TestUtil::ReflectionTester::NOT_NULL);
@ -1149,11 +1151,11 @@ TEST(GeneratedMessageReflectionTest, ReleaseExtensionMessageTest) {
TestUtil::ReflectionTester reflection_tester(
unittest::TestAllExtensions::descriptor());
// When nothing is set, we expect all released messages to be NULL.
// When nothing is set, we expect all released messages to be nullptr.
reflection_tester.ExpectMessagesReleasedViaReflection(
&message, TestUtil::ReflectionTester::IS_NULL);
// After fields are set we should get non-NULL releases.
// After fields are set we should get non-nullptr releases.
reflection_tester.SetAllFieldsViaReflection(&message);
reflection_tester.ExpectMessagesReleasedViaReflection(
&message, TestUtil::ReflectionTester::NOT_NULL);
@ -1182,13 +1184,13 @@ TEST(GeneratedMessageReflectionTest, ReleaseOneofMessageTest) {
Message* released = reflection->ReleaseMessage(
&message, descriptor->FindFieldByName("foo_lazy_message"));
EXPECT_TRUE(released != NULL);
EXPECT_TRUE(released != nullptr);
EXPECT_EQ(&sub_message, released);
delete released;
released = reflection->ReleaseMessage(
&message, descriptor->FindFieldByName("foo_lazy_message"));
EXPECT_TRUE(released == NULL);
EXPECT_TRUE(released == nullptr);
}
TEST(GeneratedMessageReflectionTest, ArenaReleaseMessageTest) {
@ -1198,11 +1200,11 @@ TEST(GeneratedMessageReflectionTest, ArenaReleaseMessageTest) {
TestUtil::ReflectionTester reflection_tester(
unittest::TestAllTypes::descriptor());
// When nothing is set, we expect all released messages to be NULL.
// When nothing is set, we expect all released messages to be nullptr.
reflection_tester.ExpectMessagesReleasedViaReflection(
message, TestUtil::ReflectionTester::IS_NULL);
// After fields are set we should get non-NULL releases.
// After fields are set we should get non-nullptr releases.
reflection_tester.SetAllFieldsViaReflection(message);
reflection_tester.ExpectMessagesReleasedViaReflection(
message, TestUtil::ReflectionTester::NOT_NULL);
@ -1222,11 +1224,11 @@ TEST(GeneratedMessageReflectionTest, ArenaReleaseExtensionMessageTest) {
TestUtil::ReflectionTester reflection_tester(
unittest::TestAllExtensions::descriptor());
// When nothing is set, we expect all released messages to be NULL.
// When nothing is set, we expect all released messages to be nullptr.
reflection_tester.ExpectMessagesReleasedViaReflection(
message, TestUtil::ReflectionTester::IS_NULL);
// After fields are set we should get non-NULL releases.
// After fields are set we should get non-nullptr releases.
reflection_tester.SetAllFieldsViaReflection(message);
reflection_tester.ExpectMessagesReleasedViaReflection(
message, TestUtil::ReflectionTester::NOT_NULL);
@ -1250,12 +1252,12 @@ TEST(GeneratedMessageReflectionTest, ArenaReleaseOneofMessageTest) {
Message* released = reflection->ReleaseMessage(
message, descriptor->FindFieldByName("foo_lazy_message"));
EXPECT_TRUE(released != NULL);
EXPECT_TRUE(released != nullptr);
delete released;
released = reflection->ReleaseMessage(
message, descriptor->FindFieldByName("foo_lazy_message"));
EXPECT_TRUE(released == NULL);
EXPECT_TRUE(released == nullptr);
}
#ifdef PROTOBUF_HAS_DEATH_TEST

@ -74,14 +74,14 @@ struct UnknownFieldHandler {
static bool ParseExtension(MessageLite* msg, const ParseTable& table,
io::CodedInputStream* input, int tag) {
ExtensionSet* extensions = GetExtensionSet(msg, table.extension_offset);
if (extensions == NULL) {
if (extensions == nullptr) {
return false;
}
const Message* prototype =
down_cast<const Message*>(table.default_instance());
GOOGLE_DCHECK(prototype != NULL);
GOOGLE_DCHECK(prototype != nullptr);
GOOGLE_DCHECK(table.unknown_field_set);
UnknownFieldSet* unknown_fields =
MutableUnknownFields(msg, table.arena_offset);

@ -78,7 +78,7 @@ struct UnknownFieldHandlerLite {
static bool ParseExtension(MessageLite* msg, const ParseTable& table,
io::CodedInputStream* input, int tag) {
ExtensionSet* extensions = GetExtensionSet(msg, table.extension_offset);
if (extensions == NULL) {
if (extensions == nullptr) {
return false;
}

@ -83,7 +83,7 @@ inline const Type* Raw(const MessageLite* msg, int64_t offset) {
inline ExtensionSet* GetExtensionSet(MessageLite* msg,
int64_t extension_offset) {
if (extension_offset == -1) {
return NULL;
return nullptr;
}
return Raw<ExtensionSet>(msg, extension_offset);
@ -148,7 +148,7 @@ inline void ClearOneofField(const ParseTableField& field, Arena* arena,
MessageLite* msg) {
switch (field.processing_type & kTypeMask) {
case WireFormatLite::TYPE_MESSAGE:
if (arena == NULL) {
if (arena == nullptr) {
delete *Raw<MessageLite*>(msg, field.offset);
}
break;
@ -161,7 +161,7 @@ inline void ClearOneofField(const ParseTableField& field, Arena* arena,
case TYPE_STRING_INLINED:
case TYPE_BYTES_INLINED:
Raw<InlinedStringField>(msg, field.offset)->DestroyNoArena(NULL);
Raw<InlinedStringField>(msg, field.offset)->DestroyNoArena(nullptr);
break;
default:
@ -347,11 +347,11 @@ class RepeatedMessageTypeHandler {
return t->GetMaybeArenaPointer();
}
static inline Type* NewFromPrototype(const Type* prototype,
Arena* arena = NULL) {
Arena* arena = nullptr) {
return prototype->New(arena);
}
static void Delete(Type* t, Arena* arena = NULL) {
if (arena == NULL) {
static void Delete(Type* t, Arena* arena = nullptr) {
if (arena == nullptr) {
delete t;
}
}
@ -376,7 +376,7 @@ bool MergePartialFromCodedStreamInlined(MessageLite* msg,
// TODO(ckennelly): Make this a compile-time parameter with templates.
GOOGLE_DCHECK_GE(table.has_bits_offset, 0);
uint32_t* has_bits = Raw<uint32_t>(msg, table.has_bits_offset);
GOOGLE_DCHECK(has_bits != NULL);
GOOGLE_DCHECK(has_bits != nullptr);
while (true) {
uint32_t tag = input->ReadTagWithCutoffNoLastTag(kMaxTag).first;
@ -623,7 +623,7 @@ bool MergePartialFromCodedStreamInlined(MessageLite* msg,
MutableField<MessageLite*>(msg, has_bits, presence_index, offset);
MessageLite* submsg = *submsg_holder;
if (submsg == NULL) {
if (submsg == nullptr) {
Arena* const arena = msg->GetArena();
const MessageLite* prototype =
table.aux[field_number].messages.default_message();
@ -642,7 +642,7 @@ bool MergePartialFromCodedStreamInlined(MessageLite* msg,
RepeatedPtrFieldBase* field = Raw<RepeatedPtrFieldBase>(msg, offset);
const MessageLite* prototype =
table.aux[field_number].messages.default_message();
GOOGLE_DCHECK(prototype != NULL);
GOOGLE_DCHECK(prototype != nullptr);
MessageLite* submsg =
MergePartialFromCodedStreamHelper::Add(field, prototype);
@ -659,11 +659,11 @@ bool MergePartialFromCodedStreamInlined(MessageLite* msg,
MutableField<MessageLite*>(msg, has_bits, presence_index, offset);
MessageLite* submsg = *submsg_holder;
if (submsg == NULL) {
if (submsg == nullptr) {
Arena* const arena = msg->GetArena();
const MessageLite* prototype =
table.aux[field_number].messages.default_message();
if (prototype == NULL) {
if (prototype == nullptr) {
prototype = ImplicitWeakMessage::default_instance();
}
submsg = prototype->New(arena);
@ -683,7 +683,7 @@ bool MergePartialFromCodedStreamInlined(MessageLite* msg,
RepeatedPtrFieldBase* field = Raw<RepeatedPtrFieldBase>(msg, offset);
const MessageLite* prototype =
table.aux[field_number].messages.default_message();
if (prototype == NULL) {
if (prototype == nullptr) {
prototype = ImplicitWeakMessage::default_instance();
}
@ -703,7 +703,7 @@ bool MergePartialFromCodedStreamInlined(MessageLite* msg,
MessageLite** submsg_holder = Raw<MessageLite*>(msg, offset);
ResetOneofField<ProcessingType_MESSAGE>(
table, field_number, arena, msg, oneof_case + presence_index,
offset, NULL);
offset, nullptr);
MessageLite* submsg = *submsg_holder;
if (PROTOBUF_PREDICT_FALSE(

@ -591,12 +591,12 @@ bool IsNull<WireFormatLite::TYPE_BYTES>(const void* ptr) {
template <>
bool IsNull<WireFormatLite::TYPE_GROUP>(const void* ptr) {
return Get<const MessageLite*>(ptr) == NULL;
return Get<const MessageLite*>(ptr) == nullptr;
}
template <>
bool IsNull<WireFormatLite::TYPE_MESSAGE>(const void* ptr) {
return Get<const MessageLite*>(ptr) == NULL;
return Get<const MessageLite*>(ptr) == nullptr;
}
@ -739,7 +739,7 @@ MessageLite* DuplicateIfNonNullInternal(MessageLite* message) {
ret->CheckTypeAndMergeFrom(*message);
return ret;
} else {
return NULL;
return nullptr;
}
}
@ -761,7 +761,7 @@ MessageLite* GetOwnedMessageInternal(Arena* message_arena,
submessage_arena);
GOOGLE_DCHECK(message_arena != submessage_arena);
GOOGLE_DCHECK_EQ(submessage_arena, nullptr);
if (message_arena != NULL && submessage_arena == NULL) {
if (message_arena != nullptr && submessage_arena == nullptr) {
message_arena->Own(submessage);
return submessage;
} else {

@ -103,12 +103,12 @@ class ImplicitWeakTypeHandler {
static constexpr bool Moveable = false;
static inline MessageLite* NewFromPrototype(const MessageLite* prototype,
Arena* arena = NULL) {
Arena* arena = nullptr) {
return prototype->New(arena);
}
static inline void Delete(MessageLite* value, Arena* arena) {
if (arena == NULL) {
if (arena == nullptr) {
delete value;
}
}

@ -199,8 +199,8 @@ class PROTOBUF_EXPORT InlinedStringField {
uint32_t* donating_states, uint32_t mask);
// Release returns a std::string* instance that is heap-allocated and is not
// Own()'d by any arena. If the field is not set, this returns NULL. The
// caller retains ownership. Clears this field back to NULL state. Used to
// Own()'d by any arena. If the field is not set, this returns nullptr. The
// caller retains ownership. Clears this field back to nullptr state. Used to
// implement release_<field>() methods on generated classes.
PROTOBUF_MUST_USE_RESULT std::string* Release(
const std::string* default_value, Arena* arena, bool donated);
@ -248,9 +248,9 @@ class PROTOBUF_EXPORT InlinedStringField {
get_mutable()->clear();
}
// Clears content, but keeps allocated std::string if arena != NULL, to avoid
// the overhead of heap operations. After this returns, the content (as seen
// by the user) will always be equal to |default_value|.
// Clears content, but keeps allocated std::string if arena != nullptr, to
// avoid the overhead of heap operations. After this returns, the content (as
// seen by the user) will always be equal to |default_value|.
void ClearToDefault(const LazyString& default_value, Arena* arena,
bool donated);

@ -946,7 +946,7 @@ CodedOutputStream::~CodedOutputStream() { Trim(); }
uint8_t* CodedOutputStream::WriteStringWithSizeToArray(const std::string& str,
uint8_t* target) {
GOOGLE_DCHECK_LE(str.size(), kuint32max);
GOOGLE_DCHECK_LE(str.size(), std::numeric_limits<uint32_t>::max());
target = WriteVarint32ToArray(str.size(), target);
return WriteStringToArray(str, target);
}

@ -116,6 +116,7 @@
#include <climits>
#include <cstddef>
#include <cstring>
#include <limits>
#include <string>
#include <type_traits>
#include <utility>
@ -1551,7 +1552,7 @@ inline CodedInputStream::CodedInputStream(ZeroCopyInputStream* input)
last_tag_(0),
legitimate_message_end_(false),
aliasing_enabled_(false),
current_limit_(kint32max),
current_limit_(std::numeric_limits<int32_t>::max()),
buffer_size_after_limit_(0),
total_bytes_limit_(kDefaultTotalBytesLimit),
recursion_budget_(default_recursion_limit_),

@ -224,6 +224,21 @@ Tokenizer::~Tokenizer() {
}
}
bool Tokenizer::report_whitespace() const { return report_whitespace_; }
// Note: `set_report_whitespace(false)` implies `set_report_newlines(false)`.
void Tokenizer::set_report_whitespace(bool report) {
report_whitespace_ = report;
report_newlines_ &= report;
}
// If true, newline tokens are reported by Next().
bool Tokenizer::report_newlines() const { return report_newlines_; }
// Note: `set_report_newlines(true)` implies `set_report_whitespace(true)`.
void Tokenizer::set_report_newlines(bool report) {
report_newlines_ = report;
report_whitespace_ |= report; // enable report_whitespace if necessary
}
// -------------------------------------------------------------------
// Internal helpers.
@ -560,13 +575,46 @@ Tokenizer::NextCommentStatus Tokenizer::TryConsumeCommentStart() {
}
}
bool Tokenizer::TryConsumeWhitespace() {
if (report_newlines_) {
if (TryConsumeOne<WhitespaceNoNewline>()) {
ConsumeZeroOrMore<WhitespaceNoNewline>();
current_.type = TYPE_WHITESPACE;
return true;
}
return false;
}
if (TryConsumeOne<Whitespace>()) {
ConsumeZeroOrMore<Whitespace>();
current_.type = TYPE_WHITESPACE;
return report_whitespace_;
}
return false;
}
bool Tokenizer::TryConsumeNewline() {
if (!report_whitespace_ || !report_newlines_) {
return false;
}
if (TryConsume('\n')) {
current_.type = TYPE_NEWLINE;
return true;
}
return false;
}
// -------------------------------------------------------------------
bool Tokenizer::Next() {
previous_ = current_;
while (!read_error_) {
ConsumeZeroOrMore<Whitespace>();
StartToken();
bool report_token = TryConsumeWhitespace() || TryConsumeNewline();
EndToken();
if (report_token) {
return true;
}
switch (TryConsumeCommentStart()) {
case LINE_COMMENT:
@ -990,7 +1038,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) {
static uint32_t AssembleUTF16(uint32_t head_surrogate,
uint32_t trail_surrogate) {
GOOGLE_DCHECK(IsHeadSurrogate(head_surrogate));
GOOGLE_DCHECK(IsTrailSurrogate(trail_surrogate));
return 0x10000 + (((head_surrogate - kMinHeadSurrogate) << 10) |

@ -122,6 +122,13 @@ class PROTOBUF_EXPORT Tokenizer {
TYPE_SYMBOL, // Any other printable character, like '!' or '+'.
// Symbols are always a single character, so "!+$%" is
// four tokens.
TYPE_WHITESPACE, // A sequence of whitespace. This token type is only
// produced if report_whitespace() is true. It is not
// reported for whitespace within comments or strings.
TYPE_NEWLINE, // A newline (\n). This token type is only
// produced if report_whitespace() is true and
// report_newlines() is true. It is not reported for
// newlines in comments or strings.
};
// Structure representing a token read from the token stream.
@ -252,6 +259,16 @@ class PROTOBUF_EXPORT Tokenizer {
allow_multiline_strings_ = allow;
}
// If true, whitespace tokens are reported by Next().
// Note: `set_report_whitespace(false)` implies `set_report_newlines(false)`.
bool report_whitespace() const;
void set_report_whitespace(bool report);
// If true, newline tokens are reported by Next().
// Note: `set_report_newlines(true)` implies `set_report_whitespace(true)`.
bool report_newlines() const;
void set_report_newlines(bool report);
// External helper: validate an identifier.
static bool IsIdentifier(const std::string& text);
@ -287,6 +304,8 @@ class PROTOBUF_EXPORT Tokenizer {
CommentStyle comment_style_;
bool require_space_after_number_;
bool allow_multiline_strings_;
bool report_whitespace_ = false;
bool report_newlines_ = false;
// Since we count columns we need to interpret tabs somehow. We'll take
// the standard 8-character definition for lack of any way to do better.
@ -360,6 +379,14 @@ class PROTOBUF_EXPORT Tokenizer {
// of comment it is.
NextCommentStatus TryConsumeCommentStart();
// If we're looking at a TYPE_WHITESPACE token and `report_whitespace_` is
// true, consume it and return true.
bool TryConsumeWhitespace();
// If we're looking at a TYPE_NEWLINE token and `report_newlines_` is true,
// consume it and return true.
bool TryConsumeNewline();
// -----------------------------------------------------------------
// These helper methods make the parsing code more readable. The
// "character classes" referred to are defined at the top of the .cc file.

@ -317,6 +317,45 @@ TEST_1D(TokenizerTest, FloatSuffix, kBlockSizes) {
EXPECT_TRUE(error_collector.text_.empty());
}
SimpleTokenCase kWhitespaceTokenCases[] = {
{" ", Tokenizer::TYPE_WHITESPACE},
{" ", Tokenizer::TYPE_WHITESPACE},
{"\t", Tokenizer::TYPE_WHITESPACE},
{"\v", Tokenizer::TYPE_WHITESPACE},
{"\t ", Tokenizer::TYPE_WHITESPACE},
{"\v\t", Tokenizer::TYPE_WHITESPACE},
{" \t\r", Tokenizer::TYPE_WHITESPACE},
// Newlines:
{"\n", Tokenizer::TYPE_NEWLINE},
};
TEST_2D(TokenizerTest, Whitespace, kWhitespaceTokenCases, kBlockSizes) {
{
TestInputStream input(kWhitespaceTokenCases_case.input.data(),
kWhitespaceTokenCases_case.input.size(),
kBlockSizes_case);
TestErrorCollector error_collector;
Tokenizer tokenizer(&input, &error_collector);
EXPECT_FALSE(tokenizer.Next());
}
{
TestInputStream input(kWhitespaceTokenCases_case.input.data(),
kWhitespaceTokenCases_case.input.size(),
kBlockSizes_case);
TestErrorCollector error_collector;
Tokenizer tokenizer(&input, &error_collector);
tokenizer.set_report_whitespace(true);
tokenizer.set_report_newlines(true);
ASSERT_TRUE(tokenizer.Next());
EXPECT_EQ(tokenizer.current().text, kWhitespaceTokenCases_case.input);
EXPECT_EQ(tokenizer.current().type, kWhitespaceTokenCases_case.type);
EXPECT_FALSE(tokenizer.Next());
}
}
#endif
// -------------------------------------------------------------------
@ -476,6 +515,81 @@ TEST_2D(TokenizerTest, MultipleTokens, kMultiTokenCases, kBlockSizes) {
EXPECT_TRUE(error_collector.text_.empty());
}
MultiTokenCase kMultiWhitespaceTokenCases[] = {
// Test all token types at the same time.
{"foo 1 \t1.2 \n +\v'bar'",
{
{Tokenizer::TYPE_IDENTIFIER, "foo", 0, 0, 3},
{Tokenizer::TYPE_WHITESPACE, " ", 0, 3, 4},
{Tokenizer::TYPE_INTEGER, "1", 0, 4, 5},
{Tokenizer::TYPE_WHITESPACE, " \t", 0, 5, 8},
{Tokenizer::TYPE_FLOAT, "1.2", 0, 8, 11},
{Tokenizer::TYPE_WHITESPACE, " ", 0, 11, 13},
{Tokenizer::TYPE_NEWLINE, "\n", 0, 13, 0},
{Tokenizer::TYPE_WHITESPACE, " ", 1, 0, 3},
{Tokenizer::TYPE_SYMBOL, "+", 1, 3, 4},
{Tokenizer::TYPE_WHITESPACE, "\v", 1, 4, 5},
{Tokenizer::TYPE_STRING, "'bar'", 1, 5, 10},
{Tokenizer::TYPE_END, "", 1, 10, 10},
}},
};
TEST_2D(TokenizerTest, MultipleWhitespaceTokens, kMultiWhitespaceTokenCases,
kBlockSizes) {
// Set up the tokenizer.
TestInputStream input(kMultiWhitespaceTokenCases_case.input.data(),
kMultiWhitespaceTokenCases_case.input.size(),
kBlockSizes_case);
TestErrorCollector error_collector;
Tokenizer tokenizer(&input, &error_collector);
tokenizer.set_report_whitespace(true);
tokenizer.set_report_newlines(true);
// Before Next() is called, the initial token should always be TYPE_START.
EXPECT_EQ(Tokenizer::TYPE_START, tokenizer.current().type);
EXPECT_EQ("", tokenizer.current().text);
EXPECT_EQ(0, tokenizer.current().line);
EXPECT_EQ(0, tokenizer.current().column);
EXPECT_EQ(0, tokenizer.current().end_column);
// Loop through all expected tokens.
int i = 0;
Tokenizer::Token token;
do {
token = kMultiWhitespaceTokenCases_case.output[i++];
SCOPED_TRACE(testing::Message() << "Token #" << i << ": " << token.text);
Tokenizer::Token previous = tokenizer.current();
// Next() should only return false when it hits the end token.
if (token.type != Tokenizer::TYPE_END) {
ASSERT_TRUE(tokenizer.Next());
} else {
ASSERT_FALSE(tokenizer.Next());
}
// Check that the previous token is set correctly.
EXPECT_EQ(previous.type, tokenizer.previous().type);
EXPECT_EQ(previous.text, tokenizer.previous().text);
EXPECT_EQ(previous.line, tokenizer.previous().line);
EXPECT_EQ(previous.column, tokenizer.previous().column);
EXPECT_EQ(previous.end_column, tokenizer.previous().end_column);
// Check that the token matches the expected one.
EXPECT_EQ(token.type, tokenizer.current().type);
EXPECT_EQ(token.text, tokenizer.current().text);
EXPECT_EQ(token.line, tokenizer.current().line);
EXPECT_EQ(token.column, tokenizer.current().column);
EXPECT_EQ(token.end_column, tokenizer.current().end_column);
} while (token.type != Tokenizer::TYPE_END);
// There should be no errors.
EXPECT_TRUE(error_collector.text_.empty());
}
// This test causes gcc 3.3.5 (and earlier?) to give the cryptic error:
// "sorry, unimplemented: `method_call_expr' not supported by dump_expr"
#if !defined(__GNUC__) || __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3)

@ -194,7 +194,7 @@ class MapEntryImpl : public Base {
_has_bits_{} {}
~MapEntryImpl() {
if (Base::GetArenaForAllocation() != NULL) return;
if (Base::GetArenaForAllocation() != nullptr) return;
KeyTypeHandler::DeleteNoArena(key_);
ValueTypeHandler::DeleteNoArena(value_);
}

@ -40,7 +40,7 @@ namespace protobuf {
namespace internal {
MapFieldBase::~MapFieldBase() {
if (repeated_field_ != NULL && arena_ == NULL) delete repeated_field_;
if (repeated_field_ != nullptr && arena_ == nullptr) delete repeated_field_;
}
const RepeatedPtrFieldBase& MapFieldBase::GetRepeatedField() const {
@ -117,7 +117,7 @@ size_t MapFieldBase::SpaceUsedExcludingSelfLong() const {
}
size_t MapFieldBase::SpaceUsedExcludingSelfNoLock() const {
if (repeated_field_ != NULL) {
if (repeated_field_ != nullptr) {
return repeated_field_->SpaceUsedExcludingSelfLong();
} else {
return 0;
@ -187,7 +187,7 @@ void MapFieldBase::SyncRepeatedFieldWithMap() const {
}
void MapFieldBase::SyncRepeatedFieldWithMapNoLock() const {
if (repeated_field_ == NULL) {
if (repeated_field_ == nullptr) {
repeated_field_ = Arena::CreateMessage<RepeatedPtrField<Message> >(arena_);
}
}
@ -434,7 +434,7 @@ void DynamicMapField::SyncRepeatedFieldWithMapNoLock() const {
const Reflection* reflection = default_entry_->GetReflection();
const FieldDescriptor* key_des = default_entry_->GetDescriptor()->map_key();
const FieldDescriptor* val_des = default_entry_->GetDescriptor()->map_value();
if (MapFieldBase::repeated_field_ == NULL) {
if (MapFieldBase::repeated_field_ == nullptr) {
MapFieldBase::repeated_field_ =
Arena::CreateMessage<RepeatedPtrField<Message> >(MapFieldBase::arena_);
}
@ -597,7 +597,7 @@ void DynamicMapField::SyncMapWithRepeatedFieldNoLock() const {
size_t DynamicMapField::SpaceUsedExcludingSelfNoLock() const {
size_t size = 0;
if (MapFieldBase::repeated_field_ != NULL) {
if (MapFieldBase::repeated_field_ != nullptr) {
size += MapFieldBase::repeated_field_->SpaceUsedExcludingSelfLong();
}
size += sizeof(map_);

@ -324,7 +324,7 @@ class MapFieldAccessor;
class PROTOBUF_EXPORT MapFieldBase {
public:
MapFieldBase()
: arena_(NULL), repeated_field_(NULL), state_(STATE_MODIFIED_MAP) {}
: arena_(nullptr), repeated_field_(nullptr), state_(STATE_MODIFIED_MAP) {}
// This constructor is for constant initialized global instances.
// It uses a linker initialized mutex, so it is not compatible with regular
@ -577,15 +577,15 @@ class MapField : public TypeDefinedMapFieldBase<Key, T> {
void InternalSwap(MapField* other);
// Used in the implementation of parsing. Caller should take the ownership iff
// arena_ is NULL.
// arena_ is nullptr.
EntryType* NewEntry() const { return impl_.NewEntry(); }
// Used in the implementation of serializing enum value type. Caller should
// take the ownership iff arena_ is NULL.
// take the ownership iff arena_ is nullptr.
EntryType* NewEnumEntryWrapper(const Key& key, const T t) const {
return impl_.NewEnumEntryWrapper(key, t);
}
// Used in the implementation of serializing other value types. Caller should
// take the ownership iff arena_ is NULL.
// take the ownership iff arena_ is nullptr.
EntryType* NewEntryWrapper(const Key& key, const T& t) const {
return impl_.NewEntryWrapper(key, t);
}

@ -138,7 +138,7 @@ template <typename Key, typename T>
void TypeDefinedMapFieldBase<Key, T>::InitializeIterator(
MapIterator* map_iter) const {
map_iter->iter_ = new typename Map<Key, T>::const_iterator;
GOOGLE_CHECK(map_iter->iter_ != NULL);
GOOGLE_CHECK(map_iter->iter_ != nullptr);
}
template <typename Key, typename T>
@ -304,7 +304,7 @@ template <typename Derived, typename Key, typename T,
WireFormatLite::FieldType kValueFieldType>
void MapField<Derived, Key, T, kKeyFieldType,
kValueFieldType>::SyncRepeatedFieldWithMapNoLock() const {
if (this->MapFieldBase::repeated_field_ == NULL) {
if (this->MapFieldBase::repeated_field_ == nullptr) {
this->MapFieldBase::repeated_field_ =
Arena::CreateMessage<RepeatedPtrField<Message> >(
this->MapFieldBase::arena_);
@ -341,7 +341,7 @@ void MapField<Derived, Key, T, kKeyFieldType,
RepeatedPtrField<EntryType>* repeated_field =
reinterpret_cast<RepeatedPtrField<EntryType>*>(
this->MapFieldBase::repeated_field_);
GOOGLE_CHECK(this->MapFieldBase::repeated_field_ != NULL);
GOOGLE_CHECK(this->MapFieldBase::repeated_field_ != nullptr);
map->clear();
for (typename RepeatedPtrField<EntryType>::iterator it =
repeated_field->begin();
@ -361,7 +361,7 @@ template <typename Derived, typename Key, typename T,
size_t MapField<Derived, Key, T, kKeyFieldType,
kValueFieldType>::SpaceUsedExcludingSelfNoLock() const {
size_t size = 0;
if (this->MapFieldBase::repeated_field_ != NULL) {
if (this->MapFieldBase::repeated_field_ != nullptr) {
size += this->MapFieldBase::repeated_field_->SpaceUsedExcludingSelfLong();
}
size += impl_.GetMap().SpaceUsedExcludingSelfLong();

@ -84,17 +84,17 @@ class MapFieldLite {
void InternalSwap(MapFieldLite* other) { map_.InternalSwap(other->map_); }
// Used in the implementation of parsing. Caller should take the ownership iff
// arena_ is NULL.
// arena_ is nullptr.
EntryType* NewEntry() const {
return Arena::CreateMessage<EntryType>(map_.arena());
}
// Used in the implementation of serializing enum value type. Caller should
// take the ownership iff arena_ is NULL.
// take the ownership iff arena_ is nullptr.
EntryType* NewEnumEntryWrapper(const Key& key, const T t) const {
return EntryType::EnumWrap(key, t, map_.arena_);
}
// Used in the implementation of serializing other value types. Caller should
// take the ownership iff arena_ is NULL.
// take the ownership iff arena_ is nullptr.
EntryType* NewEntryWrapper(const Key& key, const T& t) const {
return EntryType::Wrap(key, t, map_.arena_);
}

@ -209,7 +209,7 @@ TEST_P(MapFieldBasePrimitiveTest, Arena) {
Arena::CreateMessage<MapFieldBaseStub>(&arena);
// Trigger conversion to repeated field.
EXPECT_TRUE(map_field->MutableRepeatedField() != NULL);
EXPECT_TRUE(map_field->MutableRepeatedField() != nullptr);
EXPECT_EQ(map_field->GetArenaForInternalRepeatedField(), &arena);
}
@ -308,7 +308,7 @@ class MapFieldStateTest
EXPECT_EQ(map_size, map->size());
if (is_repeated_null) {
EXPECT_TRUE(repeated_field == NULL);
EXPECT_TRUE(repeated_field == nullptr);
} else {
if (repeated_field == nullptr) {
EXPECT_EQ(repeated_size, 0);

@ -884,7 +884,7 @@ TEST_F(MapImplTest, CopyConstructorWithArena) {
}
TEST_F(MapImplTest, CopyConstructorWithoutArena) {
CopyConstructorHelper(NULL, &map_);
CopyConstructorHelper(nullptr, &map_);
}
TEST_F(MapImplTest, IterConstructor) {
@ -3040,8 +3040,8 @@ class MapFieldInDynamicMessageTest : public testing::Test {
std::string(UNITTEST_PACKAGE_NAME) + ".TestMap");
recursive_map_descriptor_ = pool_->FindMessageTypeByName(
std::string(UNITTEST_PACKAGE_NAME) + ".TestRecursiveMapMessage");
ASSERT_TRUE(map_descriptor_ != NULL);
ASSERT_TRUE(recursive_map_descriptor_ != NULL);
ASSERT_TRUE(map_descriptor_ != nullptr);
ASSERT_TRUE(recursive_map_descriptor_ != nullptr);
map_prototype_ = factory_.GetPrototype(map_descriptor_);
}
};
@ -3781,7 +3781,7 @@ TEST(ArenaTest, StringMapNoLeak) {
}
(*message->mutable_map_string_string())[data] = data;
// We rely on heap checkers to detect memory leak for us.
ASSERT_FALSE(message == NULL);
ASSERT_FALSE(message == nullptr);
}
TEST(ArenaTest, IsInitialized) {

@ -510,7 +510,7 @@ inline size_t MapTypeHandler<WireFormatLite::TYPE_MESSAGE,
template <typename Type>
inline void MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::Clear(
Type** value, Arena* /* arena */) {
if (*value != NULL) (*value)->Clear();
if (*value != nullptr) (*value)->Clear();
}
template <typename Type>
inline void MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::Merge(
@ -533,7 +533,7 @@ constexpr auto MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::Constinit()
template <typename Type>
inline Type* MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::EnsureMutable(
Type** value, Arena* arena) {
if (*value == NULL) {
if (*value == nullptr) {
*value = MapArenaMessageCreator<
Type,
Arena::is_arena_constructable<Type>::type::value>::CreateMessage(arena);
@ -545,7 +545,7 @@ template <typename Type>
inline const Type&
MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::DefaultIfNotInitialized(
const Type* value) {
return value != NULL ? *value : *Type::internal_default_instance();
return value != nullptr ? *value : *Type::internal_default_instance();
}
template <typename Type>

@ -275,35 +275,35 @@ const Message* GeneratedMessageFactory::GetPrototype(const Descriptor* type) {
{
ReaderMutexLock lock(&mutex_);
const Message* result = FindPtrOrNull(type_map_, type);
if (result != NULL) return result;
if (result != nullptr) return result;
}
// If the type is not in the generated pool, then we can't possibly handle
// it.
if (type->file()->pool() != DescriptorPool::generated_pool()) return NULL;
if (type->file()->pool() != DescriptorPool::generated_pool()) return nullptr;
// Apparently the file hasn't been registered yet. Let's do that now.
const internal::DescriptorTable* registration_data =
FindPtrOrNull(file_map_, type->file()->name().c_str());
if (registration_data == NULL) {
if (registration_data == nullptr) {
GOOGLE_LOG(DFATAL) << "File appears to be in generated pool but wasn't "
"registered: "
<< type->file()->name();
return NULL;
return nullptr;
}
WriterMutexLock lock(&mutex_);
// Check if another thread preempted us.
const Message* result = FindPtrOrNull(type_map_, type);
if (result == NULL) {
if (result == nullptr) {
// Nope. OK, register everything.
internal::RegisterFileLevelMetadata(registration_data);
// Should be here now.
result = FindPtrOrNull(type_map_, type);
}
if (result == NULL) {
if (result == nullptr) {
GOOGLE_LOG(DFATAL) << "Type appears to be in generated pool but wasn't "
<< "registered: " << type->full_name();
}
@ -367,7 +367,7 @@ const internal::RepeatedFieldAccessor* Reflection::RepeatedFieldAccessor(
}
}
GOOGLE_LOG(FATAL) << "Should not reach here.";
return NULL;
return nullptr;
}
namespace internal {

@ -197,7 +197,7 @@ template bool MergeFromImpl<true>(BoundedZCIS input, MessageLite* msg,
MessageLite* MessageLite::New(Arena* arena) const {
MessageLite* message = New();
if (arena != NULL) {
if (arena != nullptr) {
arena->Own(message);
}
return message;

@ -218,7 +218,7 @@ class PROTOBUF_EXPORT MessageLite {
virtual MessageLite* New() const = 0;
// Construct a new instance on the arena. Ownership is passed to the caller
// if arena is a NULL. Default implementation for backwards compatibility.
// if arena is a nullptr. Default implementation for backwards compatibility.
virtual MessageLite* New(Arena* arena) const;
// Same as GetOwningArena.
@ -520,7 +520,7 @@ class PROTOBUF_EXPORT MessageLite {
private:
// TODO(gerbens) make this a pure abstract function
virtual const void* InternalGetTable() const { return NULL; }
virtual const void* InternalGetTable() const { return nullptr; }
friend class FastReflectionMessageMutator;
friend class FastReflectionStringSetter;

@ -39,6 +39,8 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <limits>
#include <google/protobuf/message.h>
#ifndef _MSC_VER
#include <unistd.h>
@ -487,6 +489,8 @@ class RepeatedInputStream : public io::ZeroCopyInputStream {
} // namespace
TEST(MESSAGE_TEST_NAME, TestParseMessagesCloseTo2G) {
constexpr int32_t kint32max = std::numeric_limits<int32_t>::max();
// Create a message with a large std::string field.
std::string value = std::string(64 * 1024 * 1024, 'x');
UNITTEST::TestAllTypes message;

@ -188,7 +188,7 @@ class InternalMetadata {
template <typename T>
PROTOBUF_NOINLINE void DeleteOutOfLineHelper() {
if (arena() == NULL) {
if (arena() == nullptr) {
delete PtrValue<Container<T>>();
}
}

@ -395,7 +395,7 @@
// choose 16 rather than some other number just in case the compiler would
// be confused by an unaligned pointer.
#define PROTOBUF_FIELD_OFFSET(TYPE, FIELD) \
static_cast< ::google::protobuf::uint32>(reinterpret_cast<const char*>( \
static_cast< ::uint32_t>(reinterpret_cast<const char*>( \
&reinterpret_cast<const TYPE*>(16)->FIELD) - \
reinterpret_cast<const char*>(16))
#endif

@ -245,7 +245,7 @@ TEST(PreserveUnknownEnumTest, Proto2CatchesUnknownValues) {
// SetRepeatedEnumValue.
const EnumValueDescriptor* enum_value =
repeated_field->enum_type()->FindValueByName("BAR");
EXPECT_TRUE(enum_value != NULL);
EXPECT_TRUE(enum_value != nullptr);
r->AddEnum(&message, repeated_field, enum_value);
const FieldDescriptor* singular_field =

@ -92,7 +92,7 @@ class RepeatedFieldRef<
const Reflection* reflection = message.GetReflection();
data_ = reflection->RepeatedFieldData(const_cast<Message*>(&message), field,
internal::RefTypeTraits<T>::cpp_type,
NULL);
nullptr);
accessor_ = reflection->RepeatedFieldAccessor(field);
}
@ -143,7 +143,7 @@ class MutableRepeatedFieldRef<
MutableRepeatedFieldRef(Message* message, const FieldDescriptor* field) {
const Reflection* reflection = message->GetReflection();
data_ = reflection->RepeatedFieldData(
message, field, internal::RefTypeTraits<T>::cpp_type, NULL);
message, field, internal::RefTypeTraits<T>::cpp_type, nullptr);
accessor_ = reflection->RepeatedFieldAccessor(field);
}
@ -504,7 +504,7 @@ struct RefTypeTraits<
typedef T* IteratorPointerType;
static constexpr FieldDescriptor::CppType cpp_type =
PrimitiveTraits<T>::cpp_type;
static const Descriptor* GetMessageFieldDescriptor() { return NULL; }
static const Descriptor* GetMessageFieldDescriptor() { return nullptr; }
};
template <typename T>
@ -518,7 +518,7 @@ struct RefTypeTraits<
typedef int32_t* IteratorPointerType;
static constexpr FieldDescriptor::CppType cpp_type =
FieldDescriptor::CPPTYPE_ENUM;
static const Descriptor* GetMessageFieldDescriptor() { return NULL; }
static const Descriptor* GetMessageFieldDescriptor() { return nullptr; }
};
template <typename T>
@ -531,7 +531,7 @@ struct RefTypeTraits<
typedef const std::string* IteratorPointerType;
static constexpr FieldDescriptor::CppType cpp_type =
FieldDescriptor::CPPTYPE_STRING;
static const Descriptor* GetMessageFieldDescriptor() { return NULL; }
static const Descriptor* GetMessageFieldDescriptor() { return nullptr; }
};
template <typename T>
@ -542,7 +542,7 @@ struct MessageDescriptorGetter {
};
template <>
struct MessageDescriptorGetter<Message> {
static const Descriptor* get() { return NULL; }
static const Descriptor* get() { return nullptr; }
};
template <typename T>

@ -50,7 +50,7 @@ namespace internal {
void** RepeatedPtrFieldBase::InternalExtend(int extend_amount) {
int new_size = current_size_ + extend_amount;
if (total_size_ >= new_size) {
// N.B.: rep_ is non-NULL because extend_amount is always > 0, hence
// N.B.: rep_ is non-nullptr because extend_amount is always > 0, hence
// total_size must be non-zero since it is lower-bounded by new_size.
return &rep_->elements[current_size_];
}
@ -64,7 +64,7 @@ void** RepeatedPtrFieldBase::InternalExtend(int extend_amount) {
sizeof(old_rep->elements[0])))
<< "Requested size is too large to fit into size_t.";
size_t bytes = kRepHeaderSize + sizeof(old_rep->elements[0]) * new_size;
if (arena == NULL) {
if (arena == nullptr) {
rep_ = reinterpret_cast<Rep*>(::operator new(bytes));
} else {
rep_ = reinterpret_cast<Rep*>(Arena::CreateArray<char>(arena, bytes));
@ -80,7 +80,7 @@ void** RepeatedPtrFieldBase::InternalExtend(int extend_amount) {
} else {
rep_->allocated_size = 0;
}
if (arena == NULL) {
if (arena == nullptr) {
#if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation)
const size_t old_size =
old_total_size * sizeof(rep_->elements[0]) + kRepHeaderSize;
@ -98,6 +98,24 @@ void RepeatedPtrFieldBase::Reserve(int new_size) {
}
}
void RepeatedPtrFieldBase::DestroyProtos() {
GOOGLE_DCHECK(rep_);
GOOGLE_DCHECK(arena_ == nullptr);
int n = rep_->allocated_size;
void* const* elements = rep_->elements;
for (int i = 0; i < n; i++) {
delete static_cast<MessageLite*>(elements[i]);
}
#if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation)
const size_t size = total_size_ * sizeof(elements[0]) + kRepHeaderSize;
::operator delete(static_cast<void*>(rep_), size);
rep_ = nullptr;
#else
::operator delete(static_cast<void*>(rep_));
rep_ = nullptr;
#endif
}
void* RepeatedPtrFieldBase::AddOutOfLineHelper(void* obj) {
if (!rep_ || rep_->allocated_size == total_size_) {
InternalExtend(1); // Equivalent to "Reserve(total_size_ + 1)"
@ -108,7 +126,7 @@ void* RepeatedPtrFieldBase::AddOutOfLineHelper(void* obj) {
}
void RepeatedPtrFieldBase::CloseGap(int start, int num) {
if (rep_ == NULL) return;
if (rep_ == nullptr) return;
// Close up a gap of "num" elements starting at offset "start".
for (int i = start + num; i < rep_->allocated_size; ++i)
rep_->elements[i - num] = rep_->elements[i];
@ -117,7 +135,7 @@ void RepeatedPtrFieldBase::CloseGap(int start, int num) {
}
MessageLite* RepeatedPtrFieldBase::AddWeak(const MessageLite* prototype) {
if (rep_ != NULL && current_size_ < rep_->allocated_size) {
if (rep_ != nullptr && current_size_ < rep_->allocated_size) {
return reinterpret_cast<MessageLite*>(rep_->elements[current_size_++]);
}
if (!rep_ || rep_->allocated_size == total_size_) {

@ -213,7 +213,7 @@ class RepeatedField final {
void RemoveLast();
// Extract elements with indices in "[start .. start+num-1]".
// Copy them into "elements[0 .. num-1]" if "elements" is not NULL.
// Copy them into "elements[0 .. num-1]" if "elements" is not nullptr.
// Caution: implementation also moves elements with indices [start+num ..].
// Calling this routine inside a loop can cause quadratic behavior.
void ExtractSubrange(int start, int num, Element* elements);
@ -391,7 +391,7 @@ class RepeatedField final {
// Internal helper to delete all elements and deallocate the storage.
void InternalDeallocate(Rep* rep, int size) {
if (rep != NULL) {
if (rep != nullptr) {
Element* e = &rep->elements[0];
if (!std::is_trivial<Element>::value) {
Element* limit = &rep->elements[size];
@ -399,7 +399,7 @@ class RepeatedField final {
e->~Element();
}
}
if (rep->arena == NULL) {
if (rep->arena == nullptr) {
#if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation)
const size_t bytes = size * sizeof(*e) + kRepHeaderSize;
::operator delete(static_cast<void*>(rep), bytes);
@ -599,6 +599,8 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase {
// Must be called from destructor.
template <typename TypeHandler>
void Destroy();
bool NeedsDestroy() const { return rep_ != nullptr && arena_ == nullptr; }
void DestroyProtos();
bool empty() const;
int size() const;
@ -613,7 +615,8 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase {
template <typename TypeHandler>
void Delete(int index);
template <typename TypeHandler>
typename TypeHandler::Type* Add(typename TypeHandler::Type* prototype = NULL);
typename TypeHandler::Type* Add(
typename TypeHandler::Type* prototype = nullptr);
public:
// The next few methods are public so that they can be called from generated
@ -625,8 +628,8 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase {
// Creates and adds an element using the given prototype, without introducing
// a link-time dependency on the concrete message type. This method is used to
// implement implicit weak fields. The prototype may be NULL, in which case an
// ImplicitWeakMessage will be used as a placeholder.
// implement implicit weak fields. The prototype may be nullptr, in which case
// an ImplicitWeakMessage will be used as a placeholder.
MessageLite* AddWeak(const MessageLite* prototype);
template <typename TypeHandler>
@ -681,7 +684,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase {
// Advanced memory management --------------------------------------
// Like Add(), but if there are no cleared objects to use, returns NULL.
// Like Add(), but if there are no cleared objects to use, returns nullptr.
template <typename TypeHandler>
typename TypeHandler::Type* AddFromCleared();
@ -833,9 +836,9 @@ class GenericTypeHandler {
return Arena::Create<GenericType>(arena, std::move(value));
}
static inline GenericType* NewFromPrototype(const GenericType* prototype,
Arena* arena = NULL);
Arena* arena = nullptr);
static inline void Delete(GenericType* value, Arena* arena) {
if (arena == NULL) {
if (arena == nullptr) {
delete value;
}
}
@ -911,7 +914,7 @@ class StringTypeHandler {
}
static inline Arena* GetOwningArena(std::string*) { return nullptr; }
static inline void Delete(std::string* value, Arena* arena) {
if (arena == NULL) {
if (arena == nullptr) {
delete value;
}
}
@ -1106,9 +1109,9 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase {
// Extract elements with indices in the range "[start .. start+num-1]".
// The caller assumes ownership of the extracted elements and is responsible
// for deleting them when they are no longer needed.
// If "elements" is non-NULL, then pointers to the extracted elements
// If "elements" is non-nullptr, then pointers to the extracted elements
// are stored in "elements[0 .. num-1]" for the convenience of the caller.
// If "elements" is NULL, then the caller must use some other mechanism
// If "elements" is nullptr, then the caller must use some other mechanism
// to perform any further operations (like deletion) on these elements.
// Caution: implementation also moves elements with indices [start+num ..].
// Calling this routine inside a loop can cause quadratic behavior.
@ -1430,7 +1433,7 @@ void RepeatedField<Element>::ExtractSubrange(int start, int num,
GOOGLE_DCHECK_LE(start + num, this->current_size_);
// Save the values of the removed elements if requested.
if (elements != NULL) {
if (elements != nullptr) {
for (int i = 0; i < num; ++i) elements[i] = this->Get(i + start);
}
@ -1605,7 +1608,7 @@ inline int CalculateReserveSize(int total_size, int new_size) {
template <typename Element>
void RepeatedField<Element>::Reserve(int new_size) {
if (total_size_ >= new_size) return;
Rep* old_rep = total_size_ > 0 ? rep() : NULL;
Rep* old_rep = total_size_ > 0 ? rep() : nullptr;
Rep* new_rep;
Arena* arena = GetArena();
new_size = internal::CalculateReserveSize(total_size_, new_size);
@ -1615,7 +1618,7 @@ void RepeatedField<Element>::Reserve(int new_size) {
<< "Requested size is too large to fit into size_t.";
size_t bytes =
kRepHeaderSize + sizeof(Element) * static_cast<size_t>(new_size);
if (arena == NULL) {
if (arena == nullptr) {
new_rep = static_cast<Rep*>(::operator new(bytes));
} else {
new_rep = reinterpret_cast<Rep*>(Arena::CreateArray<char>(arena, bytes));
@ -1695,18 +1698,18 @@ struct ElementCopier<Element, true> {
namespace internal {
constexpr RepeatedPtrFieldBase::RepeatedPtrFieldBase()
: arena_(NULL), current_size_(0), total_size_(0), rep_(NULL) {}
: arena_(nullptr), current_size_(0), total_size_(0), rep_(nullptr) {}
inline RepeatedPtrFieldBase::RepeatedPtrFieldBase(Arena* arena)
: arena_(arena), current_size_(0), total_size_(0), rep_(NULL) {}
: arena_(arena), current_size_(0), total_size_(0), rep_(nullptr) {}
template <typename TypeHandler>
void RepeatedPtrFieldBase::Destroy() {
if (rep_ != NULL && arena_ == NULL) {
if (rep_ != nullptr && arena_ == nullptr) {
int n = rep_->allocated_size;
void* const* elements = rep_->elements;
for (int i = 0; i < n; i++) {
TypeHandler::Delete(cast<TypeHandler>(elements[i]), NULL);
TypeHandler::Delete(cast<TypeHandler>(elements[i]), nullptr);
}
#if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation)
const size_t size = total_size_ * sizeof(elements[0]) + kRepHeaderSize;
@ -1715,7 +1718,7 @@ void RepeatedPtrFieldBase::Destroy() {
::operator delete(static_cast<void*>(rep_));
#endif
}
rep_ = NULL;
rep_ = nullptr;
}
template <typename TypeHandler>
@ -1794,7 +1797,7 @@ inline void RepeatedPtrFieldBase::Delete(int index) {
template <typename TypeHandler>
inline typename TypeHandler::Type* RepeatedPtrFieldBase::Add(
typename TypeHandler::Type* prototype) {
if (rep_ != NULL && current_size_ < rep_->allocated_size) {
if (rep_ != nullptr && current_size_ < rep_->allocated_size) {
return cast<TypeHandler>(rep_->elements[current_size_++]);
}
typename TypeHandler::Type* result =
@ -1806,7 +1809,7 @@ inline typename TypeHandler::Type* RepeatedPtrFieldBase::Add(
template <typename TypeHandler,
typename std::enable_if<TypeHandler::Movable::value>::type*>
inline void RepeatedPtrFieldBase::Add(typename TypeHandler::Type&& value) {
if (rep_ != NULL && current_size_ < rep_->allocated_size) {
if (rep_ != nullptr && current_size_ < rep_->allocated_size) {
*cast<TypeHandler>(rep_->elements[current_size_++]) = std::move(value);
return;
}
@ -1856,7 +1859,7 @@ inline void RepeatedPtrFieldBase::MergeFrom(const RepeatedPtrFieldBase& other) {
inline void RepeatedPtrFieldBase::MergeFromInternal(
const RepeatedPtrFieldBase& other,
void (RepeatedPtrFieldBase::*inner_loop)(void**, void**, int, int)) {
// Note: wrapper has already guaranteed that other.rep_ != NULL here.
// Note: wrapper has already guaranteed that other.rep_ != nullptr here.
int other_size = other.current_size_;
void** other_elements = other.rep_->elements;
void** new_elements = InternalExtend(other_size);
@ -1906,11 +1909,11 @@ inline void RepeatedPtrFieldBase::CopyFrom(const RepeatedPtrFieldBase& other) {
inline int RepeatedPtrFieldBase::Capacity() const { return total_size_; }
inline void* const* RepeatedPtrFieldBase::raw_data() const {
return rep_ ? rep_->elements : NULL;
return rep_ ? rep_->elements : nullptr;
}
inline void** RepeatedPtrFieldBase::raw_mutable_data() const {
return rep_ ? const_cast<void**>(rep_->elements) : NULL;
return rep_ ? const_cast<void**>(rep_->elements) : nullptr;
}
template <typename TypeHandler>
@ -1936,7 +1939,7 @@ inline void RepeatedPtrFieldBase::SwapElements(int index1, int index2) {
template <typename TypeHandler>
inline size_t RepeatedPtrFieldBase::SpaceUsedExcludingSelfLong() const {
size_t allocated_bytes = static_cast<size_t>(total_size_) * sizeof(void*);
if (rep_ != NULL) {
if (rep_ != nullptr) {
for (int i = 0; i < rep_->allocated_size; ++i) {
allocated_bytes +=
TypeHandler::SpaceUsedLong(*cast<TypeHandler>(rep_->elements[i]));
@ -1948,10 +1951,10 @@ inline size_t RepeatedPtrFieldBase::SpaceUsedExcludingSelfLong() const {
template <typename TypeHandler>
inline typename TypeHandler::Type* RepeatedPtrFieldBase::AddFromCleared() {
if (rep_ != NULL && current_size_ < rep_->allocated_size) {
if (rep_ != nullptr && current_size_ < rep_->allocated_size) {
return cast<TypeHandler>(rep_->elements[current_size_++]);
} else {
return NULL;
return nullptr;
}
}
@ -1989,7 +1992,7 @@ void RepeatedPtrFieldBase::AddAllocatedSlowWithCopy(
// Ensure that either the value is in the same arena, or if not, we do the
// appropriate thing: Own() it (if it's on heap and we're in an arena) or copy
// it to our arena/heap (otherwise).
if (my_arena != NULL && value_arena == NULL) {
if (my_arena != nullptr && value_arena == nullptr) {
my_arena->Own(value);
} else if (my_arena != value_arena) {
typename TypeHandler::Type* new_value =
@ -2107,7 +2110,7 @@ inline int RepeatedPtrFieldBase::ClearedCount() const {
template <typename TypeHandler>
inline void RepeatedPtrFieldBase::AddCleared(
typename TypeHandler::Type* value) {
GOOGLE_DCHECK(GetArena() == NULL)
GOOGLE_DCHECK(GetArena() == nullptr)
<< "AddCleared() can only be used on a RepeatedPtrField not on an arena.";
GOOGLE_DCHECK(TypeHandler::GetOwningArena(value) == nullptr)
<< "AddCleared() can only accept values not on an arena.";
@ -2119,11 +2122,11 @@ inline void RepeatedPtrFieldBase::AddCleared(
template <typename TypeHandler>
inline typename TypeHandler::Type* RepeatedPtrFieldBase::ReleaseCleared() {
GOOGLE_DCHECK(GetArena() == NULL)
GOOGLE_DCHECK(GetArena() == nullptr)
<< "ReleaseCleared() can only be used on a RepeatedPtrField not on "
<< "an arena.";
GOOGLE_DCHECK(GetArena() == NULL);
GOOGLE_DCHECK(rep_ != NULL);
GOOGLE_DCHECK(GetArena() == nullptr);
GOOGLE_DCHECK(rep_ != nullptr);
GOOGLE_DCHECK_GT(rep_->allocated_size, current_size_);
return cast<TypeHandler>(rep_->elements[--rep_->allocated_size]);
}
@ -2163,7 +2166,15 @@ inline RepeatedPtrField<Element>::RepeatedPtrField(Iter begin, Iter end) {
template <typename Element>
RepeatedPtrField<Element>::~RepeatedPtrField() {
Destroy<TypeHandler>();
#ifdef __cpp_if_constexpr
if constexpr (std::is_base_of<MessageLite, Element>::value) {
#else
if (std::is_base_of<MessageLite, Element>::value) {
#endif
if (NeedsDestroy()) DestroyProtos();
} else {
Destroy<TypeHandler>();
}
}
template <typename Element>
@ -2344,8 +2355,8 @@ inline void RepeatedPtrField<Element>::ExtractSubrangeInternal(
// ExtractSubrange() must return heap-allocated objects by contract, and we
// cannot fulfill this contract if we are an on arena, we must GOOGLE_DCHECK() that
// we are not on an arena.
GOOGLE_DCHECK(GetArena() == NULL)
<< "ExtractSubrange() when arena is non-NULL is only supported when "
GOOGLE_DCHECK(GetArena() == nullptr)
<< "ExtractSubrange() when arena is non-nullptr is only supported when "
<< "the Element type supplies a MergeFrom() operation to make copies.";
UnsafeArenaExtractSubrange(start, num, elements);
}
@ -2359,7 +2370,7 @@ inline void RepeatedPtrField<Element>::UnsafeArenaExtractSubrange(
if (num > 0) {
// Save the values of the removed elements if requested.
if (elements != NULL) {
if (elements != nullptr) {
for (int i = 0; i < num; ++i) {
elements[i] = RepeatedPtrFieldBase::Mutable<TypeHandler>(i + start);
}
@ -2514,7 +2525,7 @@ class RepeatedPtrIterator {
using pointer = Element*;
using reference = Element&;
RepeatedPtrIterator() : it_(NULL) {}
RepeatedPtrIterator() : it_(nullptr) {}
explicit RepeatedPtrIterator(void* const* it) : it_(it) {}
// Allow "upcasting" from RepeatedPtrIterator<T**> to
@ -2607,7 +2618,7 @@ class RepeatedPtrOverPtrsIterator {
using pointer = Element*;
using reference = Element&;
RepeatedPtrOverPtrsIterator() : it_(NULL) {}
RepeatedPtrOverPtrsIterator() : it_(nullptr) {}
explicit RepeatedPtrOverPtrsIterator(VoidPtr* it) : it_(it) {}
// dereferenceable

@ -165,7 +165,7 @@ TEST(RepeatedFieldReflectionTest, ExtensionFields) {
const FieldDescriptor* fd_repeated_int64_extension =
desc->file()->FindExtensionByName("repeated_int64_extension");
GOOGLE_CHECK(fd_repeated_int64_extension != NULL);
GOOGLE_CHECK(fd_repeated_int64_extension != nullptr);
const RepeatedField<int64>& rf_int64_extension =
refl->GetRepeatedField<int64>(extended_message,
@ -538,7 +538,7 @@ TEST(RepeatedFieldReflectionTest, RepeatedFieldRefForExtensionFields) {
const FieldDescriptor* fd_repeated_int64_extension =
desc->file()->FindExtensionByName("repeated_int64_extension");
GOOGLE_CHECK(fd_repeated_int64_extension != NULL);
GOOGLE_CHECK(fd_repeated_int64_extension != nullptr);
const RepeatedFieldRef<int64> rf_int64_extension =
refl->GetRepeatedFieldRef<int64>(extended_message,

@ -1534,7 +1534,7 @@ TEST(RepeatedPtrField, ExtractSubrange) {
// Create a catcher array and call ExtractSubrange.
std::string* catcher[10];
for (int i = 0; i < 10; ++i) catcher[i] = NULL;
for (int i = 0; i < 10; ++i) catcher[i] = nullptr;
field.ExtractSubrange(start, num, catcher);
// Does the resulting array have the right size?
@ -1543,7 +1543,7 @@ TEST(RepeatedPtrField, ExtractSubrange) {
// Were the removed elements extracted into the catcher array?
for (int i = 0; i < num; ++i)
EXPECT_EQ(*catcher[i], *subject[start + i]);
EXPECT_EQ(NULL, catcher[num]);
EXPECT_EQ(nullptr, catcher[num]);
// Does the resulting array contain the right values?
for (int i = 0; i < start; ++i)
@ -1908,7 +1908,7 @@ TEST_F(RepeatedPtrFieldPtrsIteratorTest, PtrSTLAlgorithms_lower_bound) {
std::lower_bound(proto_array_.pointer_begin(),
proto_array_.pointer_end(), &v, StringLessThan());
GOOGLE_CHECK(*it != NULL);
GOOGLE_CHECK(*it != nullptr);
EXPECT_EQ(**it, "n");
EXPECT_TRUE(it == proto_array_.pointer_begin() + 3);
@ -1919,7 +1919,7 @@ TEST_F(RepeatedPtrFieldPtrsIteratorTest, PtrSTLAlgorithms_lower_bound) {
const_proto_array_->pointer_begin(), const_proto_array_->pointer_end(),
&v, StringLessThan());
GOOGLE_CHECK(*it != NULL);
GOOGLE_CHECK(*it != nullptr);
EXPECT_EQ(**it, "n");
EXPECT_TRUE(it == const_proto_array_->pointer_begin() + 3);

@ -100,7 +100,7 @@ SourceContext::SourceContext(const SourceContext& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.SourceContext)
}
void SourceContext::SharedCtor() {
inline void SourceContext::SharedCtor() {
file_name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}

@ -205,7 +205,7 @@ Struct::Struct(const Struct& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.Struct)
}
void Struct::SharedCtor() {
inline void Struct::SharedCtor() {
}
Struct::~Struct() {
@ -498,7 +498,7 @@ Value::Value(const Value& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.Value)
}
void Value::SharedCtor() {
inline void Value::SharedCtor() {
clear_has_kind();
}
@ -865,7 +865,7 @@ ListValue::ListValue(const ListValue& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.ListValue)
}
void ListValue::SharedCtor() {
inline void ListValue::SharedCtor() {
}
ListValue::~ListValue() {

@ -348,6 +348,12 @@ class TextFormat::Parser::ParserImpl {
}
private:
static constexpr int32_t kint32max = std::numeric_limits<int32_t>::max();
static constexpr uint32_t kuint32max = std::numeric_limits<uint32_t>::max();
static constexpr int64_t kint64min = std::numeric_limits<int64_t>::min();
static constexpr int64_t kint64max = std::numeric_limits<int64_t>::max();
static constexpr uint64_t kuint64max = std::numeric_limits<uint64_t>::max();
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ParserImpl);
// Reports an error with the given message with information indicating

@ -213,7 +213,7 @@ class PROTOBUF_EXPORT TextFormat {
virtual ~Finder();
// Try to find an extension of *message by fully-qualified field
// name. Returns NULL if no extension is known for this name or number.
// name. Returns nullptr if no extension is known for this name or number.
// The base implementation uses the extensions already known by the message.
virtual const FieldDescriptor* FindExtension(Message* message,
const std::string& name) const;
@ -224,7 +224,7 @@ class PROTOBUF_EXPORT TextFormat {
const Descriptor* descriptor, int number) const;
// Find the message type for an Any proto.
// Returns NULL if no message is known for this name.
// Returns nullptr if no message is known for this name.
// The base implementation only accepts prefixes of type.googleprod.com/ or
// type.googleapis.com/, and searches the DescriptorPool of the parent
// message.
@ -564,18 +564,19 @@ class PROTOBUF_EXPORT TextFormat {
// Like TextFormat::MergeFromString().
bool MergeFromString(ConstStringParam input, Message* output);
// Set where to report parse errors. If NULL (the default), errors will
// Set where to report parse errors. If nullptr (the default), errors will
// be printed to stderr.
void RecordErrorsTo(io::ErrorCollector* error_collector) {
error_collector_ = error_collector;
}
// Set how parser finds extensions. If NULL (the default), the
// Set how parser finds extensions. If nullptr (the default), the
// parser will use the standard Reflection object associated with
// the message being parsed.
void SetFinder(const Finder* finder) { finder_ = finder; }
// Sets where location information about the parse will be written. If NULL
// Sets where location information about the parse will be written. If
// nullptr
// (the default), then no location will be written.
void WriteLocationsTo(ParseInfoTree* tree) { parse_info_tree_ = tree; }

@ -509,7 +509,7 @@ TEST_F(TextFormatTest, FieldSpecificCustomPrinterRegisterSameFieldTwice) {
TEST_F(TextFormatTest, ErrorCasesRegisteringFieldValuePrinterShouldFail) {
protobuf_unittest::TestAllTypes message;
TextFormat::Printer printer;
// NULL printer.
// nullptr printer.
EXPECT_FALSE(printer.RegisterFieldValuePrinter(
message.GetDescriptor()->FindFieldByName("optional_int32"),
static_cast<const TextFormat::FieldValuePrinter*>(nullptr)));
@ -518,7 +518,7 @@ TEST_F(TextFormatTest, ErrorCasesRegisteringFieldValuePrinterShouldFail) {
static_cast<const TextFormat::FastFieldValuePrinter*>(nullptr)));
// Because registration fails, the ownership of this printer is never taken.
TextFormat::FieldValuePrinter my_field_printer;
// NULL field
// nullptr field
EXPECT_FALSE(printer.RegisterFieldValuePrinter(nullptr, &my_field_printer));
}
@ -1086,7 +1086,7 @@ TEST_F(TextFormatTest, PrintExotic) {
// seemed to trigger an odd case on MinGW/GCC 3.4.5 where GCC's parsing of
// the value differed from strtod()'s parsing. That is to say, the
// following assertion fails on MinGW:
// assert(1.23e22 == strtod("1.23e22", NULL));
// assert(1.23e22 == strtod("1.23e22", nullptr));
// As a result, SimpleDtoa() would print the value as
// "1.2300000000000001e+22" to make sure strtod() produce the exact same
// result. Our goal is to test runtime parsing, not compile-time parsing,
@ -1504,11 +1504,11 @@ TEST_F(TextFormatParserTest, ParseInfoTreeBuilding) {
ExpectLocation(nested_tree, nested_field->message_type(), "bb", -1, 12, 2, 12,
8);
// Verify a NULL tree for an unknown nested field.
// Verify a nullptr tree for an unknown nested field.
TextFormat::ParseInfoTree* unknown_nested_tree =
tree.GetTreeForNested(nested_field, 2);
EXPECT_EQ(NULL, unknown_nested_tree);
EXPECT_EQ(nullptr, unknown_nested_tree);
}
TEST_F(TextFormatParserTest, ParseFieldValueFromString) {

@ -100,7 +100,7 @@ Timestamp::Timestamp(const Timestamp& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.Timestamp)
}
void Timestamp::SharedCtor() {
inline void Timestamp::SharedCtor() {
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&seconds_) - reinterpret_cast<char*>(this)),
0, static_cast<size_t>(reinterpret_cast<char*>(&nanos_) -

@ -385,7 +385,7 @@ Type::Type(const Type& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.Type)
}
void Type::SharedCtor() {
inline void Type::SharedCtor() {
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&source_context_) - reinterpret_cast<char*>(this)),
@ -767,7 +767,7 @@ Field::Field(const Field& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.Field)
}
void Field::SharedCtor() {
inline void Field::SharedCtor() {
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
type_url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
json_name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
@ -1259,7 +1259,7 @@ Enum::Enum(const Enum& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.Enum)
}
void Enum::SharedCtor() {
inline void Enum::SharedCtor() {
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&source_context_) - reinterpret_cast<char*>(this)),
@ -1588,7 +1588,7 @@ EnumValue::EnumValue(const EnumValue& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.EnumValue)
}
void EnumValue::SharedCtor() {
inline void EnumValue::SharedCtor() {
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
number_ = 0;
}
@ -1857,7 +1857,7 @@ Option::Option(const Option& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.Option)
}
void Option::SharedCtor() {
inline void Option::SharedCtor() {
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
value_ = nullptr;
}

@ -72,13 +72,13 @@ class UnknownFieldSetTest : public testing::Test {
const UnknownField* GetField(const std::string& name) {
const FieldDescriptor* field = descriptor_->FindFieldByName(name);
if (field == NULL) return NULL;
if (field == nullptr) return nullptr;
for (int i = 0; i < unknown_fields_->field_count(); i++) {
if (unknown_fields_->field(i).number() == field->number()) {
return &unknown_fields_->field(i);
}
}
return NULL;
return nullptr;
}
// Constructs a protocol buffer which contains fields with all the same
@ -145,7 +145,7 @@ TEST_F(UnknownFieldSetTest, AllFieldsPresent) {
TEST_F(UnknownFieldSetTest, Varint) {
const UnknownField* field = GetField("optional_int32");
ASSERT_TRUE(field != NULL);
ASSERT_TRUE(field != nullptr);
ASSERT_EQ(UnknownField::TYPE_VARINT, field->type());
EXPECT_EQ(all_fields_.optional_int32(), field->varint());
@ -153,7 +153,7 @@ TEST_F(UnknownFieldSetTest, Varint) {
TEST_F(UnknownFieldSetTest, Fixed32) {
const UnknownField* field = GetField("optional_fixed32");
ASSERT_TRUE(field != NULL);
ASSERT_TRUE(field != nullptr);
ASSERT_EQ(UnknownField::TYPE_FIXED32, field->type());
EXPECT_EQ(all_fields_.optional_fixed32(), field->fixed32());
@ -161,7 +161,7 @@ TEST_F(UnknownFieldSetTest, Fixed32) {
TEST_F(UnknownFieldSetTest, Fixed64) {
const UnknownField* field = GetField("optional_fixed64");
ASSERT_TRUE(field != NULL);
ASSERT_TRUE(field != nullptr);
ASSERT_EQ(UnknownField::TYPE_FIXED64, field->type());
EXPECT_EQ(all_fields_.optional_fixed64(), field->fixed64());
@ -169,7 +169,7 @@ TEST_F(UnknownFieldSetTest, Fixed64) {
TEST_F(UnknownFieldSetTest, LengthDelimited) {
const UnknownField* field = GetField("optional_string");
ASSERT_TRUE(field != NULL);
ASSERT_TRUE(field != nullptr);
ASSERT_EQ(UnknownField::TYPE_LENGTH_DELIMITED, field->type());
EXPECT_EQ(all_fields_.optional_string(), field->length_delimited());
@ -177,7 +177,7 @@ TEST_F(UnknownFieldSetTest, LengthDelimited) {
TEST_F(UnknownFieldSetTest, Group) {
const UnknownField* field = GetField("optionalgroup");
ASSERT_TRUE(field != NULL);
ASSERT_TRUE(field != nullptr);
ASSERT_EQ(UnknownField::TYPE_GROUP, field->type());
ASSERT_EQ(1, field->group().field_count());
@ -185,7 +185,7 @@ TEST_F(UnknownFieldSetTest, Group) {
const UnknownField& nested_field = field->group().field(0);
const FieldDescriptor* nested_field_descriptor =
unittest::TestAllTypes::OptionalGroup::descriptor()->FindFieldByName("a");
ASSERT_TRUE(nested_field_descriptor != NULL);
ASSERT_TRUE(nested_field_descriptor != nullptr);
EXPECT_EQ(nested_field_descriptor->number(), nested_field.number());
ASSERT_EQ(UnknownField::TYPE_VARINT, nested_field.type());
@ -456,8 +456,8 @@ TEST_F(UnknownFieldSetTest, UnknownEnumValue) {
TestAllTypes::descriptor()->FindFieldByName("optional_nested_enum");
const FieldDescriptor* repeated_field =
TestAllTypes::descriptor()->FindFieldByName("repeated_nested_enum");
ASSERT_TRUE(singular_field != NULL);
ASSERT_TRUE(repeated_field != NULL);
ASSERT_TRUE(singular_field != nullptr);
ASSERT_TRUE(repeated_field != nullptr);
std::string data;

@ -92,19 +92,19 @@ bool WireFormat::SkipField(io::CodedInputStream* input, uint32_t tag,
case WireFormatLite::WIRETYPE_VARINT: {
uint64_t value;
if (!input->ReadVarint64(&value)) return false;
if (unknown_fields != NULL) unknown_fields->AddVarint(number, value);
if (unknown_fields != nullptr) unknown_fields->AddVarint(number, value);
return true;
}
case WireFormatLite::WIRETYPE_FIXED64: {
uint64_t value;
if (!input->ReadLittleEndian64(&value)) return false;
if (unknown_fields != NULL) unknown_fields->AddFixed64(number, value);
if (unknown_fields != nullptr) unknown_fields->AddFixed64(number, value);
return true;
}
case WireFormatLite::WIRETYPE_LENGTH_DELIMITED: {
uint32_t length;
if (!input->ReadVarint32(&length)) return false;
if (unknown_fields == NULL) {
if (unknown_fields == nullptr) {
if (!input->Skip(length)) return false;
} else {
if (!input->ReadString(unknown_fields->AddLengthDelimited(number),
@ -116,8 +116,8 @@ bool WireFormat::SkipField(io::CodedInputStream* input, uint32_t tag,
}
case WireFormatLite::WIRETYPE_START_GROUP: {
if (!input->IncrementRecursionDepth()) return false;
if (!SkipMessage(input, (unknown_fields == NULL)
? NULL
if (!SkipMessage(input, (unknown_fields == nullptr)
? nullptr
: unknown_fields->AddGroup(number))) {
return false;
}
@ -136,7 +136,7 @@ bool WireFormat::SkipField(io::CodedInputStream* input, uint32_t tag,
case WireFormatLite::WIRETYPE_FIXED32: {
uint32_t value;
if (!input->ReadLittleEndian32(&value)) return false;
if (unknown_fields != NULL) unknown_fields->AddFixed32(number, value);
if (unknown_fields != nullptr) unknown_fields->AddFixed32(number, value);
return true;
}
default: {
@ -179,7 +179,7 @@ bool WireFormat::ReadPackedEnumPreserveUnknowns(io::CodedInputStream* input,
input, &value)) {
return false;
}
if (is_valid == NULL || is_valid(value)) {
if (is_valid == nullptr || is_valid(value)) {
values->Add(value);
} else {
unknown_fields->AddVarint(field_number, value);
@ -346,15 +346,15 @@ bool WireFormat::ParseAndMergePartial(io::CodedInputStream* input,
return true;
}
const FieldDescriptor* field = NULL;
const FieldDescriptor* field = nullptr;
if (descriptor != NULL) {
if (descriptor != nullptr) {
int field_number = WireFormatLite::GetTagFieldNumber(tag);
field = descriptor->FindFieldByNumber(field_number);
// If that failed, check if the field is an extension.
if (field == NULL && descriptor->IsExtensionNumber(field_number)) {
if (input->GetExtensionPool() == NULL) {
if (field == nullptr && descriptor->IsExtensionNumber(field_number)) {
if (input->GetExtensionPool() == nullptr) {
field = message_reflection->FindKnownExtensionByNumber(field_number);
} else {
field = input->GetExtensionPool()->FindExtensionByNumber(
@ -364,7 +364,7 @@ bool WireFormat::ParseAndMergePartial(io::CodedInputStream* input,
// If that failed, but we're a MessageSet, and this is the tag for a
// MessageSet item, then parse that.
if (field == NULL && descriptor->options().message_set_wire_format() &&
if (field == nullptr && descriptor->options().message_set_wire_format() &&
tag == WireFormatLite::kMessageSetItemStartTag) {
if (!ParseAndMergeMessageSetItem(input, message)) {
return false;
@ -393,7 +393,7 @@ bool WireFormat::ParseAndMergeMessageSetField(uint32_t field_number,
Message* message,
io::CodedInputStream* input) {
const Reflection* message_reflection = message->GetReflection();
if (field == NULL) {
if (field == nullptr) {
// We store unknown MessageSet extensions as groups.
return SkipMessageSetField(
input, field_number, message_reflection->MutableUnknownFields(message));
@ -416,13 +416,13 @@ static bool StrictUtf8Check(const FieldDescriptor* field) {
bool WireFormat::ParseAndMergeField(
uint32_t tag,
const FieldDescriptor* field, // May be NULL for unknown
const FieldDescriptor* field, // May be nullptr for unknown
Message* message, io::CodedInputStream* input) {
const Reflection* message_reflection = message->GetReflection();
enum { UNKNOWN, NORMAL_FORMAT, PACKED_FORMAT } value_format;
if (field == NULL) {
if (field == nullptr) {
value_format = UNKNOWN;
} else if (WireFormatLite::GetTagWireType(tag) ==
WireTypeForFieldType(field->type())) {
@ -489,7 +489,7 @@ bool WireFormat::ParseAndMergeField(
} else {
const EnumValueDescriptor* enum_value =
field->enum_type()->FindValueByNumber(value);
if (enum_value != NULL) {
if (enum_value != nullptr) {
message_reflection->AddEnum(message, field, enum_value);
} else {
// The enum value is not one of the known values. Add it to the
@ -642,7 +642,7 @@ bool WireFormat::ParseAndMergeMessageSetItem(io::CodedInputStream* input,
}
bool SkipField(uint32_t tag, io::CodedInputStream* input) {
return WireFormat::SkipField(input, tag, NULL);
return WireFormat::SkipField(input, tag, nullptr);
}
const Reflection* message_reflection;

@ -146,17 +146,17 @@ class PROTOBUF_EXPORT WireFormat {
// Helpers for dealing with unknown fields
// Skips a field value of the given WireType. The input should start
// positioned immediately after the tag. If unknown_fields is non-NULL,
// positioned immediately after the tag. If unknown_fields is non-nullptr,
// the contents of the field will be added to it.
static bool SkipField(io::CodedInputStream* input, uint32_t tag,
UnknownFieldSet* unknown_fields);
// Reads and ignores a message from the input. If unknown_fields is
// non-NULL, the contents will be added to it.
// non-nullptr, the contents will be added to it.
static bool SkipMessage(io::CodedInputStream* input,
UnknownFieldSet* unknown_fields);
// Read a packed enum field. If the is_valid function is not NULL, values
// Read a packed enum field. If the is_valid function is not nullptr, values
// for which is_valid(value) returns false are appended to
// unknown_fields_stream.
static bool ReadPackedEnumPreserveUnknowns(io::CodedInputStream* input,
@ -225,24 +225,24 @@ class PROTOBUF_EXPORT WireFormat {
// after the tag.
static bool ParseAndMergeField(
uint32_t tag,
const FieldDescriptor* field, // May be NULL for unknown
const FieldDescriptor* field, // May be nullptr for unknown
Message* message, io::CodedInputStream* input);
// Serialize a single field.
static void SerializeFieldWithCachedSizes(
const FieldDescriptor* field, // Cannot be NULL
const FieldDescriptor* field, // Cannot be nullptr
const Message& message, io::CodedOutputStream* output) {
output->SetCur(InternalSerializeField(field, message, output->Cur(),
output->EpsCopy()));
}
static uint8_t* InternalSerializeField(
const FieldDescriptor* field, // Cannot be NULL
const FieldDescriptor* field, // Cannot be nullptr
const Message& message, uint8_t* target, io::EpsCopyOutputStream* stream);
// Compute size of a single field. If the field is a message type, this
// will call ByteSize() for the embedded message, insuring that it caches
// its size.
static size_t FieldByteSize(const FieldDescriptor* field, // Cannot be NULL
static size_t FieldByteSize(const FieldDescriptor* field, // Can't be nullptr
const Message& message);
// Parse/serialize a MessageSet::Item group. Used with messages that use
@ -266,7 +266,7 @@ class PROTOBUF_EXPORT WireFormat {
// length, but for other length-delimited types, the size of the length is
// included.
static size_t FieldDataOnlyByteSize(
const FieldDescriptor* field, // Cannot be NULL
const FieldDescriptor* field, // Cannot be nullptr
const Message& message);
enum Operation {
@ -357,7 +357,7 @@ inline void WireFormat::VerifyUTF8String(const char* data, int size,
WireFormat::Operation op) {
#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
WireFormatLite::VerifyUtf8String(
data, size, static_cast<WireFormatLite::Operation>(op), NULL);
data, size, static_cast<WireFormatLite::Operation>(op), nullptr);
#else
// Avoid the compiler warning about unused variables.
(void)data;

@ -34,6 +34,7 @@
#include <google/protobuf/wire_format_lite.h>
#include <limits>
#include <stack>
#include <string>
#include <vector>
@ -303,7 +304,7 @@ bool WireFormatLite::ReadPackedEnumPreserveUnknowns(
if (!ReadPrimitive<int, WireFormatLite::TYPE_ENUM>(input, &value)) {
return false;
}
if (is_valid == NULL || is_valid(value)) {
if (is_valid == nullptr || is_valid(value)) {
values->Add(value);
} else {
uint32_t tag = WireFormatLite::MakeTag(field_number,
@ -475,11 +476,13 @@ void WireFormatLite::WriteEnum(int field_number, int value,
WriteEnumNoTag(value, output);
}
constexpr size_t kInt32MaxSize = std::numeric_limits<int32_t>::max();
void WireFormatLite::WriteString(int field_number, const std::string& value,
io::CodedOutputStream* output) {
// String is for UTF-8 text only
WriteTag(field_number, WIRETYPE_LENGTH_DELIMITED, output);
GOOGLE_CHECK_LE(value.size(), static_cast<size_t>(kint32max));
GOOGLE_CHECK_LE(value.size(), kInt32MaxSize);
output->WriteVarint32(value.size());
output->WriteString(value);
}
@ -488,14 +491,14 @@ void WireFormatLite::WriteStringMaybeAliased(int field_number,
io::CodedOutputStream* output) {
// String is for UTF-8 text only
WriteTag(field_number, WIRETYPE_LENGTH_DELIMITED, output);
GOOGLE_CHECK_LE(value.size(), static_cast<size_t>(kint32max));
GOOGLE_CHECK_LE(value.size(), kInt32MaxSize);
output->WriteVarint32(value.size());
output->WriteRawMaybeAliased(value.data(), value.size());
}
void WireFormatLite::WriteBytes(int field_number, const std::string& value,
io::CodedOutputStream* output) {
WriteTag(field_number, WIRETYPE_LENGTH_DELIMITED, output);
GOOGLE_CHECK_LE(value.size(), static_cast<size_t>(kint32max));
GOOGLE_CHECK_LE(value.size(), kInt32MaxSize);
output->WriteVarint32(value.size());
output->WriteString(value);
}
@ -503,7 +506,7 @@ void WireFormatLite::WriteBytesMaybeAliased(int field_number,
const std::string& value,
io::CodedOutputStream* output) {
WriteTag(field_number, WIRETYPE_LENGTH_DELIMITED, output);
GOOGLE_CHECK_LE(value.size(), static_cast<size_t>(kint32max));
GOOGLE_CHECK_LE(value.size(), kInt32MaxSize);
output->WriteVarint32(value.size());
output->WriteRawMaybeAliased(value.data(), value.size());
}
@ -583,7 +586,7 @@ void PrintUTF8ErrorLog(const char* field_name, const char* operation_str,
bool WireFormatLite::VerifyUtf8String(const char* data, int size, Operation op,
const char* field_name) {
if (!IsStructurallyValidUTF8(data, size)) {
const char* operation_str = NULL;
const char* operation_str = nullptr;
switch (op) {
case PARSE:
operation_str = "parsing";

@ -294,14 +294,15 @@ class PROTOBUF_EXPORT WireFormatLite {
static bool ReadPackedPrimitiveNoInline(io::CodedInputStream* input,
RepeatedField<CType>* value);
// Read a packed enum field. If the is_valid function is not NULL, values for
// which is_valid(value) returns false are silently dropped.
// Read a packed enum field. If the is_valid function is not nullptr, values
// for which is_valid(value) returns false are silently dropped.
static bool ReadPackedEnumNoInline(io::CodedInputStream* input,
bool (*is_valid)(int),
RepeatedField<int>* values);
// Read a packed enum field. If the is_valid function is not NULL, values for
// which is_valid(value) returns false are appended to unknown_fields_stream.
// Read a packed enum field. If the is_valid function is not nullptr, values
// for which is_valid(value) returns false are appended to
// unknown_fields_stream.
static bool ReadPackedEnumPreserveUnknowns(
io::CodedInputStream* input, int field_number, bool (*is_valid)(int),
io::CodedOutputStream* unknown_fields_stream, RepeatedField<int>* values);
@ -1106,7 +1107,7 @@ inline bool WireFormatLite::ReadRepeatedFixedSizePrimitive(
int num_read = 0;
while (num_read < elements_available &&
(buffer = io::CodedInputStream::ExpectTagFromArray(buffer, tag)) !=
NULL) {
nullptr) {
buffer = ReadPrimitiveFromArray<CType, DeclaredType>(buffer, &value);
values->AddAlreadyReserved(value);
++num_read;

@ -270,7 +270,7 @@ DoubleValue::DoubleValue(const DoubleValue& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.DoubleValue)
}
void DoubleValue::SharedCtor() {
inline void DoubleValue::SharedCtor() {
value_ = 0;
}
@ -448,7 +448,7 @@ FloatValue::FloatValue(const FloatValue& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.FloatValue)
}
void FloatValue::SharedCtor() {
inline void FloatValue::SharedCtor() {
value_ = 0;
}
@ -626,7 +626,7 @@ Int64Value::Int64Value(const Int64Value& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.Int64Value)
}
void Int64Value::SharedCtor() {
inline void Int64Value::SharedCtor() {
value_ = int64_t{0};
}
@ -804,7 +804,7 @@ UInt64Value::UInt64Value(const UInt64Value& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.UInt64Value)
}
void UInt64Value::SharedCtor() {
inline void UInt64Value::SharedCtor() {
value_ = uint64_t{0u};
}
@ -982,7 +982,7 @@ Int32Value::Int32Value(const Int32Value& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.Int32Value)
}
void Int32Value::SharedCtor() {
inline void Int32Value::SharedCtor() {
value_ = 0;
}
@ -1160,7 +1160,7 @@ UInt32Value::UInt32Value(const UInt32Value& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.UInt32Value)
}
void UInt32Value::SharedCtor() {
inline void UInt32Value::SharedCtor() {
value_ = 0u;
}
@ -1338,7 +1338,7 @@ BoolValue::BoolValue(const BoolValue& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.BoolValue)
}
void BoolValue::SharedCtor() {
inline void BoolValue::SharedCtor() {
value_ = false;
}
@ -1520,7 +1520,7 @@ StringValue::StringValue(const StringValue& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.StringValue)
}
void StringValue::SharedCtor() {
inline void StringValue::SharedCtor() {
value_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}
@ -1717,7 +1717,7 @@ BytesValue::BytesValue(const BytesValue& from)
// @@protoc_insertion_point(copy_constructor:google.protobuf.BytesValue)
}
void BytesValue::SharedCtor() {
inline void BytesValue::SharedCtor() {
value_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}

Loading…
Cancel
Save