Use is_closed() in more places in the runtime.

PiperOrigin-RevId: 508709514
pull/11914/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent d5ec124bb9
commit 1cf2901a1d
  1. 7
      src/google/protobuf/generated_message_reflection.cc
  2. 8
      src/google/protobuf/wire_format.cc

@ -1339,8 +1339,8 @@ void Reflection::ClearField(Message* message,
case FieldDescriptor::CPPTYPE_MESSAGE:
if (schema_.HasBitIndex(field) == static_cast<uint32_t>(-1)) {
// Proto3 does not have has-bits and we need to set a message field
// to nullptr in order to indicate its un-presence.
// Some fields do not have hasbits and we need to set a message
// field to nullptr in order to indicate its un-presence.
if (message->GetArenaForAllocation() == nullptr) {
delete *MutableRaw<Message*>(message, field);
}
@ -1554,8 +1554,7 @@ void CheckInOrder(const FieldDescriptor* field, uint32_t* last) {
namespace internal {
bool CreateUnknownEnumValues(const FieldDescriptor* field) {
bool open_enum = false;
return field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 || open_enum;
return field->enum_type() == nullptr || !field->enum_type()->is_closed();
}
} // namespace internal
using internal::CreateUnknownEnumValues;

@ -412,7 +412,7 @@ bool WireFormat::ParseAndMergeMessageSetField(uint32_t field_number,
}
static bool StrictUtf8Check(const FieldDescriptor* field) {
return field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3;
return field->requires_utf8_validation();
}
bool WireFormat::ParseAndMergeField(
@ -484,8 +484,7 @@ bool WireFormat::ParseAndMergeField(
if (!WireFormatLite::ReadPrimitive<int, WireFormatLite::TYPE_ENUM>(
input, &value))
return false;
if (message->GetDescriptor()->file()->syntax() ==
FileDescriptor::SYNTAX_PROTO3) {
if (!field->enum_type()->is_closed()) {
message_reflection->AddEnumValue(message, field, value);
} else {
const EnumValueDescriptor* enum_value =
@ -869,8 +868,7 @@ const char* WireFormat::_InternalParseAndMergeField(
auto rep_enum =
reflection->MutableRepeatedFieldInternal<int>(msg, field);
bool open_enum = false;
if (field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 ||
open_enum) {
if (!field->enum_type()->is_closed() || open_enum) {
ptr = internal::PackedEnumParser(rep_enum, ptr, ctx);
} else {
return ctx->ReadPackedVarint(

Loading…
Cancel
Save