From 8284321780ac672b1e3bc9db2f96575a24c0c3b0 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 8 Jul 2020 17:51:03 -0700 Subject: [PATCH] Fixed upb_fielddef_packed() to have the correct default. --- upb/def.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/upb/def.c b/upb/def.c index 0b5c9c5473..15d30aa106 100644 --- a/upb/def.c +++ b/upb/def.c @@ -1548,13 +1548,21 @@ static bool create_fielddef( f->oneof = NULL; } - if (google_protobuf_FieldDescriptorProto_has_options(field_proto)) { - options = google_protobuf_FieldDescriptorProto_options(field_proto); - f->lazy_ = google_protobuf_FieldOptions_lazy(options); + options = google_protobuf_FieldDescriptorProto_has_options(field_proto) ? + google_protobuf_FieldDescriptorProto_options(field_proto) : NULL; + + if (options && google_protobuf_FieldOptions_has_packed(options)) { f->packed_ = google_protobuf_FieldOptions_packed(options); + } else { + /* Repeated fields default to packed for proto3 only. */ + f->packed_ = upb_fielddef_isprimitive(f) && + f->label_ == UPB_LABEL_REPEATED && f->file->syntax == UPB_SYNTAX_PROTO3; + } + + if (options) { + f->lazy_ = google_protobuf_FieldOptions_lazy(options); } else { f->lazy_ = false; - f->packed_ = false; } return true;