diff --git a/Makefile.am b/Makefile.am index aee2d84..b0cb065 100644 --- a/Makefile.am +++ b/Makefile.am @@ -250,6 +250,23 @@ BUILT_SOURCES += \ EXTRA_DIST += \ t/issue251/issue251.proto +# Issue #330 +check_PROGRAMS += \ + t/issue330/issue330 +TESTS += \ + t/issue330/issue330 +t_issue330_issue330_SOURCES = \ + t/issue330/issue330.c \ + t/issue330/issue330.pb-c.c +t_issue330_issue330_LDADD = \ + protobuf-c/libprotobuf-c.la +t/issue330/issue330.pb-c.c t/issue330/issue330.pb-c.h: $(top_builddir)/protoc-c/protoc-gen-c$(EXEEXT) $(top_srcdir)/t/issue330/issue330.proto + $(AM_V_GEN)@PROTOC@ --plugin=protoc-gen-c=$(top_builddir)/protoc-c/protoc-gen-c$(EXEEXT) -I$(top_srcdir) --c_out=$(top_builddir) $(top_srcdir)/t/issue330/issue330.proto +BUILT_SOURCES += \ + t/issue330/issue330.pb-c.c t/issue330/issue330.pb-c.h +EXTRA_DIST += \ + t/issue330/issue330.proto + # Issue #375 check_PROGRAMS += \ t/issue375/issue375 diff --git a/protoc-c/c_field.cc b/protoc-c/c_field.cc index eaa38d2..bf11def 100644 --- a/protoc-c/c_field.cc +++ b/protoc-c/c_field.cc @@ -140,8 +140,14 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer, if (descriptor_->label() == FieldDescriptor::LABEL_REPEATED && is_packable_type (descriptor_->type()) - && descriptor_->options().packed()) + && descriptor_->options().packed()) { variables["flags"] += " | PROTOBUF_C_FIELD_FLAG_PACKED"; + } else if (descriptor_->label() == FieldDescriptor::LABEL_REPEATED + && is_packable_type (descriptor_->type()) + && FieldSyntax(descriptor_) == 3 + && !descriptor_->options().has_packed()) { + variables["flags"] += " | PROTOBUF_C_FIELD_FLAG_PACKED"; + } if (descriptor_->options().deprecated()) variables["flags"] += " | PROTOBUF_C_FIELD_FLAG_DEPRECATED"; diff --git a/t/issue330/.gitignore b/t/issue330/.gitignore new file mode 100644 index 0000000..e8625da --- /dev/null +++ b/t/issue330/.gitignore @@ -0,0 +1 @@ +issue330 diff --git a/t/issue330/issue330.c b/t/issue330/issue330.c new file mode 100644 index 0000000..294125d --- /dev/null +++ b/t/issue330/issue330.c @@ -0,0 +1,25 @@ +#include +#include + +#include "t/issue330/issue330.pb-c.h" + +int main(void) +{ + /* Output of $ echo acl_id: 2 acl_id: 3 | protoc issue330.proto \ + * --encode=pbr_route | xxd -i: 0x52, 0x02, 0x02, 0x03 + */ + uint8_t protoc[] = {0x52, 0x02, 0x02, 0x03}; + PbrRoute msg = PBR_ROUTE__INIT; + int ids[] = {2, 3}; + uint8_t buf[16] = {0}; + size_t sz = 0; + + msg.n_acl_id = 2; + msg.acl_id = ids; + sz = pbr_route__pack(&msg, buf); + + assert (sz == sizeof protoc); + assert (memcmp (protoc, buf, sz) == 0); + + return EXIT_SUCCESS; +} diff --git a/t/issue330/issue330.proto b/t/issue330/issue330.proto new file mode 100644 index 0000000..c1e221e --- /dev/null +++ b/t/issue330/issue330.proto @@ -0,0 +1,5 @@ +syntax = "proto3"; + +message pbr_route { +repeated int32 acl_id = 10; +}