Unverified Commit 61301f01 authored by Hao Nguyen's avatar Hao Nguyen Committed by GitHub

Merge pull request #6245 from haon4/201906111559

Down Integrate to GitHub
parents b008801b 09cab821
......@@ -108,7 +108,7 @@ public abstract class AbstractMessage
@Override
public final String toString() {
return TextFormat.printToString(this);
return TextFormat.printer().printToString(this);
}
@Override
......@@ -468,7 +468,7 @@ public abstract class AbstractMessage
@Override
public String toString() {
return TextFormat.printToString(this);
return TextFormat.printer().printToString(this);
}
/** Construct an UninitializedMessageException reporting missing fields in the given message. */
......
......@@ -76,6 +76,10 @@ public class ExtensionRegistryLite {
// applications. Need to support this feature on smaller granularity.
private static volatile boolean eagerlyParseMessageSets = false;
// short circuit the ExtensionRegistryFactory via assumevalues trickery
@SuppressWarnings("JavaOptionalSuggestions")
private static boolean doFullRuntimeInheritanceCheck = true;
// Visible for testing.
static final String EXTENSION_CLASS_NAME = "com.google.protobuf.Extension";
......@@ -107,7 +111,9 @@ public class ExtensionRegistryLite {
* available.
*/
public static ExtensionRegistryLite newInstance() {
return ExtensionRegistryFactory.create();
return doFullRuntimeInheritanceCheck
? ExtensionRegistryFactory.create()
: new ExtensionRegistryLite();
}
private static volatile ExtensionRegistryLite emptyRegistry;
......@@ -122,7 +128,11 @@ public class ExtensionRegistryLite {
synchronized (ExtensionRegistryLite.class) {
result = emptyRegistry;
if (result == null) {
result = emptyRegistry = ExtensionRegistryFactory.createEmpty();
result =
emptyRegistry =
doFullRuntimeInheritanceCheck
? ExtensionRegistryFactory.createEmpty()
: EMPTY_REGISTRY_LITE;
}
}
}
......@@ -163,7 +173,7 @@ public class ExtensionRegistryLite {
if (GeneratedMessageLite.GeneratedExtension.class.isAssignableFrom(extension.getClass())) {
add((GeneratedMessageLite.GeneratedExtension<?, ?>) extension);
}
if (ExtensionRegistryFactory.isFullRegistry(this)) {
if (doFullRuntimeInheritanceCheck && ExtensionRegistryFactory.isFullRegistry(this)) {
try {
this.getClass().getMethod("add", extensionClass).invoke(this, extension);
} catch (Exception e) {
......
......@@ -85,7 +85,7 @@ public interface Message extends MessageLite, MessageOrBuilder {
/**
* Converts the message to a string in protocol buffer text format. This is just a trivial wrapper
* around {@link TextFormat#printToString(MessageOrBuilder)}.
* around {@link TextFormat.Printer#printToString(MessageOrBuilder)}.
*/
@Override
String toString();
......
......@@ -140,11 +140,11 @@ public final class UnknownFieldSet implements MessageLite {
/**
* Converts the set to a string in protocol buffer text format. This is just a trivial wrapper
* around {@link TextFormat#printToString(UnknownFieldSet)}.
* around {@link TextFormat.Printer#printToString(UnknownFieldSet)}.
*/
@Override
public String toString() {
return TextFormat.printToString(this);
return TextFormat.printer().printToString(this);
}
/**
......
......@@ -766,7 +766,7 @@ public class MapForProto2Test extends TestCase {
setMapValuesUsingAccessors(builder);
TestMap message = builder.build();
String textData = TextFormat.printToString(message);
String textData = TextFormat.printer().printToString(message);
builder = TestMap.newBuilder();
TextFormat.merge(textData, builder);
......
......@@ -857,7 +857,7 @@ public class MapTest extends TestCase {
setMapValuesUsingAccessors(builder);
TestMap message = builder.build();
String textData = TextFormat.printToString(message);
String textData = TextFormat.printer().printToString(message);
builder = TestMap.newBuilder();
TextFormat.merge(textData, builder);
......
......@@ -234,7 +234,7 @@ public class UnknownEnumValueTest extends TestCase {
TestAllTypes message = builder.build();
// We can print a message with unknown enum values.
String textData = TextFormat.printToString(message);
String textData = TextFormat.printer().printToString(message);
assertEquals(
"optional_nested_enum: UNKNOWN_ENUM_VALUE_NestedEnum_4321\n"
+ "repeated_nested_enum: UNKNOWN_ENUM_VALUE_NestedEnum_5432\n"
......
......@@ -958,19 +958,19 @@ jspb.Message.getMapField = function(msg, fieldNumber, noLazyCreate,
// If we already have a map in the map wrappers, return that.
if (fieldNumber in msg.wrappers_) {
return msg.wrappers_[fieldNumber];
} else if (noLazyCreate) {
return undefined;
} else {
// Wrap the underlying elements array with a Map.
var arr = jspb.Message.getField(msg, fieldNumber);
if (!arr) {
arr = [];
jspb.Message.setField(msg, fieldNumber, arr);
}
var arr = jspb.Message.getField(msg, fieldNumber);
// Wrap the underlying elements array with a Map.
if (!arr) {
if (noLazyCreate) {
return undefined;
}
return msg.wrappers_[fieldNumber] =
new jspb.Map(
/** @type {!Array<!Array<!Object>>} */ (arr), opt_valueCtor);
arr = [];
jspb.Message.setField(msg, fieldNumber, arr);
}
return msg.wrappers_[fieldNumber] =
new jspb.Map(
/** @type {!Array<!Array<!Object>>} */ (arr), opt_valueCtor);
};
......
......@@ -8,5 +8,6 @@ Description: Google's Data Interchange Format
Version: @VERSION@
Libs: -L${libdir} -lprotobuf @PTHREAD_LIBS@
Libs.private: @LIBS@
Cflags: -I${includedir} @PTHREAD_CFLAGS@
Conflicts: protobuf-lite
......@@ -615,18 +615,86 @@ class SecondaryDescriptorFromDescriptorDB(DescriptorPoolTestBase,
factory_test1_pb2.DESCRIPTOR.serialized_pb)
self.factory_test2_fd = descriptor_pb2.FileDescriptorProto.FromString(
factory_test2_pb2.DESCRIPTOR.serialized_pb)
db = descriptor_database.DescriptorDatabase()
db.Add(self.factory_test1_fd)
db.Add(self.factory_test2_fd)
db.Add(descriptor_pb2.FileDescriptorProto.FromString(
self.db = descriptor_database.DescriptorDatabase()
self.db.Add(self.factory_test1_fd)
self.db.Add(self.factory_test2_fd)
self.db.Add(descriptor_pb2.FileDescriptorProto.FromString(
unittest_import_public_pb2.DESCRIPTOR.serialized_pb))
db.Add(descriptor_pb2.FileDescriptorProto.FromString(
self.db.Add(descriptor_pb2.FileDescriptorProto.FromString(
unittest_import_pb2.DESCRIPTOR.serialized_pb))
db.Add(descriptor_pb2.FileDescriptorProto.FromString(
self.db.Add(descriptor_pb2.FileDescriptorProto.FromString(
unittest_pb2.DESCRIPTOR.serialized_pb))
db.Add(descriptor_pb2.FileDescriptorProto.FromString(
self.db.Add(descriptor_pb2.FileDescriptorProto.FromString(
no_package_pb2.DESCRIPTOR.serialized_pb))
self.pool = descriptor_pool.DescriptorPool(descriptor_db=db)
self.pool = descriptor_pool.DescriptorPool(descriptor_db=self.db)
def testErrorCollector(self):
file_proto = descriptor_pb2.FileDescriptorProto()
file_proto.package = 'collector'
file_proto.name = 'error_file'
message_type = file_proto.message_type.add()
message_type.name = 'ErrorMessage'
field = message_type.field.add()
field.number = 1
field.name = 'nested_message_field'
field.label = descriptor.FieldDescriptor.LABEL_OPTIONAL
field.type = descriptor.FieldDescriptor.TYPE_MESSAGE
field.type_name = 'SubMessage'
oneof = message_type.oneof_decl.add()
oneof.name = 'MyOneof'
enum_type = file_proto.enum_type.add()
enum_type.name = 'MyEnum'
enum_value = enum_type.value.add()
enum_value.name = 'MyEnumValue'
enum_value.number = 0
self.db.Add(file_proto)
self.assertRaisesRegexp(KeyError, 'SubMessage',
self.pool.FindMessageTypeByName,
'collector.ErrorMessage')
self.assertRaisesRegexp(KeyError, 'SubMessage',
self.pool.FindFileByName, 'error_file')
with self.assertRaises(KeyError) as exc:
self.pool.FindFileByName('none_file')
self.assertIn(str(exc.exception), ('\'none_file\'',
'\"Couldn\'t find file none_file\"'))
# Pure python _ConvertFileProtoToFileDescriptor() method has side effect
# that all the symbols found in the file will load into the pool even the
# file can not build. So when FindMessageTypeByName('ErrorMessage') was
# called the first time, a KeyError will be raised but call the find
# method later will return a descriptor which is not build.
# TODO(jieluo): fix pure python to revert the load if file can not be build
if api_implementation.Type() == 'cpp':
error_msg = ('Invalid proto descriptor for file "error_file":\\n '
'collector.ErrorMessage.nested_message_field: "SubMessage" '
'is not defined.\\n collector.ErrorMessage.MyOneof: Oneof '
'must have at least one field.\\n\'')
with self.assertRaises(KeyError) as exc:
self.pool.FindMessageTypeByName('collector.ErrorMessage')
self.assertEqual(str(exc.exception), '\'Couldn\\\'t build file for '
'message collector.ErrorMessage\\n' + error_msg)
with self.assertRaises(KeyError) as exc:
self.pool.FindFieldByName('collector.ErrorMessage.nested_message_field')
self.assertEqual(str(exc.exception), '\'Couldn\\\'t build file for field'
' collector.ErrorMessage.nested_message_field\\n'
+ error_msg)
with self.assertRaises(KeyError) as exc:
self.pool.FindEnumTypeByName('collector.MyEnum')
self.assertEqual(str(exc.exception), '\'Couldn\\\'t build file for enum'
' collector.MyEnum\\n' + error_msg)
with self.assertRaises(KeyError) as exc:
self.pool.FindFileContainingSymbol('collector.MyEnumValue')
self.assertEqual(str(exc.exception), '\'Couldn\\\'t build file for symbol'
' collector.MyEnumValue\\n' + error_msg)
with self.assertRaises(KeyError) as exc:
self.pool.FindOneofByName('collector.ErrorMessage.MyOneof')
self.assertEqual(str(exc.exception), '\'Couldn\\\'t build file for oneof'
' collector.ErrorMessage.MyOneof\\n' + error_msg)
class ProtoFile(object):
......
......@@ -54,6 +54,7 @@ from google.protobuf import unittest_mset_pb2
from google.protobuf import unittest_pb2
from google.protobuf import descriptor_pool
from google.protobuf import json_format
from google.protobuf.util import json_format_pb2
from google.protobuf.util import json_format_proto3_pb2
......@@ -247,6 +248,22 @@ class JsonFormatTest(JsonFormatBase):
}
self.assertEqual(golden_dict, message_dict)
def testExtensionSerializationDictMatchesProto3SpecMore(self):
"""See go/proto3-json-spec for spec.
"""
message = json_format_pb2.TestMessageWithExtension()
ext = json_format_pb2.TestExtension.ext
message.Extensions[ext].value = 'stuff'
message_dict = json_format.MessageToDict(
message
)
expected_dict = {
'[protobuf_unittest.TestExtension.ext]': {
'value': u'stuff',
},
}
self.assertEqual(expected_dict, message_dict)
def testExtensionSerializationJsonMatchesProto3Spec(self):
"""See go/proto3-json-spec for spec.
......
......@@ -233,12 +233,8 @@ class _Printer(object):
js[name] = [self._FieldToJsonObject(field, k)
for k in value]
elif field.is_extension:
f = field
if (f.containing_type.GetOptions().message_set_wire_format and
f.type == descriptor.FieldDescriptor.TYPE_MESSAGE and
f.label == descriptor.FieldDescriptor.LABEL_OPTIONAL):
f = f.message_type
name = '[%s.%s]' % (f.full_name, name)
full_qualifier = field.full_name[:-len(field.name)]
name = '[%s%s]' % (full_qualifier, name)
js[name] = self._FieldToJsonObject(field, value)
else:
js[name] = self._FieldToJsonObject(field, value)
......@@ -493,10 +489,16 @@ class _Parser(object):
raise ParseError('Message type {0} does not have extensions'.format(
message_descriptor.full_name))
identifier = name[1:-1] # strip [] brackets
identifier = '.'.join(identifier.split('.')[:-1])
# pylint: disable=protected-access
field = message.Extensions._FindExtensionByName(identifier)
# pylint: enable=protected-access
if not field:
# Try looking for extension by the message type name, dropping the
# field name following the final . separator in full_name.
identifier = '.'.join(identifier.split('.')[:-1])
# pylint: disable=protected-access
field = message.Extensions._FindExtensionByName(identifier)
# pylint: enable=protected-access
if not field:
if self.ignore_unknown_fields:
continue
......
......@@ -67,6 +67,38 @@ static std::unordered_map<const DescriptorPool*, PyDescriptorPool*>*
namespace cdescriptor_pool {
// Collects errors that occur during proto file building to allow them to be
// propagated in the python exception instead of only living in ERROR logs.
class BuildFileErrorCollector : public DescriptorPool::ErrorCollector {
public:
BuildFileErrorCollector() : error_message(""), had_errors_(false) {}
void AddError(const string& filename, const string& element_name,
const Message* descriptor, ErrorLocation location,
const string& message) override {
// Replicates the logging behavior that happens in the C++ implementation
// when an error collector is not passed in.
if (!had_errors_) {
error_message +=
("Invalid proto descriptor for file \"" + filename + "\":\n");
had_errors_ = true;
}
// As this only happens on failure and will result in the program not
// running at all, no effort is made to optimize this string manipulation.
error_message += (" " + element_name + ": " + message + "\n");
}
void Clear() {
had_errors_ = false;
error_message = "";
}
string error_message;
private:
bool had_errors_;
};
// Create a Python DescriptorPool object, but does not fill the "pool"
// attribute.
static PyDescriptorPool* _CreateDescriptorPool() {
......@@ -76,6 +108,7 @@ static PyDescriptorPool* _CreateDescriptorPool() {
return NULL;
}
cpool->error_collector = nullptr;
cpool->underlay = NULL;
cpool->database = NULL;
......@@ -124,7 +157,8 @@ static PyDescriptorPool* PyDescriptorPool_NewWithDatabase(
return NULL;
}
if (database != NULL) {
cpool->pool = new DescriptorPool(database);
cpool->error_collector = new BuildFileErrorCollector();
cpool->pool = new DescriptorPool(database, cpool->error_collector);
cpool->database = database;
} else {
cpool->pool = new DescriptorPool();
......@@ -167,6 +201,7 @@ static void Dealloc(PyObject* pself) {
delete self->descriptor_options;
delete self->database;
delete self->pool;
delete self->error_collector;
Py_TYPE(self)->tp_free(pself);
}
......@@ -182,6 +217,20 @@ static int GcClear(PyObject* pself) {
return 0;
}
PyObject* SetErrorFromCollector(DescriptorPool::ErrorCollector* self,
char* name, char* error_type) {
BuildFileErrorCollector* error_collector =
reinterpret_cast<BuildFileErrorCollector*>(self);
if (error_collector && !error_collector->error_message.empty()) {
PyErr_Format(PyExc_KeyError, "Couldn't build file for %s %.200s\n%s",
error_type, name, error_collector->error_message.c_str());
error_collector->Clear();
return NULL;
}
PyErr_Format(PyExc_KeyError, "Couldn't find %s %.200s", error_type, name);
return NULL;
}
static PyObject* FindMessageByName(PyObject* self, PyObject* arg) {
Py_ssize_t name_size;
char* name;
......@@ -194,8 +243,9 @@ static PyObject* FindMessageByName(PyObject* self, PyObject* arg) {
string(name, name_size));
if (message_descriptor == NULL) {
PyErr_Format(PyExc_KeyError, "Couldn't find message %.200s", name);
return NULL;
return SetErrorFromCollector(
reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
"message");
}
......@@ -212,12 +262,12 @@ static PyObject* FindFileByName(PyObject* self, PyObject* arg) {
return NULL;
}
PyDescriptorPool* py_pool = reinterpret_cast<PyDescriptorPool*>(self);
const FileDescriptor* file_descriptor =
reinterpret_cast<PyDescriptorPool*>(self)->pool->FindFileByName(
string(name, name_size));
py_pool->pool->FindFileByName(string(name, name_size));
if (file_descriptor == NULL) {
PyErr_Format(PyExc_KeyError, "Couldn't find file %.200s", name);
return NULL;
return SetErrorFromCollector(py_pool->error_collector, name, "file");
}
return PyFileDescriptor_FromDescriptor(file_descriptor);
}
......@@ -232,9 +282,7 @@ PyObject* FindFieldByName(PyDescriptorPool* self, PyObject* arg) {
const FieldDescriptor* field_descriptor =
self->pool->FindFieldByName(string(name, name_size));
if (field_descriptor == NULL) {
PyErr_Format(PyExc_KeyError, "Couldn't find field %.200s",
name);
return NULL;
return SetErrorFromCollector(self->error_collector, name, "field");
}
......@@ -255,8 +303,8 @@ PyObject* FindExtensionByName(PyDescriptorPool* self, PyObject* arg) {
const FieldDescriptor* field_descriptor =
self->pool->FindExtensionByName(string(name, name_size));
if (field_descriptor == NULL) {
PyErr_Format(PyExc_KeyError, "Couldn't find extension field %.200s", name);
return NULL;
return SetErrorFromCollector(self->error_collector, name,
"extension field");
}
......@@ -277,8 +325,7 @@ PyObject* FindEnumTypeByName(PyDescriptorPool* self, PyObject* arg) {
const EnumDescriptor* enum_descriptor =
self->pool->FindEnumTypeByName(string(name, name_size));
if (enum_descriptor == NULL) {
PyErr_Format(PyExc_KeyError, "Couldn't find enum %.200s", name);
return NULL;
return SetErrorFromCollector(self->error_collector, name, "enum");
}
......@@ -299,8 +346,7 @@ PyObject* FindOneofByName(PyDescriptorPool* self, PyObject* arg) {
const OneofDescriptor* oneof_descriptor =
self->pool->FindOneofByName(string(name, name_size));
if (oneof_descriptor == NULL) {
PyErr_Format(PyExc_KeyError, "Couldn't find oneof %.200s", name);
return NULL;
return SetErrorFromCollector(self->error_collector, name, "oneof");
}
......@@ -322,8 +368,9 @@ static PyObject* FindServiceByName(PyObject* self, PyObject* arg) {
reinterpret_cast<PyDescriptorPool*>(self)->pool->FindServiceByName(
string(name, name_size));
if (service_descriptor == NULL) {
PyErr_Format(PyExc_KeyError, "Couldn't find service %.200s", name);
return NULL;
return SetErrorFromCollector(
reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
"service");
}
......@@ -341,8 +388,9 @@ static PyObject* FindMethodByName(PyObject* self, PyObject* arg) {
reinterpret_cast<PyDescriptorPool*>(self)->pool->FindMethodByName(
string(name, name_size));
if (method_descriptor == NULL) {
PyErr_Format(PyExc_KeyError, "Couldn't find method %.200s", name);
return NULL;
return SetErrorFromCollector(
reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
"method");
}
......@@ -360,8 +408,9 @@ static PyObject* FindFileContainingSymbol(PyObject* self, PyObject* arg) {
reinterpret_cast<PyDescriptorPool*>(self)->pool->FindFileContainingSymbol(
string(name, name_size));
if (file_descriptor == NULL) {
PyErr_Format(PyExc_KeyError, "Couldn't find symbol %.200s", name);
return NULL;
return SetErrorFromCollector(
reinterpret_cast<PyDescriptorPool*>(self)->error_collector, name,
"symbol");
}
......@@ -384,7 +433,16 @@ static PyObject* FindExtensionByNumber(PyObject* self, PyObject* args) {
reinterpret_cast<PyDescriptorPool*>(self)->pool->FindExtensionByNumber(
descriptor, number);
if (extension_descriptor == NULL) {
PyErr_Format(PyExc_KeyError, "Couldn't find extension %d", number);
BuildFileErrorCollector* error_collector =
reinterpret_cast<BuildFileErrorCollector*>(
reinterpret_cast<PyDescriptorPool*>(self)->error_collector);
if (error_collector && !error_collector->error_message.empty()) {
PyErr_Format(PyExc_KeyError, "Couldn't build file for Extension %.d\n%s",
number, error_collector->error_message.c_str());
error_collector->Clear();
return NULL;
}
PyErr_Format(PyExc_KeyError, "Couldn't find Extension %d", number);
return NULL;
}
......@@ -511,32 +569,6 @@ static PyObject* AddServiceDescriptor(PyObject* self, PyObject* descriptor) {
}
// The code below loads new Descriptors from a serialized FileDescriptorProto.
// Collects errors that occur during proto file building to allow them to be
// propagated in the python exception instead of only living in ERROR logs.
class BuildFileErrorCollector : public DescriptorPool::ErrorCollector {
public:
BuildFileErrorCollector() : error_message(""), had_errors(false) {}
void AddError(const string& filename, const string& element_name,
const Message* descriptor, ErrorLocation location,
const string& message) {
// Replicates the logging behavior that happens in the C++ implementation
// when an error collector is not passed in.
if (!had_errors) {
error_message +=
("Invalid proto descriptor for file \"" + filename + "\":\n");
had_errors = true;
}
// As this only happens on failure and will result in the program not
// running at all, no effort is made to optimize this string manipulation.
error_message += (" " + element_name + ": " + message + "\n");
}
string error_message;
bool had_errors;
};
static PyObject* AddSerializedFile(PyObject* pself, PyObject* serialized_pb) {
PyDescriptorPool* self = reinterpret_cast<PyDescriptorPool*>(pself);
char* message_type;
......
......@@ -59,6 +59,10 @@ typedef struct PyDescriptorPool {
// The C++ pool containing Descriptors.
DescriptorPool* pool;
// The error collector to store error info. Can be NULL. This pointer is
// owned.
DescriptorPool::ErrorCollector* error_collector;
// The C++ pool acting as an underlay. Can be NULL.
// This pointer is not owned and must stay alive.
const DescriptorPool* underlay;
......
......@@ -92,6 +92,7 @@ def GenerateUnittestProtos():
generate_proto("../src/google/protobuf/unittest_mset_wire_format.proto", False)
generate_proto("../src/google/protobuf/unittest_no_generic_services.proto", False)
generate_proto("../src/google/protobuf/unittest_proto3_arena.proto", False)
generate_proto("../src/google/protobuf/util/json_format.proto", False)
generate_proto("../src/google/protobuf/util/json_format_proto3.proto", False)
generate_proto("google/protobuf/internal/any_test.proto", False)
generate_proto("google/protobuf/internal/descriptor_pool_test1.proto", False)
......
......@@ -115,11 +115,6 @@ class Any::_Internal {
public:
};
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int Any::kTypeUrlFieldNumber;
const int Any::kValueFieldNumber;
#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
Any::Any()
: ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr), _any_metadata_(&type_url_, &value_) {
SharedCtor();
......@@ -419,10 +414,6 @@ bool Any::IsInitialized() const {
return true;
}
void Any::Swap(Any* other) {
if (other == this) return;
InternalSwap(other);
}
void Any::InternalSwap(Any* other) {
using std::swap;
_internal_metadata_.Swap(&other->_internal_metadata_);
......
......@@ -126,10 +126,13 @@ class PROTOBUF_EXPORT Any :
}
static bool ParseAnyTypeUrl(const string& type_url,
std::string* full_type_name);
void Swap(Any* other);
friend void swap(Any& a, Any& b) {
a.Swap(&b);
}
inline void Swap(Any* other) {
if (other == this) return;
InternalSwap(other);
}
// implements Message ----------------------------------------------
......@@ -191,9 +194,12 @@ class PROTOBUF_EXPORT Any :
// accessors -------------------------------------------------------
enum : int {
kTypeUrlFieldNumber = 1,
kValueFieldNumber = 2,
};
// string type_url = 1;
void clear_type_url();
static const int kTypeUrlFieldNumber = 1;
const std::string& type_url() const;
void set_type_url(const std::string& value);
void set_type_url(std::string&& value);
......@@ -205,7 +211,6 @@ class PROTOBUF_EXPORT Any :
// bytes value = 2;
void clear_value();
static const int kValueFieldNumber = 2;
const std::string& value() const;
void set_value(const std::string& value);
void set_value(std::string&& value);
......
......@@ -196,16 +196,6 @@ void Api::clear_source_context() {
}
source_context_ = nullptr;
}
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int Api::kNameFieldNumber;
const int Api::kMethodsFieldNumber;
const int Api::kOptionsFieldNumber;
const int Api::kVersionFieldNumber;
const int Api::kSourceContextFieldNumber;
const int Api::kMixinsFieldNumber;
const int Api::kSyntaxFieldNumber;
#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
Api::Api()
: ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) {
SharedCtor();
......@@ -777,10 +767,6 @@ bool Api::IsInitialized() const {
return true;
}
void Api::Swap(Api* other) {
if (other == this) return;
InternalSwap(other);
}
void Api::InternalSwap(Api* other) {
using std::swap;
_internal_metadata_.Swap(&other->_internal_metadata_);
......@@ -811,16 +797,6 @@ class Method::_Internal {
void Method::clear_options() {
options_.Clear();
}
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int Method::kNameFieldNumber;
const int Method::kRequestTypeUrlFieldNumber;
const int Method::kRequestStreamingFieldNumber;
const int Method::kResponseTypeUrlFieldNumber;
const int Method::kResponseStreamingFieldNumber;
const int Method::kOptionsFieldNumber;
const int Method::kSyntaxFieldNumber;
#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
Method::Method()
: ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) {
SharedCtor();
......@@ -1374,10 +1350,6 @@ bool Method::IsInitialized() const {
return true;
}
void Method::Swap(Method* other) {
if (other == this) return;
InternalSwap(other);
}
void Method::InternalSwap(Method* other) {
using std::swap;
_internal_metadata_.Swap(&other->_internal_metadata_);
......@@ -1406,11 +1378,6 @@ class Mixin::_Internal {
public:
};
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int Mixin::kNameFieldNumber;
const int Mixin::kRootFieldNumber;
#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
Mixin::Mixin()
: ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) {
SharedCtor();
......@@ -1721,10 +1688,6 @@ bool Mixin::IsInitialized() const {
return true;
}
void Mixin::Swap(Mixin* other) {
if (other == this) return;
InternalSwap(other);
}
void Mixin::InternalSwap(Mixin* other) {
using std::swap;
_internal_metadata_.Swap(&other->_internal_metadata_);
......
......@@ -120,10 +120,13 @@ class PROTOBUF_EXPORT Api :
static constexpr int kIndexInFileMessages =
0;
void Swap(Api* other);
friend void swap(Api& a, Api& b) {
a.Swap(&b);
}
inline void Swap(Api* other) {
if (other == this) return;
InternalSwap(other);
}
// implements Message ----------------------------------------------
......@@ -185,10 +188,18 @@ class PROTOBUF_EXPORT Api :
// accessors -------------------------------------------------------
enum : int {
kMethodsFieldNumber = 2,
kOptionsFieldNumber = 3,
kMixinsFieldNumber = 6,
kNameFieldNumber = 1,
kVersionFieldNumber = 4,
kSourceContextFieldNumber = 5,
kSyntaxFieldNumber = 7,
};
// repeated .google.protobuf.Method methods = 2;
int methods_size() const;
void clear_methods();
static const int kMethodsFieldNumber = 2;
PROTOBUF_NAMESPACE_ID::Method* mutable_methods(int index);
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Method >*
mutable_methods();
......@@ -200,7 +211,6 @@ class PROTOBUF_EXPORT Api :
// repeated .google.protobuf.Option options = 3;
int options_size() const;
void clear_options();
static const int kOptionsFieldNumber = 3;
PROTOBUF_NAMESPACE_ID::Option* mutable_options(int index);
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Option >*
mutable_options();
......@@ -212,7 +222,6 @@ class PROTOBUF_EXPORT Api :
// repeated .google.protobuf.Mixin mixins = 6;
int mixins_size() const;
void clear_mixins();
static const int kMixinsFieldNumber = 6;
PROTOBUF_NAMESPACE_ID::Mixin* mutable_mixins(int index);
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Mixin >*
mutable_mixins();
......@@ -223,7 +232,6 @@ class PROTOBUF_EXPORT Api :
// string name = 1;
void clear_name();
static const int kNameFieldNumber = 1;
const std::string& name() const;
void set_name(const std::string& value);
void set_name(std::string&& value);
......@@ -235,7 +243,6 @@ class PROTOBUF_EXPORT Api :
// string version = 4;
void clear_version();
static const int kVersionFieldNumber = 4;
const std::string& version() const;
void set_version(const std::string& value);
void set_version(std::string&& value);
......@@ -248,7 +255,6 @@ class PROTOBUF_EXPORT Api :
// .google.protobuf.SourceContext source_context = 5;
bool has_source_context() const;
void clear_source_context();
static const int kSourceContextFieldNumber = 5;
const PROTOBUF_NAMESPACE_ID::SourceContext& source_context() const;
PROTOBUF_NAMESPACE_ID::SourceContext* release_source_context();
PROTOBUF_NAMESPACE_ID::SourceContext* mutable_source_context();
......@@ -256,7 +262,6 @@ class PROTOBUF_EXPORT Api :
// .google.protobuf.Syntax syntax = 7;
void clear_syntax();
static const int kSyntaxFieldNumber = 7;
PROTOBUF_NAMESPACE_ID::Syntax syntax() const;
void set_syntax(PROTOBUF_NAMESPACE_ID::Syntax value);
......@@ -321,10 +326,13 @@ class PROTOBUF_EXPORT Method :
static constexpr int kIndexInFileMessages =
1;
void Swap(Method* other);
friend void swap(Method& a, Method& b) {
a.Swap(&b);
}
inline void Swap(Method* other) {
if (other == this) return;
InternalSwap(other);
}
// implements Message ----------------------------------------------
......@@ -386,10 +394,18 @@ class PROTOBUF_EXPORT Method :
// accessors -------------------------------------------------------
enum : int {
kOptionsFieldNumber = 6,
kNameFieldNumber = 1,
kRequestTypeUrlFieldNumber = 2,
kResponseTypeUrlFieldNumber = 4,
kRequestStreamingFieldNumber = 3,
kResponseStreamingFieldNumber = 5,
kSyntaxFieldNumber = 7,
};
// repeated .google.protobuf.Option options = 6;
int options_size() const;
void clear_options();
static const int kOptionsFieldNumber = 6;
PROTOBUF_NAMESPACE_ID::Option* mutable_options(int index);
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::Option >*
mutable_options();
......@@ -400,7 +416,6 @@ class PROTOBUF_EXPORT Method :
// string name = 1;
void clear_name();
static const int kNameFieldNumber = 1;
const std::string& name() const;
void set_name(const std::string& value);
void set_name(std::string&& value);
......@@ -412,7 +427,6 @@ class PROTOBUF_EXPORT Method :
// string request_type_url = 2;
void clear_request_type_url();
static const int kRequestTypeUrlFieldNumber = 2;
const std::string& request_type_url() const;
void set_request_type_url(const std::string& value);
void set_request_type_url(std::string&& value);
......@@ -424,7 +438,6 @@ class PROTOBUF_EXPORT Method :
// string response_type_url = 4;
void clear_response_type_url();
static const int kResponseTypeUrlFieldNumber = 4;
const std::string& response_type_url() const;
void set_response_type_url(const std::string& value);
void set_response_type_url(std::string&& value);
......@@ -436,19 +449,16 @@ class PROTOBUF_EXPORT Method :
// bool request_streaming = 3;
void clear_request_streaming();
static const int kRequestStreamingFieldNumber = 3;
bool request_streaming() const;
void set_request_streaming(bool value);
// bool response_streaming = 5;
void clear_response_streaming();
static const int kResponseStreamingFieldNumber = 5;
bool response_streaming() const;
void set_response_streaming(bool value);
// .google.protobuf.Syntax syntax = 7;
void clear_syntax();
static const int kSyntaxFieldNumber = 7;
PROTOBUF_NAMESPACE_ID::Syntax syntax() const;
void set_syntax(PROTOBUF_NAMESPACE_ID::Syntax value);
......@@ -513,10 +523,13 @@ class PROTOBUF_EXPORT Mixin :
static constexpr int kIndexInFileMessages =
2;
void Swap(Mixin* other);
friend void swap(Mixin& a, Mixin& b) {
a.Swap(&b);
}
inline void Swap(Mixin* other) {
if (other == this) return;
InternalSwap(other);
}
// implements Message ----------------------------------------------
......@@ -578,9 +591,12 @@ class PROTOBUF_EXPORT Mixin :
// accessors -------------------------------------------------------
enum : int {
kNameFieldNumber = 1,
kRootFieldNumber = 2,
};
// string name = 1;
void clear_name();
static const int kNameFieldNumber = 1;
const std::string& name() const;
void set_name(const std::string& value);
void set_name(std::string&& value);
......@@ -592,7 +608,6 @@ class PROTOBUF_EXPORT Mixin :
// string root = 2;
void clear_root();
static const int kRootFieldNumber = 2;
const std::string& root() const;
void set_root(const std::string& value);
void set_root(std::string&& value);
......
......@@ -245,7 +245,7 @@ struct ArenaOptions {
// well as protobuf container types like RepeatedPtrField and Map. The protocol
// is internal to protobuf and is not guaranteed to be stable. Non-proto types
// should not rely on this protocol.
class PROTOBUF_EXPORT Arena final {
class PROTOBUF_EXPORT alignas(8) Arena final {
public:
// Arena constructor taking custom options. See ArenaOptions below for
// descriptions of the options available.
......
......@@ -2023,6 +2023,10 @@ TEST_F(CommandLineInterfaceTest, GeneratorPluginNotFound) {
// Error written to stdout by child process after exec() fails.
ExpectErrorSubstring("no_such_file: program not found or is not executable");
ExpectErrorSubstring(
"Please specify a program using absolute path or make sure "
"the program is available in your PATH system variable");
// Error written by parent process when child fails.
ExpectErrorSubstring(
"--badplug_out: prefix-gen-badplug: Plugin failed with status code 1.");
......
......@@ -1489,9 +1489,9 @@ class ParseLoopGenerator {
std::string enum_validator;
if (field->type() == FieldDescriptor::TYPE_ENUM &&
!HasPreservingUnknownEnumSemantics(field)) {
enum_validator = StrCat(
", ", QualifiedClassName(field->enum_type(), options_),
"_IsValid, mutable_unknown_fields(), ", field->number());
enum_validator =
StrCat(", ", QualifiedClassName(field->enum_type(), options_),
"_IsValid, &_internal_metadata_, ", field->number());
}
format_("ptr = $pi_ns$::Packed$1$Parser(mutable_$2$(), ptr, ctx$3$);\n",
DeclaredTypeMethodName(field->type()), FieldName(field),
......
......@@ -714,6 +714,18 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* printer) {
ordered_fields.push_back(field);
}
if (!ordered_fields.empty()) {
format("enum : int {\n");
for (auto field : ordered_fields) {
Formatter::SaveState save(&format);
std::map<std::string, std::string> vars;
SetCommonFieldVariables(field, &vars, options_);
format.AddMap(vars);
format(" ${1$$2$$}$ = $number$,\n", field, FieldConstantName(field));
}
format("};\n");
}
for (auto field : ordered_fields) {
PrintFieldComment(format, field);
......@@ -735,10 +747,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* printer) {
field);
}
format(
"$deprecated_attr$void ${1$clear_$name$$}$();\n"
"$deprecated_attr$static const int ${1$$2$$}$ = $number$;\n",
field, FieldConstantName(field));
format("$deprecated_attr$void ${1$clear_$name$$}$();\n", field);
// Generate type-specific accessor declarations.
field_generators_.get(field).GenerateAccessorDeclarations(printer);
......@@ -1159,10 +1168,6 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
"\n",
index_in_file_messages_);
if (SupportsArenas(descriptor_)) {
format("void UnsafeArenaSwap($classname$* other);\n");
}
if (IsAnyMessage(descriptor_, options_)) {
format(
"// implements Any -----------------------------------------------\n"
......@@ -1205,10 +1210,34 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* printer) {
ShouldMarkNewAsFinal(descriptor_, options_) ? "final" : "");
format(
"void Swap($classname$* other);\n"
"friend void swap($classname$& a, $classname$& b) {\n"
" a.Swap(&b);\n"
"}\n"
"}\n");
if (SupportsArenas(descriptor_)) {
format(
"inline void Swap($classname$* other) {\n"
" if (other == this) return;\n"
" if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {\n"
" InternalSwap(other);\n"
" } else {\n"
" ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);\n"
" }\n"
"}\n"
"void UnsafeArenaSwap($classname$* other) {\n"
" if (other == this) return;\n"
" $DCHK$(GetArenaNoVirtual() == other->GetArenaNoVirtual());\n"
" InternalSwap(other);\n"
"}\n");
} else {
format(
"inline void Swap($classname$* other) {\n"
" if (other == this) return;\n"
" InternalSwap(other);\n"
"}\n");
}
format(
"\n"
"// implements Message ----------------------------------------------\n"
"\n"
......@@ -2031,15 +2060,6 @@ void MessageGenerator::GenerateClassMethods(io::Printer* printer) {
}
}
// Generate field number constants.
format("#if !defined(_MSC_VER) || _MSC_VER >= 1900\n");
for (auto field : FieldRange(descriptor_)) {
format("const int $classname$::$1$;\n", FieldConstantName(field));
}
format(
"#endif // !defined(_MSC_VER) || _MSC_VER >= 1900\n"
"\n");
GenerateStructors(printer);
format("\n");
......@@ -3003,40 +3023,7 @@ void MessageGenerator::GenerateOneofClear(io::Printer* printer) {
void MessageGenerator::GenerateSwap(io::Printer* printer) {
Formatter format(printer, variables_);
if (SupportsArenas(descriptor_)) {
// Generate the Swap member function. This is a lightweight wrapper around
// UnsafeArenaSwap() / MergeFrom() with temporaries, depending on the memory
// ownership situation: swapping across arenas or between an arena and a
// heap requires copying.
format(
"void $classname$::Swap($classname$* other) {\n"
" if (other == this) return;\n"
" if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {\n"
" InternalSwap(other);\n"
" } else {\n"
" $classname$* temp = New(GetArenaNoVirtual());\n"
" temp->MergeFrom(*other);\n"
" other->CopyFrom(*this);\n"
" InternalSwap(temp);\n"
" if (GetArenaNoVirtual() == nullptr) {\n"
" delete temp;\n"
" }\n"
" }\n"
"}\n"
"void $classname$::UnsafeArenaSwap($classname$* other) {\n"
" if (other == this) return;\n"
" $DCHK$(GetArenaNoVirtual() == other->GetArenaNoVirtual());\n"
" InternalSwap(other);\n"
"}\n");
} else {
format(
"void $classname$::Swap($classname$* other) {\n"
" if (other == this) return;\n"
" InternalSwap(other);\n"
"}\n");
}
// Generate the UnsafeArenaSwap member function.
format("void $classname$::InternalSwap($classname$* other) {\n");
format.Indent();
format("using std::swap;\n");
......
......@@ -1651,7 +1651,11 @@ bool IsWellKnownTypeFile(const FileDescriptor* file) {
} // anonymous namespace
void Generator::GenerateHeader(const GeneratorOptions& options,
const FileDescriptor* file,
io::Printer* printer) const {
if (file != nullptr) {
printer->Print("// source: $filename$\n", "filename", file->name());
}
printer->Print(
"/**\n"
" * @fileoverview\n"
......@@ -3637,7 +3641,7 @@ bool Generator::GenerateFile(const FileDescriptor* file,
void Generator::GenerateFile(const GeneratorOptions& options,
io::Printer* printer,
const FileDescriptor* file) const {
GenerateHeader(options, printer);
GenerateHeader(options, file, printer);
// Generate "require" statements.
if ((options.import_style == GeneratorOptions::kImportCommonJs ||
......@@ -3748,7 +3752,11 @@ bool Generator::GenerateAll(const std::vector<const FileDescriptor*>& files,
}
}
GenerateHeader(options, &printer);
if (files.size() == 1) {
GenerateHeader(options, files[0], &printer);
} else {
GenerateHeader(options, nullptr, &printer);
}
std::set<std::string> provided;
FindProvides(options, &printer, files, &provided);
......@@ -3811,7 +3819,7 @@ bool Generator::GenerateAll(const std::vector<const FileDescriptor*>& files,
output.get(), '$',
options.annotate_code ? &annotation_collector : nullptr);
GenerateHeader(options, &printer);
GenerateHeader(options, file, &printer);
std::set<std::string> provided;
for (auto one_desc : scc->descriptors) {
......@@ -3864,7 +3872,7 @@ bool Generator::GenerateAll(const std::vector<const FileDescriptor*>& files,
output.get(), '$',
options.annotate_code ? &annotation_collector : nullptr);
GenerateHeader(options, &printer);
GenerateHeader(options, file, &printer);
std::set<std::string> provided;
FindProvidesForEnum(options, &printer, enumdesc, &provided);
......@@ -3896,7 +3904,7 @@ bool Generator::GenerateAll(const std::vector<const FileDescriptor*>& files,
output.get(), '$',
options.annotate_code ? &annotation_collector : nullptr);
GenerateHeader(options, &printer);
GenerateHeader(options, file, &printer);
std::set<std::string> provided;
std::vector<const FieldDescriptor*> fields;
......
......@@ -157,7 +157,7 @@ class PROTOC_EXPORT Generator : public CodeGenerator {
private:
void GenerateHeader(const GeneratorOptions& options,
io::Printer* printer) const;
const FileDescriptor* file, io::Printer* printer) const;
// Generate goog.provides() calls.
void FindProvides(const GeneratorOptions& options, io::Printer* printer,
......
......@@ -225,13 +225,6 @@ class Version::_Internal {
}
};
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int Version::kMajorFieldNumber;
const int Version::kMinorFieldNumber;
const int Version::kPatchFieldNumber;
const int Version::kSuffixFieldNumber;
#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
Version::Version()
: ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) {
SharedCtor();
......@@ -631,10 +624,6 @@ bool Version::IsInitialized() const {
return true;
}
void Version::Swap(Version* other) {
if (other == this) return;
InternalSwap(other);
}
void Version::InternalSwap(Version* other) {
using std::swap;
_internal_metadata_.Swap(&other->_internal_metadata_);
......@@ -676,13 +665,6 @@ CodeGeneratorRequest::_Internal::compiler_version(const CodeGeneratorRequest* ms
void CodeGeneratorRequest::clear_proto_file() {
proto_file_.Clear();
}
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int CodeGeneratorRequest::kFileToGenerateFieldNumber;
const int CodeGeneratorRequest::kParameterFieldNumber;
const int CodeGeneratorRequest::kProtoFileFieldNumber;
const int CodeGeneratorRequest::kCompilerVersionFieldNumber;
#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
CodeGeneratorRequest::CodeGeneratorRequest()
: ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) {
SharedCtor();
......@@ -1115,10 +1097,6 @@ bool CodeGeneratorRequest::IsInitialized() const {
return true;
}
void CodeGeneratorRequest::Swap(CodeGeneratorRequest* other) {
if (other == this) return;
InternalSwap(other);
}
void CodeGeneratorRequest::InternalSwap(CodeGeneratorRequest* other) {
using std::swap;
_internal_metadata_.Swap(&other->_internal_metadata_);
......@@ -1153,12 +1131,6 @@ class CodeGeneratorResponse_File::_Internal {
}
};
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int CodeGeneratorResponse_File::kNameFieldNumber;
const int CodeGeneratorResponse_File::kInsertionPointFieldNumber;
const int CodeGeneratorResponse_File::kContentFieldNumber;
#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
CodeGeneratorResponse_File::CodeGeneratorResponse_File()
: ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) {
SharedCtor();
......@@ -1551,10 +1523,6 @@ bool CodeGeneratorResponse_File::IsInitialized() const {
return true;
}
void CodeGeneratorResponse_File::Swap(CodeGeneratorResponse_File* other) {
if (other == this) return;
InternalSwap(other);
}
void CodeGeneratorResponse_File::InternalSwap(CodeGeneratorResponse_File* other) {
using std::swap;
_internal_metadata_.Swap(&other->_internal_metadata_);
......@@ -1584,11 +1552,6 @@ class CodeGeneratorResponse::_Internal {
}
};
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int CodeGeneratorResponse::kErrorFieldNumber;
const int CodeGeneratorResponse::kFileFieldNumber;
#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
CodeGeneratorResponse::CodeGeneratorResponse()
: ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) {
SharedCtor();
......@@ -1902,10 +1865,6 @@ bool CodeGeneratorResponse::IsInitialized() const {
return true;
}
void CodeGeneratorResponse::Swap(CodeGeneratorResponse* other) {
if (other == this) return;
InternalSwap(other);
}
void CodeGeneratorResponse::InternalSwap(CodeGeneratorResponse* other) {
using std::swap;
_internal_metadata_.Swap(&other->_internal_metadata_);
......
......@@ -139,10 +139,13 @@ class PROTOC_EXPORT Version :
static constexpr int kIndexInFileMessages =
0;
void Swap(Version* other);
friend void swap(Version& a, Version& b) {
a.Swap(&b);
}
inline void Swap(Version* other) {
if (other == this) return;
InternalSwap(other);
}
// implements Message ----------------------------------------------
......@@ -204,10 +207,15 @@ class PROTOC_EXPORT Version :
// accessors -------------------------------------------------------
enum : int {
kSuffixFieldNumber = 4,
kMajorFieldNumber = 1,
kMinorFieldNumber = 2,
kPatchFieldNumber = 3,
};
// optional string suffix = 4;
bool has_suffix() const;
void clear_suffix();
static const int kSuffixFieldNumber = 4;
const std::string& suffix() const;
void set_suffix(const std::string& value);
void set_suffix(std::string&& value);
......@@ -220,21 +228,18 @@ class PROTOC_EXPORT Version :
// optional int32 major = 1;
bool has_major() const;
void clear_major();
static const int kMajorFieldNumber = 1;
::PROTOBUF_NAMESPACE_ID::int32 major() const;
void set_major(::PROTOBUF_NAMESPACE_ID::int32 value);
// optional int32 minor = 2;
bool has_minor() const;
void clear_minor();
static const int kMinorFieldNumber = 2;
::PROTOBUF_NAMESPACE_ID::int32 minor() const;
void set_minor(::PROTOBUF_NAMESPACE_ID::int32 value);
// optional int32 patch = 3;
bool has_patch() const;
void clear_patch();
static const int kPatchFieldNumber = 3;
::PROTOBUF_NAMESPACE_ID::int32 patch() const;
void set_patch(::PROTOBUF_NAMESPACE_ID::int32 value);
......@@ -304,10 +309,13 @@ class PROTOC_EXPORT CodeGeneratorRequest :
static constexpr int kIndexInFileMessages =
1;
void Swap(CodeGeneratorRequest* other);
friend void swap(CodeGeneratorRequest& a, CodeGeneratorRequest& b) {
a.Swap(&b);
}
inline void Swap(CodeGeneratorRequest* other) {
if (other == this) return;
InternalSwap(other);
}
// implements Message ----------------------------------------------
......@@ -369,10 +377,15 @@ class PROTOC_EXPORT CodeGeneratorRequest :
// accessors -------------------------------------------------------
enum : int {
kFileToGenerateFieldNumber = 1,
kProtoFileFieldNumber = 15,
kParameterFieldNumber = 2,
kCompilerVersionFieldNumber = 3,
};
// repeated string file_to_generate = 1;
int file_to_generate_size() const;
void clear_file_to_generate();
static const int kFileToGenerateFieldNumber = 1;
const std::string& file_to_generate(int index) const;
std::string* mutable_file_to_generate(int index);
void set_file_to_generate(int index, const std::string& value);
......@@ -390,7 +403,6 @@ class PROTOC_EXPORT CodeGeneratorRequest :
// repeated .google.protobuf.FileDescriptorProto proto_file = 15;
int proto_file_size() const;
void clear_proto_file();
static const int kProtoFileFieldNumber = 15;
PROTOBUF_NAMESPACE_ID::FileDescriptorProto* mutable_proto_file(int index);
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::FileDescriptorProto >*
mutable_proto_file();
......@@ -402,7 +414,6 @@ class PROTOC_EXPORT CodeGeneratorRequest :
// optional string parameter = 2;
bool has_parameter() const;
void clear_parameter();
static const int kParameterFieldNumber = 2;
const std::string& parameter() const;
void set_parameter(const std::string& value);
void set_parameter(std::string&& value);
......@@ -415,7 +426,6 @@ class PROTOC_EXPORT CodeGeneratorRequest :
// optional .google.protobuf.compiler.Version compiler_version = 3;
bool has_compiler_version() const;
void clear_compiler_version();
static const int kCompilerVersionFieldNumber = 3;
const PROTOBUF_NAMESPACE_ID::compiler::Version& compiler_version() const;
PROTOBUF_NAMESPACE_ID::compiler::Version* release_compiler_version();
PROTOBUF_NAMESPACE_ID::compiler::Version* mutable_compiler_version();
......@@ -487,10 +497,13 @@ class PROTOC_EXPORT CodeGeneratorResponse_File :
static constexpr int kIndexInFileMessages =
2;
void Swap(CodeGeneratorResponse_File* other);
friend void swap(CodeGeneratorResponse_File& a, CodeGeneratorResponse_File& b) {
a.Swap(&b);
}
inline void Swap(CodeGeneratorResponse_File* other) {
if (other == this) return;
InternalSwap(other);
}
// implements Message ----------------------------------------------
......@@ -552,10 +565,14 @@ class PROTOC_EXPORT CodeGeneratorResponse_File :
// accessors -------------------------------------------------------
enum : int {
kNameFieldNumber = 1,
kInsertionPointFieldNumber = 2,
kContentFieldNumber = 15,
};
// optional string name = 1;
bool has_name() const;
void clear_name();
static const int kNameFieldNumber = 1;
const std::string& name() const;
void set_name(const std::string& value);
void set_name(std::string&& value);
......@@ -568,7 +585,6 @@ class PROTOC_EXPORT CodeGeneratorResponse_File :
// optional string insertion_point = 2;
bool has_insertion_point() const;
void clear_insertion_point();
static const int kInsertionPointFieldNumber = 2;
const std::string& insertion_point() const;
void set_insertion_point(const std::string& value);
void set_insertion_point(std::string&& value);
......@@ -581,7 +597,6 @@ class PROTOC_EXPORT CodeGeneratorResponse_File :
// optional string content = 15;
bool has_content() const;
void clear_content();
static const int kContentFieldNumber = 15;
const std::string& content() const;
void set_content(const std::string& value);
void set_content(std::string&& value);
......@@ -656,10 +671,13 @@ class PROTOC_EXPORT CodeGeneratorResponse :
static constexpr int kIndexInFileMessages =
3;
void Swap(CodeGeneratorResponse* other);
friend void swap(CodeGeneratorResponse& a, CodeGeneratorResponse& b) {
a.Swap(&b);
}
inline void Swap(CodeGeneratorResponse* other) {
if (other == this) return;
InternalSwap(other);
}
// implements Message ----------------------------------------------
......@@ -723,10 +741,13 @@ class PROTOC_EXPORT CodeGeneratorResponse :
// accessors -------------------------------------------------------
enum : int {
kFileFieldNumber = 15,
kErrorFieldNumber = 1,
};
// repeated .google.protobuf.compiler.CodeGeneratorResponse.File file = 15;
int file_size() const;
void clear_file();
static const int kFileFieldNumber = 15;
PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File* mutable_file(int index);
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File >*
mutable_file();
......@@ -738,7 +759,6 @@ class PROTOC_EXPORT CodeGeneratorResponse :
// optional string error = 1;
bool has_error() const;
void clear_error();
static const int kErrorFieldNumber = 1;
const std::string& error() const;
void set_error(const std::string& value);
void set_error(std::string&& value);
......
......@@ -338,7 +338,10 @@ void Subprocess::Start(const std::string& program, SearchMode search_mode) {
// stuff that is unsafe here.
int ignored;
ignored = write(STDERR_FILENO, argv[0], strlen(argv[0]));
const char* message = ": program not found or is not executable\n";
const char* message =
": program not found or is not executable\n"
"Please specify a program using absolute path or make sure "
"the program is available in your PATH system variable\n";
ignored = write(STDERR_FILENO, message, strlen(message));
(void)ignored;
......
This diff is collapsed.
This diff is collapsed.
......@@ -90,11 +90,6 @@ class Duration::_Internal {
public:
};
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int Duration::kSecondsFieldNumber;
const int Duration::kNanosFieldNumber;
#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
Duration::Duration()
: ::PROTOBUF_NAMESPACE_ID::Message(), _internal_metadata_(nullptr) {
SharedCtor();
......@@ -386,25 +381,6 @@ bool Duration::IsInitialized() const {
return true;
}
void Duration::Swap(Duration* other) {
if (other == this) return;
if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
InternalSwap(other);
} else {
Duration* temp = New(GetArenaNoVirtual());
temp->MergeFrom(*other);
other->CopyFrom(*this);
InternalSwap(temp);
if (GetArenaNoVirtual() == nullptr) {
delete temp;
}
}
}
void Duration::UnsafeArenaSwap(Duration* other) {
if (other == this) return;
GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual());
InternalSwap(other);
}
void Duration::InternalSwap(Duration* other) {
using std::swap;
_internal_metadata_.Swap(&other->_internal_metadata_);
......
This diff is collapsed.
This diff is collapsed.
......@@ -116,11 +116,22 @@ class PROTOBUF_EXPORT Empty :
static constexpr int kIndexInFileMessages =
0;
void UnsafeArenaSwap(Empty* other);
void Swap(Empty* other);
friend void swap(Empty& a, Empty& b) {
a.Swap(&b);
}
inline void Swap(Empty* other) {
if (other == this) return;
if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
InternalSwap(other);
} else {
::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);
}
}
void UnsafeArenaSwap(Empty* other) {
if (other == this) return;
GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual());
InternalSwap(other);
}
// implements Message ----------------------------------------------
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment