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

pull/8902/head
Adam Cozzette 4 years ago
commit 50ea0dc402
  1. 57
      benchmarks/util/result_parser.py
  2. 44
      java/core/src/main/java/com/google/protobuf/CodedInputStream.java
  3. 2
      java/core/src/test/java/com/google/protobuf/ExtensionRegistryFactoryTest.java
  4. 4
      java/core/src/test/java/com/google/protobuf/TestUtil.java
  5. 14
      java/kotlin/src/main/kotlin/com/google/protobuf/ExtensionList.kt
  6. 932
      java/kotlin/src/test/kotlin/com/google/protobuf/Proto2Test.kt
  7. 15
      java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java
  8. 24
      java/util/src/test/java/com/google/protobuf/util/FieldMaskUtilTest.java
  9. 73
      js/gulpfile.js
  10. 12
      python/google/protobuf/internal/json_format_test.py
  11. 59
      python/google/protobuf/internal/python_protobuf.cc
  12. 9
      python/google/protobuf/internal/well_known_types.py
  13. 8
      python/google/protobuf/pyext/message.cc
  14. 57
      python/google/protobuf/python_protobuf.h
  15. 18
      python/setup.py
  16. 10
      src/google/protobuf/any.cc
  17. 12
      src/google/protobuf/any.h
  18. 2
      src/google/protobuf/any.pb.cc
  19. 5
      src/google/protobuf/any.pb.h
  20. 3
      src/google/protobuf/any_lite.cc
  21. 6
      src/google/protobuf/api.pb.cc
  22. 15
      src/google/protobuf/api.pb.h
  23. 2
      src/google/protobuf/arena_unittest.cc
  24. 14
      src/google/protobuf/arenastring.h
  25. 4
      src/google/protobuf/compiler/command_line_interface.cc
  26. 25
      src/google/protobuf/compiler/cpp/cpp_helpers.cc
  27. 21
      src/google/protobuf/compiler/cpp/cpp_message.cc
  28. 5
      src/google/protobuf/compiler/cpp/cpp_parse_function_generator.cc
  29. 6
      src/google/protobuf/compiler/cpp/cpp_primitive_field.h
  30. 9
      src/google/protobuf/compiler/cpp/cpp_string_field.h
  31. 23
      src/google/protobuf/compiler/cpp/cpp_unittest.inc
  32. 2
      src/google/protobuf/compiler/importer.cc
  33. 2
      src/google/protobuf/compiler/java/java_enum_field.cc
  34. 2
      src/google/protobuf/compiler/java/java_enum_field_lite.cc
  35. 6
      src/google/protobuf/compiler/java/java_extension.h
  36. 7
      src/google/protobuf/compiler/java/java_extension_lite.h
  37. 6
      src/google/protobuf/compiler/java/java_generator_factory.h
  38. 2
      src/google/protobuf/compiler/java/java_helpers.h
  39. 1
      src/google/protobuf/compiler/java/java_map_field.cc
  40. 1
      src/google/protobuf/compiler/java/java_map_field_lite.cc
  41. 6
      src/google/protobuf/compiler/java/java_message.cc
  42. 2
      src/google/protobuf/compiler/java/java_message_field.cc
  43. 3
      src/google/protobuf/compiler/java/java_message_field.h
  44. 2
      src/google/protobuf/compiler/java/java_message_field_lite.cc
  45. 6
      src/google/protobuf/compiler/java/java_message_lite.cc
  46. 12
      src/google/protobuf/compiler/java/java_message_lite.h
  47. 2
      src/google/protobuf/compiler/java/java_primitive_field.cc
  48. 2
      src/google/protobuf/compiler/java/java_primitive_field_lite.cc
  49. 2
      src/google/protobuf/compiler/java/java_service.h
  50. 5
      src/google/protobuf/compiler/java/java_string_field.cc
  51. 3
      src/google/protobuf/compiler/java/java_string_field.h
  52. 2
      src/google/protobuf/compiler/java/java_string_field_lite.cc
  53. 7
      src/google/protobuf/compiler/parser.cc
  54. 2
      src/google/protobuf/compiler/parser_unittest.cc
  55. 9
      src/google/protobuf/compiler/plugin.cc
  56. 8
      src/google/protobuf/compiler/plugin.pb.cc
  57. 20
      src/google/protobuf/compiler/plugin.pb.h
  58. 62
      src/google/protobuf/descriptor.cc
  59. 36
      src/google/protobuf/descriptor.h
  60. 54
      src/google/protobuf/descriptor.pb.cc
  61. 135
      src/google/protobuf/descriptor.pb.h
  62. 16
      src/google/protobuf/descriptor_database.cc
  63. 6
      src/google/protobuf/descriptor_database.h
  64. 38
      src/google/protobuf/descriptor_unittest.cc
  65. 2
      src/google/protobuf/duration.pb.cc
  66. 5
      src/google/protobuf/duration.pb.h
  67. 18
      src/google/protobuf/dynamic_message.cc
  68. 34
      src/google/protobuf/dynamic_message_unittest.cc
  69. 5
      src/google/protobuf/empty.pb.h
  70. 125
      src/google/protobuf/extension_set.cc
  71. 63
      src/google/protobuf/extension_set.h
  72. 12
      src/google/protobuf/extension_set_heavy.cc
  73. 16
      src/google/protobuf/extension_set_unittest.cc
  74. 2
      src/google/protobuf/field_mask.pb.cc
  75. 5
      src/google/protobuf/field_mask.pb.h
  76. 34
      src/google/protobuf/generated_message_reflection.cc
  77. 81
      src/google/protobuf/generated_message_reflection_unittest.cc
  78. 4
      src/google/protobuf/generated_message_table_driven.cc
  79. 7
      src/google/protobuf/generated_message_table_driven.h
  80. 2
      src/google/protobuf/generated_message_table_driven_lite.cc
  81. 26
      src/google/protobuf/generated_message_table_driven_lite.h
  82. 8
      src/google/protobuf/generated_message_util.cc
  83. 4
      src/google/protobuf/implicit_weak_message.h
  84. 10
      src/google/protobuf/inlined_string_field.h
  85. 2
      src/google/protobuf/io/coded_stream.cc
  86. 3
      src/google/protobuf/io/coded_stream.h
  87. 8
      src/google/protobuf/io/printer.h
  88. 53
      src/google/protobuf/io/tokenizer.cc
  89. 27
      src/google/protobuf/io/tokenizer.h
  90. 114
      src/google/protobuf/io/tokenizer_unittest.cc
  91. 20
      src/google/protobuf/map.h
  92. 6
      src/google/protobuf/map_entry_lite.h
  93. 55
      src/google/protobuf/map_field.cc
  94. 12
      src/google/protobuf/map_field.h
  95. 8
      src/google/protobuf/map_field_inl.h
  96. 6
      src/google/protobuf/map_field_lite.h
  97. 4
      src/google/protobuf/map_field_test.cc
  98. 42
      src/google/protobuf/map_test.inc
  99. 6
      src/google/protobuf/map_type_handler.h
  100. 14
      src/google/protobuf/message.cc
  101. Some files were not shown because too many files have changed in this diff Show More

@ -300,29 +300,44 @@ def get_result_from_file(cpp_file="",
return __results
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-cpp", "--cpp_input_file",
help="The CPP benchmark result file's name",
default="")
parser.add_argument("-java", "--java_input_file",
help="The Java benchmark result file's name",
default="")
parser.add_argument("-python", "--python_input_file",
help="The Python benchmark result file's name",
default="")
parser.add_argument("-go", "--go_input_file",
help="The golang benchmark result file's name",
default="")
parser.add_argument("-node", "--node_input_file",
help="The node.js benchmark result file's name",
default="")
parser.add_argument("-php", "--php_input_file",
help="The pure php benchmark result file's name",
default="")
parser.add_argument("-php_c", "--php_c_input_file",
help="The php with c ext benchmark result file's name",
default="")
parser.add_argument(
"-cpp",
"--cpp_input_file",
help="The CPP benchmark result file's name",
default="")
parser.add_argument(
"-java",
"--java_input_file",
help="The Java benchmark result file's name",
default="")
parser.add_argument(
"-python",
"--python_input_file",
help="The Python benchmark result file's name",
default="")
parser.add_argument(
"-go",
"--go_input_file",
help="The golang benchmark result file's name",
default="")
parser.add_argument(
"-node",
"--node_input_file",
help="The node.js benchmark result file's name",
default="")
parser.add_argument(
"-php",
"--php_input_file",
help="The pure php benchmark result file's name",
default="")
parser.add_argument(
"-php_c",
"--php_c_input_file",
help="The php with c ext benchmark result file's name",
default="")
args = parser.parse_args()
results = get_result_from_file(

@ -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();

@ -57,7 +57,7 @@ import org.junit.Ignore;
* <p>The test mechanism employed here is based on the pattern in {@code
* com.google.common.util.concurrent.AbstractFutureFallbackAtomicHelperTest}
*
* <p> This test is temporarily disabled while we figure out how to fix the class loading used for
* <p>This test is temporarily disabled while we figure out how to fix the class loading used for
* testing lite functionality.
*/
@SuppressWarnings("JUnit4ClassUsedInJUnit3")

@ -3758,7 +3758,9 @@ public final class TestUtil {
/** @param filePath The path relative to {@link #getTestDataDir}. */
public static String readTextFromFile(String filePath) {
return readBytesFromFile(filePath).toStringUtf8().replace(System.getProperty("line.separator"), "\n");
return readBytesFromFile(filePath)
.toStringUtf8()
.replace(System.getProperty("line.separator"), "\n");
}
private static File getTestDataDir() {

@ -34,14 +34,14 @@ import com.google.protobuf.ExtensionLite
import com.google.protobuf.MessageLite
/**
* Implementation for ExtensionList and ExtensionListLite. Like [DslList], represents an
* unmodifiable view of a repeated proto field -- in this case, an extension field -- but
* supports querying the extension.
* Implementation for ExtensionList and ExtensionListLite. Like [DslList], represents an
* unmodifiable view of a repeated proto field -- in this case, an extension field -- but supports
* querying the extension.
*/
class ExtensionList<E, M : MessageLite> @OnlyForUseByGeneratedProtoCode constructor(
val extension: ExtensionLite<M, List<E>>,
private val delegate: List<E>
) : List<E> by delegate {
class ExtensionList<E, M : MessageLite>
@OnlyForUseByGeneratedProtoCode
constructor(val extension: ExtensionLite<M, List<E>>, private val delegate: List<E>) :
List<E> by delegate {
override fun iterator(): Iterator<E> = UnmodifiableIterator(delegate.iterator())
override fun listIterator(): ListIterator<E> = UnmodifiableListIterator(delegate.listIterator())

@ -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());
}
}

@ -145,55 +145,50 @@ function getClosureCompilerCommand(exportsFile, outputFile) {
return [
'node_modules/.bin/google-closure-compiler',
`--js=${closureLib}/closure/goog/**.js`,
`--js=${closureLib}/third_party/closure/goog/**.js`,
'--js=map.js',
'--js=message.js',
'--js=binary/arith.js',
'--js=binary/constants.js',
'--js=binary/decoder.js',
'--js=binary/encoder.js',
'--js=binary/reader.js',
'--js=binary/utils.js',
'--js=binary/writer.js',
`--js=${exportsFile}`,
`--entry_point=${exportsFile}`,
`> ${outputFile}`
`--js=${closureLib}/third_party/closure/goog/**.js`, '--js=map.js',
'--js=message.js', '--js=binary/arith.js', '--js=binary/constants.js',
'--js=binary/decoder.js', '--js=binary/encoder.js', '--js=binary/reader.js',
'--js=binary/utils.js', '--js=binary/writer.js', `--js=${exportsFile}`,
`--entry_point=${exportsFile}`, `> ${outputFile}`
].join(' ');
}
gulp.task('dist', gulp.series(['genproto_wellknowntypes'], function(cb) {
// TODO(haberman): minify this more aggressively.
// Will require proper externs/exports.
exec(getClosureCompilerCommand('commonjs/export.js', 'google-protobuf.js'),
function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
exec(
getClosureCompilerCommand('commonjs/export.js', 'google-protobuf.js'),
function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
}));
gulp.task('commonjs_asserts', function (cb) {
exec('mkdir -p commonjs_out/test_node_modules && ' +
getClosureCompilerCommand(
'commonjs/export_asserts.js',
'commonjs_out/test_node_modules/closure_asserts_commonjs.js'),
function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
gulp.task('commonjs_asserts', function(cb) {
exec(
'mkdir -p commonjs_out/test_node_modules && ' +
getClosureCompilerCommand(
'commonjs/export_asserts.js',
'commonjs_out/test_node_modules/closure_asserts_commonjs.js'),
function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('commonjs_testdeps', function (cb) {
exec('mkdir -p commonjs_out/test_node_modules && ' +
getClosureCompilerCommand(
'commonjs/export_testdeps.js',
'commonjs_out/test_node_modules/testdeps_commonjs.js'),
function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
gulp.task('commonjs_testdeps', function(cb) {
exec(
'mkdir -p commonjs_out/test_node_modules && ' +
getClosureCompilerCommand(
'commonjs/export_testdeps.js',
'commonjs_out/test_node_modules/testdeps_commonjs.js'),
function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task(

@ -1124,24 +1124,24 @@ class JsonFormatTest(JsonFormatBase):
text = '{"value": {"foo": 123}}'
self.assertRaisesRegexp(
json_format.ParseError,
r"Timestamp JSON value not a string: {u?'foo': 123}",
json_format.Parse, text, message)
r"Timestamp JSON value not a string: {u?'foo': 123}", json_format.Parse,
text, message)
def testDurationInvalidStringValue(self):
message = json_format_proto3_pb2.TestDuration()
text = '{"value": {"foo": 123}}'
self.assertRaisesRegexp(
json_format.ParseError,
r"Duration JSON value not a string: {u?'foo': 123}",
json_format.Parse, text, message)
r"Duration JSON value not a string: {u?'foo': 123}", json_format.Parse,
text, message)
def testFieldMaskInvalidStringValue(self):
message = json_format_proto3_pb2.TestFieldMask()
text = '{"value": {"foo": 123}}'
self.assertRaisesRegexp(
json_format.ParseError,
r"FieldMask JSON value not a string: {u?'foo': 123}",
json_format.Parse, text, message)
r"FieldMask JSON value not a string: {u?'foo': 123}", json_format.Parse,
text, message)
def testInvalidAny(self):
message = any_pb2.Any()

@ -0,0 +1,59 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Author: qrczak@google.com (Marcin Kowalczyk)
#include <google/protobuf/python/python_protobuf.h>
namespace google {
namespace protobuf {
namespace python {
static const Message* GetCProtoInsidePyProtoStub(PyObject* msg) { return NULL; }
static Message* MutableCProtoInsidePyProtoStub(PyObject* msg) { return NULL; }
// This is initialized with a default, stub implementation.
// If python-google.protobuf.cc is loaded, the function pointer is overridden
// with a full implementation.
const Message* (*GetCProtoInsidePyProtoPtr)(PyObject* msg) =
GetCProtoInsidePyProtoStub;
Message* (*MutableCProtoInsidePyProtoPtr)(PyObject* msg) =
MutableCProtoInsidePyProtoStub;
const Message* GetCProtoInsidePyProto(PyObject* msg) {
return GetCProtoInsidePyProtoPtr(msg);
}
Message* MutableCProtoInsidePyProto(PyObject* msg) {
return MutableCProtoInsidePyProtoPtr(msg);
}
} // namespace python
} // namespace protobuf
} // namespace google

@ -144,8 +144,7 @@ class Timestamp(object):
ValueError: On parsing problems.
"""
if not isinstance(value, six.string_types):
raise ValueError(
'Timestamp JSON value not a string: {!r}'.format(value))
raise ValueError('Timestamp JSON value not a string: {!r}'.format(value))
timezone_offset = value.find('Z')
if timezone_offset == -1:
timezone_offset = value.find('+')
@ -307,8 +306,7 @@ class Duration(object):
ValueError: On parsing problems.
"""
if not isinstance(value, six.string_types):
raise ValueError(
'Duration JSON value not a string: {!r}'.format(value))
raise ValueError('Duration JSON value not a string: {!r}'.format(value))
if len(value) < 1 or value[-1] != 's':
raise ValueError(
'Duration must end with letter "s": {0}.'.format(value))
@ -435,8 +433,7 @@ class FieldMask(object):
def FromJsonString(self, value):
"""Converts string to FieldMask according to proto3 JSON spec."""
if not isinstance(value, six.string_types):
raise ValueError(
'FieldMask JSON value not a string: {!r}'.format(value))
raise ValueError('FieldMask JSON value not a string: {!r}'.format(value))
self.Clear()
if value:
for path in value.split(','):

@ -110,9 +110,10 @@ class MessageReflectionFriend {
const std::vector<const FieldDescriptor*>& fields) {
lhs->GetReflection()->UnsafeShallowSwapFields(lhs, rhs, fields);
}
static bool IsLazyField(const Reflection* reflection,
static bool IsLazyField(const Reflection* reflection, const Message& message,
const FieldDescriptor* field) {
return reflection->IsLazyField(field);
return reflection->IsLazyField(field) ||
reflection->IsLazyExtension(message, field);
}
};
@ -2305,7 +2306,8 @@ CMessage* InternalGetSubMessage(
cmsg->parent_field_descriptor = field_descriptor;
if (reflection->HasField(*self->message, field_descriptor)) {
// Force triggering MutableMessage to set the lazy message 'Dirty'
if (MessageReflectionFriend::IsLazyField(reflection, field_descriptor)) {
if (MessageReflectionFriend::IsLazyField(reflection, *self->message,
field_descriptor)) {
Message* sub_message = reflection->MutableMessage(
self->message, field_descriptor, factory->message_factory);
cmsg->read_only = false;

@ -0,0 +1,57 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Author: qrczak@google.com (Marcin Kowalczyk)
//
// This module exposes the C proto inside the given Python proto, in
// case the Python proto is implemented with a C proto.
#ifndef GOOGLE_PROTOBUF_PYTHON_PYTHON_PROTOBUF_H__
#define GOOGLE_PROTOBUF_PYTHON_PYTHON_PROTOBUF_H__
#include <Python.h>
namespace google {
namespace protobuf {
class Message;
namespace python {
// Return the pointer to the C proto inside the given Python proto,
// or NULL when this is not a Python proto implemented with a C proto.
const Message* GetCProtoInsidePyProto(PyObject* msg);
Message* MutableCProtoInsidePyProto(PyObject* msg);
} // namespace python
} // namespace protobuf
} // namespace google
#endif // GOOGLE_PROTOBUF_PYTHON_PYTHON_PROTOBUF_H__

@ -18,7 +18,6 @@ from setuptools import setup, Extension, find_packages
from distutils.command.build_py import build_py as _build_py
from distutils.command.clean import clean as _clean
from distutils.command.build_ext import build_ext as _build_ext
from distutils.spawn import find_executable
# Find the Protocol Compiler.
@ -158,22 +157,6 @@ class build_py(_build_py):
if not any(fnmatch.fnmatchcase(fil, pat=pat) for pat in exclude)]
class build_ext(_build_ext):
def get_ext_filename(self, ext_name):
# since python3.5, python extensions' shared libraries use a suffix that corresponds to the value
# of sysconfig.get_config_var('EXT_SUFFIX') and contains info about the architecture the library targets.
# E.g. on x64 linux the suffix is ".cpython-XYZ-x86_64-linux-gnu.so"
# When crosscompiling python wheels, we need to be able to override this suffix
# so that the resulting file name matches the target architecture and we end up with a well-formed
# wheel.
filename = _build_ext.get_ext_filename(self, ext_name)
orig_ext_suffix = sysconfig.get_config_var("EXT_SUFFIX")
new_ext_suffix = os.getenv("PROTOCOL_BUFFERS_OVERRIDE_EXT_SUFFIX")
if new_ext_suffix and filename.endswith(orig_ext_suffix):
filename = filename[:-len(orig_ext_suffix)] + new_ext_suffix
return filename
class test_conformance(_build_py):
target = 'test_python'
def run(self):
@ -308,7 +291,6 @@ if __name__ == '__main__':
cmdclass={
'clean': clean,
'build_py': build_py,
'build_ext': build_ext,
'test_conformance': test_conformance,
},
install_requires=install_requires,

@ -45,13 +45,11 @@ bool AnyMetadata::PackFrom(Arena* arena, const Message& message) {
return PackFrom(arena, message, kTypeGoogleApisComPrefix);
}
bool AnyMetadata::PackFrom(Arena* arena,
const Message& message,
bool AnyMetadata::PackFrom(Arena* arena, const Message& message,
StringPiece type_url_prefix) {
type_url_->Set(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString(),
GetTypeUrl(message.GetDescriptor()->full_name(), type_url_prefix),
arena);
GetTypeUrl(message.GetDescriptor()->full_name(), type_url_prefix), arena);
return message.SerializeToString(
value_->Mutable(ArenaStringPtr::EmptyDefault{}, arena));
}
@ -72,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);
}

@ -82,11 +82,14 @@ class PROTOBUF_EXPORT AnyMetadata {
// URL: "type.googleapis.com/<message_full_name>".
// Returns false if serializing the message failed.
template <typename T>
bool PackFrom(Arena* arena, const T& message, StringPiece type_url_prefix) {
return InternalPackFrom(arena, message, type_url_prefix, T::FullMessageName());
bool PackFrom(Arena* arena, const T& message,
StringPiece type_url_prefix) {
return InternalPackFrom(arena, message, type_url_prefix,
T::FullMessageName());
}
bool PackFrom(Arena* arena, const Message& message, StringPiece type_url_prefix);
bool PackFrom(Arena* arena, const Message& message,
StringPiece type_url_prefix);
// Unpacks the payload into the given message. Returns false if the message's
// type doesn't match the type specified in the type URL (i.e., the full
@ -108,8 +111,7 @@ class PROTOBUF_EXPORT AnyMetadata {
}
private:
bool InternalPackFrom(Arena* arena,
const MessageLite& message,
bool InternalPackFrom(Arena* arena, const MessageLite& message,
StringPiece type_url_prefix,
StringPiece type_name);
bool InternalUnpackTo(StringPiece type_name,

@ -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());
}

@ -153,7 +153,12 @@ class PROTOBUF_EXPORT Any final :
}
inline void Swap(Any* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);

@ -53,8 +53,7 @@ const char kAnyFullTypeName[] = "google.protobuf.Any";
const char kTypeGoogleApisComPrefix[] = "type.googleapis.com/";
const char kTypeGoogleProdComPrefix[] = "type.googleprod.com/";
bool AnyMetadata::InternalPackFrom(Arena* arena,
const MessageLite& message,
bool AnyMetadata::InternalPackFrom(Arena* arena, const MessageLite& message,
StringPiece type_url_prefix,
StringPiece type_name) {
type_url_->Set(&::google::protobuf::internal::GetEmptyString(),

@ -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());
}

@ -130,7 +130,12 @@ class PROTOBUF_EXPORT Api final :
}
inline void Swap(Api* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -385,7 +390,12 @@ class PROTOBUF_EXPORT Method final :
}
inline void Swap(Method* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -618,7 +628,12 @@ class PROTOBUF_EXPORT Mixin final :
}
inline void Swap(Mixin* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);

@ -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

@ -402,8 +402,8 @@ class CommandLineInterface::GeneratorContextImpl : public GeneratorContext {
// implements GeneratorContext --------------------------------------
io::ZeroCopyOutputStream* Open(const std::string& filename) override;
io::ZeroCopyOutputStream* OpenForAppend(const std::string& filename) override;
io::ZeroCopyOutputStream* OpenForInsert(const std::string& filename,
const std::string& insertion_point) override;
io::ZeroCopyOutputStream* OpenForInsert(
const std::string& filename, const std::string& insertion_point) override;
io::ZeroCopyOutputStream* OpenForInsertWithGeneratedCodeInfo(
const std::string& filename, const std::string& insertion_point,
const google::protobuf::GeneratedCodeInfo& info) override;

@ -777,8 +777,10 @@ std::string SafeFunctionName(const Descriptor* descriptor,
return function_name;
}
bool IsStringInlined(const FieldDescriptor* /* descriptor */,
const Options& /* options */) {
bool IsStringInlined(const FieldDescriptor* descriptor,
const Options& options) {
(void)descriptor;
(void)options;
return false;
}
@ -939,15 +941,19 @@ bool HasEnumDefinitions(const FileDescriptor* file) {
return false;
}
bool ShouldVerify(const Descriptor* /* descriptor */,
const Options& /* options */,
MessageSCCAnalyzer* /* scc_analyzer */) {
bool ShouldVerify(const Descriptor* descriptor, const Options& options,
MessageSCCAnalyzer* scc_analyzer) {
(void)descriptor;
(void)options;
(void)scc_analyzer;
return false;
}
bool ShouldVerify(const FileDescriptor* /* file */,
const Options& /* options */,
MessageSCCAnalyzer* /* scc_analyzer */) {
bool ShouldVerify(const FileDescriptor* file, const Options& options,
MessageSCCAnalyzer* scc_analyzer) {
(void)file;
(void)options;
(void)scc_analyzer;
return false;
}
@ -1470,7 +1476,8 @@ FileOptions_OptimizeMode GetOptimizeFor(const FileDescriptor* file,
return FileOptions::SPEED;
}
bool EnableMessageOwnedArena(const Descriptor* /* desc */) {
bool EnableMessageOwnedArena(const Descriptor* desc) {
(void)desc;
return false;
}

@ -1565,7 +1565,8 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
"bool PackFrom(const ::$proto_ns$::Message& message,\n"
" ::PROTOBUF_NAMESPACE_ID::ConstStringParam "
"type_url_prefix) {\n"
" return _any_metadata_.PackFrom(GetArena(), message, type_url_prefix);\n"
" return _any_metadata_.PackFrom(GetArena(), message, "
"type_url_prefix);\n"
"}\n"
"bool UnpackTo(::$proto_ns$::Message* message) const {\n"
" return _any_metadata_.UnpackTo(message);\n"
@ -1586,7 +1587,8 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
"bool PackFrom(const T& message,\n"
" ::PROTOBUF_NAMESPACE_ID::ConstStringParam "
"type_url_prefix) {\n"
" return _any_metadata_.PackFrom<T>(GetArena(), message, type_url_prefix);"
" return _any_metadata_.PackFrom<T>(GetArena(), message, "
"type_url_prefix);"
"}\n"
"template <typename T, class = typename std::enable_if<"
"!std::is_convertible<T, const ::$proto_ns$::Message&>"
@ -1598,13 +1600,14 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
format(
"template <typename T>\n"
"bool PackFrom(const T& message) {\n"
" return _any_metadata_.PackFrom(message);\n"
" return _any_metadata_.PackFrom(GetArena(), message);\n"
"}\n"
"template <typename T>\n"
"bool PackFrom(const T& message,\n"
" ::PROTOBUF_NAMESPACE_ID::ConstStringParam "
"type_url_prefix) {\n"
" return _any_metadata_.PackFrom(message, type_url_prefix);\n"
" return _any_metadata_.PackFrom(GetArena(), message, "
"type_url_prefix);\n"
"}\n"
"template <typename T>\n"
"bool UnpackTo(T* message) const {\n"
@ -1626,12 +1629,12 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
"}\n"
"inline void Swap($classname$* other) {\n"
" if (other == this) return;\n"
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
"#ifdef PROTOBUF_FORCE_COPY_IN_SWAP\n"
" if (GetOwningArena() != nullptr &&\n"
" GetOwningArena() == other->GetOwningArena()) {\n"
#else // PROTOBUF_FORCE_COPY_IN_SWAP
" GetOwningArena() == other->GetOwningArena()) {\n "
"#else // PROTOBUF_FORCE_COPY_IN_SWAP\n"
" if (GetOwningArena() == other->GetOwningArena()) {\n"
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
"#endif // !PROTOBUF_FORCE_COPY_IN_SWAP\n"
" InternalSwap(other);\n"
" } else {\n"
" ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);\n"
@ -2796,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);

@ -1146,9 +1146,8 @@ std::string FieldParseFunctionName(const FieldDescriptor* field,
type_format = TypeFormat::kStringValidateOnly;
break;
default:
GOOGLE_LOG(DFATAL)
<< "Mode not handled: "
<< static_cast<int>(GetUtf8CheckMode(field, options));
GOOGLE_LOG(DFATAL) << "Mode not handled: "
<< static_cast<int>(GetUtf8CheckMode(field, options));
return "";
}
break;

@ -59,7 +59,8 @@ class PrimitiveFieldGenerator : public FieldGenerator {
void GenerateSwappingCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override;
void GenerateCopyConstructorCode(io::Printer* printer) const override;
void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const override;
void GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const override;
void GenerateByteSize(io::Printer* printer) const override;
void GenerateConstinitInitializer(io::Printer* printer) const override;
@ -98,7 +99,8 @@ class RepeatedPrimitiveFieldGenerator : public FieldGenerator {
void GenerateSwappingCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override;
void GenerateCopyConstructorCode(io::Printer* printer) const override;
void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const override;
void GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const override;
void GenerateByteSize(io::Printer* printer) const override;
void GenerateConstinitInitializer(io::Printer* printer) const override;

@ -55,7 +55,8 @@ class StringFieldGenerator : public FieldGenerator {
void GenerateStaticMembers(io::Printer* printer) const override;
void GenerateAccessorDeclarations(io::Printer* printer) const override;
void GenerateInlineAccessorDefinitions(io::Printer* printer) const override;
void GenerateNonInlineAccessorDefinitions(io::Printer* printer) const override;
void GenerateNonInlineAccessorDefinitions(
io::Printer* printer) const override;
void GenerateClearingCode(io::Printer* printer) const override;
void GenerateMessageClearingCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override;
@ -63,7 +64,8 @@ class StringFieldGenerator : public FieldGenerator {
void GenerateConstructorCode(io::Printer* printer) const override;
void GenerateCopyConstructorCode(io::Printer* printer) const override;
void GenerateDestructorCode(io::Printer* printer) const override;
void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const override;
void GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const override;
void GenerateByteSize(io::Printer* printer) const override;
void GenerateConstinitInitializer(io::Printer* printer) const override;
bool IsInlined() const override { return inlined_; }
@ -108,7 +110,8 @@ class RepeatedStringFieldGenerator : public FieldGenerator {
void GenerateSwappingCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override;
void GenerateCopyConstructorCode(io::Printer* printer) const override;
void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const override;
void GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const override;
void GenerateByteSize(io::Printer* printer) const override;
void GenerateConstinitInitializer(io::Printer* printer) const override;

@ -1159,10 +1159,8 @@ class GENERATED_SERVICE_TEST_NAME : public testing::Test {
// implements TestService ----------------------------------------
void Foo(RpcController* controller,
const UNITTEST::FooRequest* request,
UNITTEST::FooResponse* response,
Closure* done) override {
void Foo(RpcController* controller, const UNITTEST::FooRequest* request,
UNITTEST::FooResponse* response, Closure* done) override {
ASSERT_FALSE(called_);
called_ = true;
method_ = "Foo";
@ -1172,10 +1170,8 @@ class GENERATED_SERVICE_TEST_NAME : public testing::Test {
done_ = done;
}
void Bar(RpcController* controller,
const UNITTEST::BarRequest* request,
UNITTEST::BarResponse* response,
Closure* done) override {
void Bar(RpcController* controller, const UNITTEST::BarRequest* request,
UNITTEST::BarResponse* response, Closure* done) override {
ASSERT_FALSE(called_);
called_ = true;
method_ = "Bar";
@ -1214,10 +1210,8 @@ class GENERATED_SERVICE_TEST_NAME : public testing::Test {
// implements TestService ----------------------------------------
void CallMethod(const MethodDescriptor* method,
RpcController* controller,
const Message* request,
Message* response,
void CallMethod(const MethodDescriptor* method, RpcController* controller,
const Message* request, Message* response,
Closure* done) override {
ASSERT_FALSE(called_);
called_ = true;
@ -1274,7 +1268,7 @@ class GENERATED_SERVICE_TEST_NAME : public testing::Test {
stub_(&mock_channel_),
done_(::google::protobuf::NewPermanentCallback(&DoNothing)) {}
virtual void SetUp() override {
void SetUp() override {
ASSERT_TRUE(foo_ != NULL);
ASSERT_TRUE(bar_ != NULL);
}
@ -1437,8 +1431,7 @@ TEST_F(GENERATED_SERVICE_TEST_NAME, NotImplemented) {
class OneofTest : public testing::Test {
protected:
virtual void SetUp() override {
}
void SetUp() override {}
void ExpectEnumCasesWork(const UNITTEST::TestOneof2 &message) {
switch (message.foo_case()) {

@ -467,7 +467,7 @@ io::ZeroCopyInputStream* DiskSourceTree::OpenVirtualFile(
for (const auto& mapping : mappings_) {
std::string temp_disk_file;
if (ApplyMapping(virtual_file, mapping.virtual_path, mapping.disk_path,
&temp_disk_file)) {
&temp_disk_file)) {
io::ZeroCopyInputStream* stream = OpenDiskFile(temp_disk_file);
if (stream != NULL) {
if (disk_file != NULL) {

@ -1110,6 +1110,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateKotlinDslMembers(
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(value: $kt_type$) {\n"
@ -1133,6 +1134,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateKotlinDslMembers(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(values: kotlin.collections.Iterable<$kt_type$>) {\n"

@ -852,6 +852,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers(
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(value: $kt_type$) {\n"
@ -875,6 +876,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(values: kotlin.collections.Iterable<$kt_type$>) {\n"

@ -94,9 +94,9 @@ class ImmutableExtensionGenerator : public ExtensionGenerator {
Context* context);
virtual ~ImmutableExtensionGenerator();
virtual void Generate(io::Printer* printer) override;
virtual int GenerateNonNestedInitializationCode(io::Printer* printer) override;
virtual int GenerateRegistrationCode(io::Printer* printer) override;
void Generate(io::Printer* printer) override;
int GenerateNonNestedInitializationCode(io::Printer* printer) override;
int GenerateRegistrationCode(io::Printer* printer) override;
protected:
const FieldDescriptor* descriptor_;

@ -51,14 +51,13 @@ class ImmutableExtensionLiteGenerator : public ExtensionGenerator {
Context* context);
virtual ~ImmutableExtensionLiteGenerator();
virtual void Generate(io::Printer* printer) override;
void Generate(io::Printer* printer) override;
// Returns an estimate of the number of bytes the printed code will compile to
virtual int GenerateNonNestedInitializationCode(
io::Printer* printer) override;
int GenerateNonNestedInitializationCode(io::Printer* printer) override;
// Returns an estimate of the number of bytes the printed code will compile to
virtual int GenerateRegistrationCode(io::Printer* printer) override;
int GenerateRegistrationCode(io::Printer* printer) override;
private:
const FieldDescriptor* descriptor_;

@ -80,13 +80,13 @@ class ImmutableGeneratorFactory : public GeneratorFactory {
ImmutableGeneratorFactory(Context* context);
virtual ~ImmutableGeneratorFactory();
virtual MessageGenerator* NewMessageGenerator(
MessageGenerator* NewMessageGenerator(
const Descriptor* descriptor) const override;
virtual ExtensionGenerator* NewExtensionGenerator(
ExtensionGenerator* NewExtensionGenerator(
const FieldDescriptor* descriptor) const override;
virtual ServiceGenerator* NewServiceGenerator(
ServiceGenerator* NewServiceGenerator(
const ServiceDescriptor* descriptor) const override;
private:

@ -155,7 +155,7 @@ std::string GetOneofStoredType(const FieldDescriptor* field);
// Whether we should generate multiple java files for messages.
inline bool MultipleJavaFiles(const FileDescriptor* descriptor,
bool immutable) {
(void) immutable;
(void)immutable;
return descriptor->options().java_multiple_files();
}

@ -709,6 +709,7 @@ void ImmutableMapFieldGenerator::GenerateKotlinDslMembers(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@JvmName(\"set$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun com.google.protobuf.kotlin.DslMap"
"<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n"
" .set(key: $kt_key_type$, value: $kt_value_type$) {\n"

@ -852,6 +852,7 @@ void ImmutableMapFieldLiteGenerator::GenerateKotlinDslMembers(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@JvmName(\"set$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun com.google.protobuf.kotlin.DslMap"
"<$kt_key_type$, $kt_value_type$, ${$$kt_capitalized_name$Proxy$}$>\n"
" .set(key: $kt_key_type$, value: $kt_value_type$) {\n"

@ -1555,6 +1555,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun <T : Comparable<T>> set(\n"
" extension: com.google.protobuf.ExtensionLite<$message$, T>,\n"
" value: T\n"
@ -1565,6 +1566,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun set(\n"
" extension: com.google.protobuf.ExtensionLite<$message$, "
"com.google.protobuf.ByteString>,\n"
@ -1576,6 +1578,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun <T : com.google.protobuf.MessageLite> set(\n"
" extension: com.google.protobuf.ExtensionLite<$message$, T>,\n"
" value: T\n"
@ -1594,6 +1597,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun <E> com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.plusAssign"
"(value: E) {\n"
@ -1613,6 +1617,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun <E> com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.plusAssign(values: "
"Iterable<E>) {\n"
@ -1631,6 +1636,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline fun com.google.protobuf.kotlin.ExtensionList<*, "
"$message$>.clear() {\n"
" clear(extension)\n"

@ -1432,6 +1432,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers(
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(value: $kt_type$) {\n"
@ -1455,6 +1456,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(values: kotlin.collections.Iterable<$kt_type$>) {\n"

@ -78,7 +78,8 @@ class ImmutableMessageFieldGenerator : public ImmutableFieldGenerator {
void GenerateParsingDoneCode(io::Printer* printer) const override;
void GenerateSerializationCode(io::Printer* printer) const override;
void GenerateSerializedSizeCode(io::Printer* printer) const override;
void GenerateFieldBuilderInitializationCode(io::Printer* printer) const override;
void GenerateFieldBuilderInitializationCode(
io::Printer* printer) const override;
void GenerateEqualsCode(io::Printer* printer) const override;
void GenerateHashCode(io::Printer* printer) const override;
void GenerateKotlinDslMembers(io::Printer* printer) const override;

@ -822,6 +822,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers(
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(value: $kt_type$) {\n"
@ -845,6 +846,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(values: kotlin.collections.Iterable<$kt_type$>) {\n"

@ -877,6 +877,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun <T : Comparable<T>> set(\n"
" extension: com.google.protobuf.ExtensionLite<$message$, T>,\n"
" value: T\n"
@ -887,6 +888,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun set(\n"
" extension: com.google.protobuf.ExtensionLite<$message$, "
"com.google.protobuf.ByteString>,\n"
@ -898,6 +900,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun <T : com.google.protobuf.MessageLite> set(\n"
" extension: com.google.protobuf.ExtensionLite<$message$, T>,\n"
" value: T\n"
@ -916,6 +919,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun <E> com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.plusAssign"
"(value: E) {\n"
@ -935,6 +939,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun <E> com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.plusAssign(values: "
"Iterable<E>) {\n"
@ -953,6 +958,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline fun com.google.protobuf.kotlin.ExtensionList<*, "
"$message$>.clear() {\n"
" clear(extension)\n"

@ -50,12 +50,12 @@ class ImmutableMessageLiteGenerator : public MessageGenerator {
ImmutableMessageLiteGenerator(const Descriptor* descriptor, Context* context);
virtual ~ImmutableMessageLiteGenerator();
virtual void Generate(io::Printer* printer) override;
virtual void GenerateInterface(io::Printer* printer) override;
virtual void GenerateExtensionRegistrationCode(io::Printer* printer) override;
virtual void GenerateStaticVariables(io::Printer* printer,
int* bytecode_estimate) override;
virtual int GenerateStaticVariableInitializers(io::Printer* printer) override;
void Generate(io::Printer* printer) override;
void GenerateInterface(io::Printer* printer) override;
void GenerateExtensionRegistrationCode(io::Printer* printer) override;
void GenerateStaticVariables(io::Printer* printer,
int* bytecode_estimate) override;
int GenerateStaticVariableInitializers(io::Printer* printer) override;
void GenerateKotlinDsl(io::Printer* printer) const override;
void GenerateKotlinMembers(io::Printer* printer) const override;
void GenerateTopLevelKotlinMembers(io::Printer* printer) const override;

@ -864,6 +864,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers(
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(value: $kt_type$) {\n"
@ -887,6 +888,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(values: kotlin.collections.Iterable<$kt_type$>) {\n"

@ -687,6 +687,7 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers(
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(value: $kt_type$) {\n"
@ -710,6 +711,7 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun com.google.protobuf.kotlin.DslList"
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(values: kotlin.collections.Iterable<$kt_type$>) {\n"

@ -80,7 +80,7 @@ class ImmutableServiceGenerator : public ServiceGenerator {
Context* context);
virtual ~ImmutableServiceGenerator();
virtual void Generate(io::Printer* printer) override;
void Generate(io::Printer* printer) override;
private:
// Generate the getDescriptorForType() method.

@ -81,7 +81,8 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
" throw new NullPointerException();\n"
" }\n";
(*variables)["isStringEmpty"] = "com.google.protobuf.GeneratedMessage" +
GeneratedCodeVersionSuffix() + ".isStringEmpty";
GeneratedCodeVersionSuffix() +
".isStringEmpty";
(*variables)["writeString"] = "com.google.protobuf.GeneratedMessage" +
GeneratedCodeVersionSuffix() + ".writeString";
(*variables)["computeStringSize"] = "com.google.protobuf.GeneratedMessage" +
@ -119,7 +120,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
(*variables)["clear_has_field_bit_builder"] = "";
(*variables)["is_field_present_message"] =
"!" + (*variables)["isStringEmpty"] + "(" + (*variables)["name"] + "_)";
"!" + (*variables)["isStringEmpty"] + "(" + (*variables)["name"] + "_)";
}
// For repeated builders, one bit is used for whether the array is immutable.

@ -78,7 +78,8 @@ class ImmutableStringFieldGenerator : public ImmutableFieldGenerator {
void GenerateParsingDoneCode(io::Printer* printer) const override;
void GenerateSerializationCode(io::Printer* printer) const override;
void GenerateSerializedSizeCode(io::Printer* printer) const override;
void GenerateFieldBuilderInitializationCode(io::Printer* printer) const override;
void GenerateFieldBuilderInitializationCode(
io::Printer* printer) const override;
void GenerateEqualsCode(io::Printer* printer) const override;
void GenerateHashCode(io::Printer* printer) const override;
void GenerateKotlinDslMembers(io::Printer* printer) const override;

@ -781,6 +781,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers(
printer->Print(variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun com.google.protobuf.kotlin.DslList"
"<kotlin.String, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(value: kotlin.String) {\n"
@ -807,6 +808,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers(
variables_,
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.jvm.JvmName(\"plusAssignAll$kt_capitalized_name$\")\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"inline operator fun com.google.protobuf.kotlin.DslList"
"<kotlin.String, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(values: kotlin.collections.Iterable<kotlin.String>) {\n"

@ -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);

@ -2588,7 +2588,7 @@ class SourceInfoTest : public ParserTest {
return true;
}
virtual void TearDown() override {
void TearDown() override {
EXPECT_TRUE(spans_.empty()) << "Forgot to call HasSpan() for:\n"
<< spans_.begin()->second->DebugString();
}

@ -72,21 +72,22 @@ class GeneratorResponseContext : public GeneratorContext {
// implements GeneratorContext --------------------------------------
virtual io::ZeroCopyOutputStream* Open(const std::string& filename) override {
io::ZeroCopyOutputStream* Open(const std::string& filename) override {
CodeGeneratorResponse::File* file = response_->add_file();
file->set_name(filename);
return new io::StringOutputStream(file->mutable_content());
}
virtual io::ZeroCopyOutputStream* OpenForInsert(
const std::string& filename, const std::string& insertion_point) override {
io::ZeroCopyOutputStream* OpenForInsert(
const std::string& filename,
const std::string& insertion_point) override {
CodeGeneratorResponse::File* file = response_->add_file();
file->set_name(filename);
file->set_insertion_point(insertion_point);
return new io::StringOutputStream(file->mutable_content());
}
virtual io::ZeroCopyOutputStream* OpenForInsertWithGeneratedCodeInfo(
io::ZeroCopyOutputStream* OpenForInsertWithGeneratedCodeInfo(
const std::string& filename, const std::string& insertion_point,
const google::protobuf::GeneratedCodeInfo& info) override {
CodeGeneratorResponse::File* file = response_->add_file();

@ -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};
}

@ -173,7 +173,12 @@ class PROTOC_EXPORT Version final :
}
inline void Swap(Version* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -378,7 +383,12 @@ class PROTOC_EXPORT CodeGeneratorRequest final :
}
inline void Swap(CodeGeneratorRequest* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -604,7 +614,12 @@ class PROTOC_EXPORT CodeGeneratorResponse_File final :
}
inline void Swap(CodeGeneratorResponse_File* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -824,7 +839,12 @@ class PROTOC_EXPORT CodeGeneratorResponse final :
}
inline void Swap(CodeGeneratorResponse* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);

@ -993,12 +993,12 @@ class TableArena {
to_relocate->PrependTo(full_blocks_);
}
static constexpr std::array<uint8_t, 6> kSmallSizes = {{
// Sizes for pointer arrays.
8, 16, 24, 32,
// Sizes for string arrays (for descriptor names).
// The most common array sizes are 2 and 3.
2 * sizeof(std::string), 3 * sizeof(std::string)}};
static constexpr std::array<uint8_t, 6> kSmallSizes = {
{// Sizes for pointer arrays.
8, 16, 24, 32,
// Sizes for string arrays (for descriptor names).
// The most common array sizes are 2 and 3.
2 * sizeof(std::string), 3 * sizeof(std::string)}};
// Helper function to iterate all lists.
std::array<Block*, 2 + kSmallSizes.size()> GetLists() const {
@ -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() {

@ -391,7 +391,12 @@ class PROTOBUF_EXPORT FileDescriptorSet final :
}
inline void Swap(FileDescriptorSet* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -550,7 +555,12 @@ class PROTOBUF_EXPORT FileDescriptorProto final :
}
inline void Swap(FileDescriptorProto* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -944,7 +954,12 @@ class PROTOBUF_EXPORT DescriptorProto_ExtensionRange final :
}
inline void Swap(DescriptorProto_ExtensionRange* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -1134,7 +1149,12 @@ class PROTOBUF_EXPORT DescriptorProto_ReservedRange final :
}
inline void Swap(DescriptorProto_ReservedRange* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -1304,7 +1324,12 @@ class PROTOBUF_EXPORT DescriptorProto final :
}
inline void Swap(DescriptorProto* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -1653,7 +1678,12 @@ class PROTOBUF_EXPORT ExtensionRangeOptions final :
}
inline void Swap(ExtensionRangeOptions* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -2004,7 +2034,12 @@ class PROTOBUF_EXPORT FieldDescriptorProto final :
}
inline void Swap(FieldDescriptorProto* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -2433,7 +2468,12 @@ class PROTOBUF_EXPORT OneofDescriptorProto final :
}
inline void Swap(OneofDescriptorProto* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -2613,7 +2653,12 @@ class PROTOBUF_EXPORT EnumDescriptorProto_EnumReservedRange final :
}
inline void Swap(EnumDescriptorProto_EnumReservedRange* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -2783,7 +2828,12 @@ class PROTOBUF_EXPORT EnumDescriptorProto final :
}
inline void Swap(EnumDescriptorProto* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -3031,7 +3081,12 @@ class PROTOBUF_EXPORT EnumValueDescriptorProto final :
}
inline void Swap(EnumValueDescriptorProto* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -3226,7 +3281,12 @@ class PROTOBUF_EXPORT ServiceDescriptorProto final :
}
inline void Swap(ServiceDescriptorProto* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -3426,7 +3486,12 @@ class PROTOBUF_EXPORT MethodDescriptorProto final :
}
inline void Swap(MethodDescriptorProto* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -3676,7 +3741,12 @@ class PROTOBUF_EXPORT FileOptions final :
}
inline void Swap(FileOptions* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -4410,7 +4480,12 @@ class PROTOBUF_EXPORT MessageOptions final :
}
inline void Swap(MessageOptions* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -4822,7 +4897,12 @@ class PROTOBUF_EXPORT FieldOptions final :
}
inline void Swap(FieldOptions* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -5328,7 +5408,12 @@ class PROTOBUF_EXPORT OneofOptions final :
}
inline void Swap(OneofOptions* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -5679,7 +5764,12 @@ class PROTOBUF_EXPORT EnumOptions final :
}
inline void Swap(EnumOptions* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -6061,7 +6151,12 @@ class PROTOBUF_EXPORT EnumValueOptions final :
}
inline void Swap(EnumValueOptions* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -6428,7 +6523,12 @@ class PROTOBUF_EXPORT ServiceOptions final :
}
inline void Swap(ServiceOptions* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -6795,7 +6895,12 @@ class PROTOBUF_EXPORT MethodOptions final :
}
inline void Swap(MethodOptions* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -7209,7 +7314,12 @@ class PROTOBUF_EXPORT UninterpretedOption_NamePart final :
}
inline void Swap(UninterpretedOption_NamePart* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -7387,7 +7497,12 @@ class PROTOBUF_EXPORT UninterpretedOption final :
}
inline void Swap(UninterpretedOption* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -7654,7 +7769,12 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location final :
}
inline void Swap(SourceCodeInfo_Location* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -7910,7 +8030,12 @@ class PROTOBUF_EXPORT SourceCodeInfo final :
}
inline void Swap(SourceCodeInfo* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -8071,7 +8196,12 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation final :
}
inline void Swap(GeneratedCodeInfo_Annotation* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
@ -8286,7 +8416,12 @@ class PROTOBUF_EXPORT GeneratedCodeInfo final :
}
inline void Swap(GeneratedCodeInfo* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);

@ -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);

@ -299,7 +299,7 @@ class MockErrorCollector : public DescriptorPool::ErrorCollector {
// Test simple files.
class FileDescriptorTest : public testing::Test {
protected:
virtual void SetUp() override {
void SetUp() override {
// Build descriptors for the following definitions:
//
// // in "foo.proto"
@ -614,7 +614,7 @@ TEST_F(FileDescriptorTest, DebugStringRoundTrip) {
// Test simple flat messages and fields.
class DescriptorTest : public testing::Test {
protected:
virtual void SetUp() override {
void SetUp() override {
// Build descriptors for the following definitions:
//
// // in "foo.proto"
@ -1101,7 +1101,7 @@ TEST_F(DescriptorTest, FieldEnumType) {
// Test simple flat messages and fields.
class OneofDescriptorTest : public testing::Test {
protected:
virtual void SetUp() override {
void SetUp() override {
// Build descriptors for the following definitions:
//
// package garply;
@ -1361,7 +1361,7 @@ TEST_F(StylizedFieldNamesTest, FindByCamelcaseName) {
// Test enum descriptors.
class EnumDescriptorTest : public testing::Test {
protected:
virtual void SetUp() override {
void SetUp() override {
// Build descriptors for the following definitions:
//
// // in "foo.proto"
@ -1512,7 +1512,7 @@ TEST_F(EnumDescriptorTest, ValueType) {
// Test service descriptors.
class ServiceDescriptorTest : public testing::Test {
protected:
virtual void SetUp() override {
void SetUp() override {
// Build descriptors for the following messages and service:
// // in "foo.proto"
// message FooRequest {}
@ -1673,7 +1673,7 @@ TEST_F(ServiceDescriptorTest, MethodOutputType) {
// Test nested types.
class NestedDescriptorTest : public testing::Test {
protected:
virtual void SetUp() override {
void SetUp() override {
// Build descriptors for the following definitions:
//
// // in "foo.proto"
@ -1887,7 +1887,7 @@ TEST_F(NestedDescriptorTest, FindEnumValueByName) {
// Test extensions.
class ExtensionDescriptorTest : public testing::Test {
protected:
virtual void SetUp() override {
void SetUp() override {
// Build descriptors for the following definitions:
//
// enum Baz {}
@ -2210,7 +2210,7 @@ TEST(OverlappingExtensionRangeTest, ExtensionRangeBefore) {
// Test reserved fields.
class ReservedDescriptorTest : public testing::Test {
protected:
virtual void SetUp() override {
void SetUp() override {
// Build descriptors for the following definitions:
//
// message Foo {
@ -2288,7 +2288,7 @@ TEST_F(ReservedDescriptorTest, IsReservedName) {
// Test reserved enum fields.
class ReservedEnumDescriptorTest : public testing::Test {
protected:
virtual void SetUp() override {
void SetUp() override {
// Build descriptors for the following definitions:
//
// enum Foo {
@ -2814,7 +2814,7 @@ class AllowUnknownDependenciesTest
DescriptorPoolMode mode() { return std::get<0>(GetParam()); }
const char* syntax() { return std::get<1>(GetParam()); }
virtual void SetUp() override {
void SetUp() override {
FileDescriptorProto foo_proto, bar_proto;
switch (mode()) {
@ -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));
@ -6792,7 +6799,7 @@ class DatabaseBackedPoolTest : public testing::Test {
SimpleDescriptorDatabase database_;
virtual void SetUp() override {
void SetUp() override {
AddToDatabase(
&database_,
"name: 'foo.proto' "
@ -7289,10 +7296,9 @@ class AbortingErrorCollector : public DescriptorPool::ErrorCollector {
public:
AbortingErrorCollector() {}
virtual void AddError(const std::string& filename,
const std::string& element_name, const Message* message,
ErrorLocation location,
const std::string& error_message) override {
void AddError(const std::string& filename, const std::string& element_name,
const Message* message, ErrorLocation location,
const std::string& error_message) override {
GOOGLE_LOG(FATAL) << "AddError() called unexpectedly: " << filename << " ["
<< element_name << "]: " << error_message;
}
@ -7307,7 +7313,7 @@ class SingletonSourceTree : public compiler::SourceTree {
SingletonSourceTree(const std::string& filename, const std::string& contents)
: filename_(filename), contents_(contents) {}
virtual io::ZeroCopyInputStream* Open(const std::string& filename) override {
io::ZeroCopyInputStream* Open(const std::string& filename) override {
return filename == filename_
? new io::ArrayInputStream(contents_.data(), contents_.size())
: nullptr;

@ -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_) -

@ -120,7 +120,12 @@ class PROTOBUF_EXPORT Duration final :
}
inline void Swap(Duration* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);

@ -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.

@ -74,7 +74,7 @@ class DynamicMessageTest : public ::testing::TestWithParam<bool> {
DynamicMessageTest() : factory_(&pool_) {}
virtual void SetUp() override {
void SetUp() override {
// We want to make sure that DynamicMessage works (particularly with
// extensions) even if we use descriptors that are *not* from compiled-in
// types, so we make copies of the descriptors for unittest.proto and
@ -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);

@ -120,7 +120,12 @@ class PROTOBUF_EXPORT Empty final :
}
inline void Swap(Empty* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);

@ -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;
@ -242,11 +242,15 @@ void ExtensionSet::DeleteFlatMap(const ExtensionSet::KeyValue* flat,
bool ExtensionSet::Has(int number) const {
const Extension* ext = FindOrNull(number);
if (ext == NULL) return false;
if (ext == nullptr) return false;
GOOGLE_DCHECK(!ext->is_repeated);
return !ext->is_cleared;
}
bool ExtensionSet::HasLazy(int number) const {
return Has(number) && FindOrNull(number)->is_lazy;
}
int ExtensionSet::NumExtensions() const {
int result = 0;
ForEach([&result](int /* number */, const Extension& ext) {
@ -259,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;
}
@ -276,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();
}
@ -301,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); \
@ -312,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); \
@ -339,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); \
} \
@ -347,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); \
} \
@ -355,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); \
} \
@ -392,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
@ -466,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;
@ -477,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 {
@ -556,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 {
@ -583,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);
}
@ -617,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;
}
@ -666,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;
}
@ -681,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);
@ -693,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);
@ -713,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;
}
@ -729,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;
@ -741,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
@ -770,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 {
@ -796,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);
}
@ -827,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);
}
@ -843,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)) {
@ -882,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();
@ -898,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)) {
@ -974,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 =
@ -1033,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);
}
@ -1096,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) {
@ -1165,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);
}
@ -1888,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) {

@ -70,6 +70,7 @@ class DescriptorPool; // descriptor.h
class MessageLite; // message_lite.h
class Message; // message.h
class MessageFactory; // message.h
class Reflection; // message.h
class UnknownFieldSet; // unknown_field_set.h
namespace internal {
class FieldSkipper; // wire_format_lite.h
@ -108,7 +109,7 @@ struct ExtensionInfo {
type(type_param),
is_repeated(isrepeated),
is_packed(ispacked),
descriptor(NULL) {}
descriptor(nullptr) {}
const MessageLite* message;
int number;
@ -132,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;
};
@ -261,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
@ -281,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);
@ -544,6 +545,8 @@ class PROTOBUF_EXPORT ExtensionSet {
template <typename Type, bool IsValid(int)>
friend class RepeatedEnumTypeTraits;
friend class google::protobuf::Reflection;
const int32_t& GetRefInt32(int number, const int32_t& default_value) const;
const int64_t& GetRefInt64(int number, const int64_t& default_value) const;
const uint32_t& GetRefUInt32(int number, const uint32_t& default_value) const;
@ -573,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;
@ -664,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.
@ -766,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
@ -806,6 +810,9 @@ class PROTOBUF_EXPORT ExtensionSet {
ExtensionFinder* extension_finder,
MessageSetFieldSkipper* field_skipper);
// Returns true if extension is present and lazy.
bool HasLazy(int number) const;
// Gets the extension with the given number, creating it if it does not
// already exist. Returns true if the extension did not already exist.
bool MaybeNewExtension(int number, const FieldDescriptor* descriptor,
@ -1078,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 <> \
@ -1100,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>* \
@ -1126,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)
@ -1159,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) {
@ -1201,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) {
@ -1216,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();
@ -1256,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) {
@ -1290,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) {
@ -1310,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() {
@ -1355,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) {
@ -1416,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) {
@ -1433,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() {

@ -120,7 +120,12 @@ class PROTOBUF_EXPORT FieldMask final :
}
inline void Swap(FieldMask* other) {
if (other == this) return;
#ifdef PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() != nullptr &&
GetOwningArena() == other->GetOwningArena()) {
#else // PROTOBUF_FORCE_COPY_IN_SWAP
if (GetOwningArena() == other->GetOwningArena()) {
#endif // !PROTOBUF_FORCE_COPY_IN_SWAP
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);

@ -248,6 +248,12 @@ UnknownFieldSet* Reflection::MutableUnknownFields(Message* message) const {
->mutable_unknown_fields<UnknownFieldSet>();
}
bool Reflection::IsLazyExtension(const Message& message,
const FieldDescriptor* field) const {
return field->is_extension() &&
GetExtensionSet(message).HasLazy(field->number());
}
bool Reflection::IsLazilyVerifiedLazyField(const FieldDescriptor* field) const {
return field->options().lazy();
}
@ -2620,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);
@ -2651,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

@ -52,6 +52,8 @@
#include <google/protobuf/map_unittest.pb.h>
#include <google/protobuf/test_util.h>
#include <google/protobuf/unittest.pb.h>
#include <google/protobuf/unittest_mset.pb.h>
#include <google/protobuf/unittest_mset_wire_format.pb.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/testing/googletest.h>
@ -70,6 +72,9 @@ class GeneratedMessageReflectionTestHelper {
const std::vector<const FieldDescriptor*>& fields) {
lhs->GetReflection()->UnsafeShallowSwapFields(lhs, rhs, fields);
}
static bool IsLazyExtension(const Message& msg, const FieldDescriptor* ext) {
return msg.GetReflection()->IsLazyExtension(msg, ext);
}
};
namespace {
@ -78,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;
}
@ -705,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) {
@ -731,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);
}
@ -750,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(
@ -767,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(
@ -785,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(
@ -802,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(
@ -818,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(
@ -835,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(
@ -853,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(
@ -870,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(
@ -1022,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);
@ -1038,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;
@ -1056,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;
}
@ -1072,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);
@ -1087,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);
@ -1106,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);
@ -1118,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);
@ -1144,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);
@ -1177,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) {
@ -1193,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);
@ -1217,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);
@ -1245,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);

@ -267,9 +267,10 @@ inline void TableSerialize(const MessageLite& msg,
}
PROTOBUF_EXPORT uint8_t* SerializeInternalToArray(const uint8_t* base,
const FieldMetadata* table,
int32_t num_fields, bool is_deterministic,
uint8_t* buffer);
const FieldMetadata* table,
int32_t num_fields,
bool is_deterministic,
uint8_t* buffer);
inline uint8_t* TableSerializeToArray(const MessageLite& msg,
const SerializationTable* table,

@ -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_),

@ -82,9 +82,9 @@ class AnnotationProtoCollector : public AnnotationCollector {
: annotation_proto_(annotation_proto) {}
// Override for AnnotationCollector::AddAnnotation.
virtual void AddAnnotation(size_t begin_offset, size_t end_offset,
const std::string& file_path,
const std::vector<int>& path) override {
void AddAnnotation(size_t begin_offset, size_t end_offset,
const std::string& file_path,
const std::vector<int>& path) override {
typename AnnotationProto::Annotation* annotation =
annotation_proto_->add_annotation();
for (int i = 0; i < path.size(); ++i) {
@ -95,7 +95,7 @@ class AnnotationProtoCollector : public AnnotationCollector {
annotation->set_end(end_offset);
}
// Override for AnnotationCollector::AddAnnotation.
virtual void AddAnnotationNew(Annotation& a) override {
void AddAnnotationNew(Annotation& a) override {
auto* annotation = annotation_proto_->add_annotation();
annotation->ParseFromString(a.second);
annotation->set_begin(a.first.first);

@ -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)

@ -50,6 +50,10 @@
#include <string_view>
#endif // defined(__cpp_lib_string_view)
#if !defined(GOOGLE_PROTOBUF_NO_RDTSC) && defined(__APPLE__)
#include <mach/mach_time.h>
#endif
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/generated_enum_util.h>
@ -1080,12 +1084,24 @@ class Map {
// lower bits are not very random, due to alignment, so we discard them
// and shift the higher bits into their place.
size_type s = reinterpret_cast<uintptr_t>(this) >> 4;
#if defined(__x86_64__) && defined(__GNUC__) && \
!defined(GOOGLE_PROTOBUF_NO_RDTSC)
#if !defined(GOOGLE_PROTOBUF_NO_RDTSC)
#if defined(__APPLE__)
// Use a commpage-based fast time function on Apple environments (MacOS,
// iOS, tvOS, watchOS, etc).
s += mach_absolute_time();
#elif defined(__x86_64__) && defined(__GNUC__)
uint32_t hi, lo;
asm volatile("rdtsc" : "=a"(lo), "=d"(hi));
s += ((static_cast<uint64_t>(hi) << 32) | lo);
#elif defined(__aarch64__) && defined(__GNUC__)
// There is no rdtsc on ARMv8. CNTVCT_EL0 is the virtual counter of the
// system timer. It runs at a different frequency than the CPU's, but is
// the best source of time-based entropy we get.
uint64_t virtual_timer_value;
asm volatile("mrs %0, cntvct_el0" : "=r"(virtual_timer_value));
s += virtual_timer_value;
#endif
#endif // !defined(GOOGLE_PROTOBUF_NO_RDTSC)
return s;
}

@ -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_);
}
@ -528,7 +528,9 @@ class MapEntryLite : public MapEntryImpl<T, MessageLite, Key, Value,
SuperType;
constexpr MapEntryLite() {}
explicit MapEntryLite(Arena* arena) : SuperType(arena) {}
~MapEntryLite() { MessageLite::_internal_metadata_.template Delete<std::string>(); }
~MapEntryLite() {
MessageLite::_internal_metadata_.template Delete<std::string>();
}
void MergeFrom(const MapEntryLite& other) { MergeFromInternal(other); }
private:

@ -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 {
@ -56,9 +56,44 @@ RepeatedPtrFieldBase* MapFieldBase::MutableRepeatedField() {
return reinterpret_cast<RepeatedPtrFieldBase*>(repeated_field_);
}
void MapFieldBase::SwapState(MapFieldBase* other) {
// a relaxed swap of the atomic
auto other_state = other->state_.load(std::memory_order_relaxed);
auto this_state = state_.load(std::memory_order_relaxed);
other->state_.store(this_state, std::memory_order_relaxed);
state_.store(other_state, std::memory_order_relaxed);
}
void SwapRepeatedPtrToNull(RepeatedPtrField<Message>** from,
RepeatedPtrField<Message>** to, Arena* from_arena,
Arena* to_arena) {
GOOGLE_DCHECK(*from != nullptr);
GOOGLE_DCHECK(*to == nullptr);
*to = Arena::CreateMessage<RepeatedPtrField<Message> >(to_arena);
**to = std::move(**from);
if (from_arena == nullptr) {
delete *from;
}
*from = nullptr;
}
void MapFieldBase::Swap(MapFieldBase* other) {
// TODO(teboring): This is incorrect when on different arenas.
InternalSwap(other);
if (arena_ == other->arena_) {
InternalSwap(other);
return;
}
if (repeated_field_ != nullptr || other->repeated_field_ != nullptr) {
if (repeated_field_ == nullptr) {
SwapRepeatedPtrToNull(&other->repeated_field_, &repeated_field_,
other->arena_, arena_);
} else if (other->repeated_field_ == nullptr) {
SwapRepeatedPtrToNull(&repeated_field_, &other->repeated_field_, arena_,
other->arena_);
} else {
repeated_field_->Swap(other->repeated_field_);
}
}
SwapState(other);
}
void MapFieldBase::UnsafeShallowSwap(MapFieldBase* other) {
@ -69,11 +104,7 @@ void MapFieldBase::UnsafeShallowSwap(MapFieldBase* other) {
void MapFieldBase::InternalSwap(MapFieldBase* other) {
std::swap(arena_, other->arena_);
std::swap(repeated_field_, other->repeated_field_);
// a relaxed swap of the atomic
auto other_state = other->state_.load(std::memory_order_relaxed);
auto this_state = state_.load(std::memory_order_relaxed);
other->state_.store(this_state, std::memory_order_relaxed);
state_.store(other_state, std::memory_order_relaxed);
SwapState(other);
}
size_t MapFieldBase::SpaceUsedExcludingSelfLong() const {
@ -86,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;
@ -156,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_);
}
}
@ -403,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_);
}
@ -566,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
@ -466,6 +466,10 @@ class PROTOBUF_EXPORT MapFieldBase {
// IncreaseIterator() is called by operator++() of MapIterator only.
// It implements the ++ operator of MapIterator.
virtual void IncreaseIterator(MapIterator* map_iter) const = 0;
// Swaps state_ with another MapFieldBase
void SwapState(MapFieldBase* other);
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapFieldBase);
};
@ -573,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) {
@ -1023,6 +1023,33 @@ TEST_F(MapImplTest, SwapArena) {
EXPECT_THAT(m2, testing::UnorderedElementsAre(testing::Pair(9398, 41999)));
}
TEST_F(MapImplTest, SwapFieldArenaReflection) {
MapReflectionTester reflection_tester(UNITTEST::TestMap::descriptor());
Arena arena;
{
// Tests filled lfs and empty rhs.
TestMap rhs;
{
// Use local_arena to allocate lhs to trigger use-after-free error.
Arena local_arena;
auto* lhs = Arena::CreateMessage<TestMap>(&local_arena);
const auto* reflection = lhs->GetReflection();
std::vector<const FieldDescriptor*> fields;
reflection_tester.SetMapFieldsViaReflection(lhs);
reflection->ListFields(*lhs, &fields);
reflection->SwapFields(lhs, &rhs, fields);
reflection_tester.ExpectClearViaReflection(*lhs);
}
reflection_tester.ExpectMapFieldsSetViaReflection(rhs);
}
}
TEST_F(MapImplTest, CopyAssignMapIterator) {
TestMap message;
MapReflectionTester reflection_tester(UNITTEST::TestMap::descriptor());
@ -1091,11 +1118,7 @@ bool MapOrderingIsRandom(int a, int b) {
}
// This test verifies that the iteration order is reasonably random even for
// small maps. Currently we only have sufficient randomness for debug builds and
// builds where we can use the RDTSC instruction, so we only test for those
// builds.
#if defined(__x86_64__) && defined(__GNUC__) && \
!defined(GOOGLE_PROTOBUF_NO_RDTSC)
// small maps.
TEST_F(MapImplTest, RandomOrdering) {
for (int i = 0; i < 10; ++i) {
for (int j = i + 1; j < 10; ++j) {
@ -1105,7 +1128,6 @@ TEST_F(MapImplTest, RandomOrdering) {
}
}
}
#endif
template <typename Key>
void TestTransparent(const Key& key, const Key& miss_key) {
@ -3018,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_);
}
};
@ -3759,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 {

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save