Fixed bug: make proto2 setters set hasbit.

pull/13171/head
Joshua Haberman 6 years ago
parent 618981a60f
commit c3011c1548
  1. 718
      google/protobuf/descriptor.upb.h
  2. 8
      upb/generated_util.h
  3. 26
      upbc/generator.cc

File diff suppressed because it is too large Load Diff

@ -84,6 +84,14 @@ UPB_INLINE bool _upb_has_field(const void *msg, size_t idx) {
return (*PTR_AT(msg, idx / 8, const char) & (idx % 8)) != 0; return (*PTR_AT(msg, idx / 8, const char) & (idx % 8)) != 0;
} }
UPB_INLINE bool _upb_sethas(const void *msg, size_t idx) {
return (*PTR_AT(msg, idx / 8, char)) |= (1 << (idx % 8));
}
UPB_INLINE bool _upb_clearhas(const void *msg, size_t idx) {
return (*PTR_AT(msg, idx / 8, char)) &= ~(1 << (idx % 8));
}
UPB_INLINE bool _upb_has_oneof_field(const void *msg, size_t case_ofs, int32_t num) { UPB_INLINE bool _upb_has_oneof_field(const void *msg, size_t case_ofs, int32_t num) {
return *PTR_AT(msg, case_ofs, int32_t) == num; return *PTR_AT(msg, case_ofs, int32_t) == num;
} }

@ -372,14 +372,15 @@ void GenerateMessageInHeader(const protobuf::Descriptor* message, Output& output
for (auto field : FieldNumberOrder(message)) { for (auto field : FieldNumberOrder(message)) {
if (field->is_repeated()) { if (field->is_repeated()) {
output( output(
"UPB_INLINE $0* $1_$2_mutable($1 *msg, size_t *len) { " "UPB_INLINE $0* $1_$2_mutable($1 *msg, size_t *len) {\n"
"return ($0*)_upb_array_mutable_accessor(msg, $3, len); }\n", " return ($0*)_upb_array_mutable_accessor(msg, $3, len);\n"
"}\n",
CType(field), msgname, field->name(), CType(field), msgname, field->name(),
GetSizeInit(layout.GetFieldOffset(field))); GetSizeInit(layout.GetFieldOffset(field)));
output( output(
"UPB_INLINE $0* $1_$2_resize($1 *msg, size_t len, " "UPB_INLINE $0* $1_$2_resize($1 *msg, size_t len, "
"upb_arena *arena) { " "upb_arena *arena) {\n"
"return ($0*)_upb_array_resize_accessor(msg, $3, len, $4, $5, arena); " " return ($0*)_upb_array_resize_accessor(msg, $3, len, $4, $5, arena);\n"
"}\n", "}\n",
CType(field), msgname, field->name(), CType(field), msgname, field->name(),
GetSizeInit(layout.GetFieldOffset(field)), GetSizeInit(layout.GetFieldOffset(field)),
@ -413,16 +414,23 @@ void GenerateMessageInHeader(const protobuf::Descriptor* message, Output& output
); );
} }
} else { } else {
output("UPB_INLINE void $0_set_$1($0 *msg, $2 value) { ", msgname, output("UPB_INLINE void $0_set_$1($0 *msg, $2 value) {\n", msgname,
field->name(), CType(field)); field->name(), CType(field));
if (field->containing_oneof()) { if (field->containing_oneof()) {
output("UPB_WRITE_ONEOF(msg, $0, $1, value, $2, $3); }\n", CType(field), output(
GetSizeInit(layout.GetFieldOffset(field)), " UPB_WRITE_ONEOF(msg, $0, $1, value, $2, $3);\n"
"}\n",
CType(field), GetSizeInit(layout.GetFieldOffset(field)),
GetSizeInit(layout.GetOneofCaseOffset(field->containing_oneof())), GetSizeInit(layout.GetOneofCaseOffset(field->containing_oneof())),
field->number()); field->number());
} else { } else {
output("UPB_FIELD_AT(msg, $0, $1) = value; }\n", CType(field), if (MessageLayout::HasHasbit(field)) {
GetSizeInit(layout.GetFieldOffset(field))); output(" _upb_sethas(msg, $0);\n", layout.GetHasbitIndex(field));
}
output(
" UPB_FIELD_AT(msg, $0, $1) = value;\n"
"}\n",
CType(field), GetSizeInit(layout.GetFieldOffset(field)));
} }
if (field->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_MESSAGE) { if (field->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_MESSAGE) {
output( output(

Loading…
Cancel
Save