looper/protobuf_c_optional-1.patch

75 lines
3.3 KiB
Diff

diff --git a/protoc-c/c_field.cc b/protoc-c/c_field.cc
index d49c001..fc4943d 100644
--- a/protoc-c/c_field.cc
+++ b/protoc-c/c_field.cc
@@ -107,7 +107,7 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer,
const std::string &descriptor_addr) const
{
std::map<std::string, std::string> variables;
- const OneofDescriptor *oneof = descriptor_->containing_oneof();
+ const OneofDescriptor *oneof = descriptor_->real_containing_oneof();
const ProtobufCFileOptions opt = descriptor_->file()->options().GetExtension(pb_c_file);
variables["TYPE"] = type_macro;
variables["classname"] = FullNameToC(FieldScope(descriptor_)->full_name(), FieldScope(descriptor_)->file());
diff --git a/protoc-c/c_generator.h b/protoc-c/c_generator.h
index b8b44aa..ceb53b2 100644
--- a/protoc-c/c_generator.h
+++ b/protoc-c/c_generator.h
@@ -93,6 +93,11 @@ class PROTOC_C_EXPORT CGenerator : public CodeGenerator {
const std::string& parameter,
OutputDirectory* output_directory,
std::string* error) const;
+
+ uint64_t GetSupportedFeatures() const override {
+ // Indicate that this code generator supports proto3 optional fields.
+ return FEATURE_PROTO3_OPTIONAL;
+ }
};
} // namespace c
diff --git a/protoc-c/c_message.cc b/protoc-c/c_message.cc
index af2974c..34744f4 100755
--- a/protoc-c/c_message.cc
+++ b/protoc-c/c_message.cc
@@ -149,7 +149,7 @@ GenerateStructDefinition(io::Printer* printer) {
}
// Generate the case enums for unions
- for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
+ for (int i = 0; i < descriptor_->real_oneof_decl_count(); i++) {
const OneofDescriptor *oneof = descriptor_->oneof_decl(i);
vars["opt_comma"] = ",";
@@ -191,7 +191,7 @@ GenerateStructDefinition(io::Printer* printer) {
printer->Indent();
for (int i = 0; i < descriptor_->field_count(); i++) {
const FieldDescriptor *field = descriptor_->field(i);
- if (field->containing_oneof() == NULL) {
+ if (field->real_containing_oneof() == NULL) {
SourceLocation fieldSourceLoc;
field->GetSourceLocation(&fieldSourceLoc);
@@ -202,7 +202,7 @@ GenerateStructDefinition(io::Printer* printer) {
}
// Generate unions from oneofs.
- for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
+ for (int i = 0; i < descriptor_->real_oneof_decl_count(); i++) {
const OneofDescriptor *oneof = descriptor_->oneof_decl(i);
vars["oneofname"] = CamelToLower(oneof->name());
vars["foneofname"] = FullNameToC(oneof->full_name(), oneof->file());
@@ -238,12 +238,12 @@ GenerateStructDefinition(io::Printer* printer) {
" { PROTOBUF_C_MESSAGE_INIT (&$lcclassname$__descriptor) \\\n ");
for (int i = 0; i < descriptor_->field_count(); i++) {
const FieldDescriptor *field = descriptor_->field(i);
- if (field->containing_oneof() == NULL) {
+ if (field->real_containing_oneof() == NULL) {
printer->Print(", ");
field_generators_.get(field).GenerateStaticInit(printer);
}
}
- for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
+ for (int i = 0; i < descriptor_->real_oneof_decl_count(); i++) {
const OneofDescriptor *oneof = descriptor_->oneof_decl(i);
vars["foneofname"] = FullNameToUpper(oneof->full_name(), oneof->file());
// Initialize the case enum