From b8001134c5c93b0408ff48faaf9d9bebf6b2e226 Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Mon, 16 Oct 2023 11:03:58 -0700 Subject: [PATCH] Remove code for handling global dtors default instances are no longer deleted. PiperOrigin-RevId: 573867065 --- .../cpp/field_generators/message_field.cc | 18 ++++----- src/google/protobuf/compiler/plugin.pb.cc | 4 +- src/google/protobuf/descriptor.pb.cc | 40 +++++++++---------- 3 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/field_generators/message_field.cc b/src/google/protobuf/compiler/cpp/field_generators/message_field.cc index 8ceb1e0c26..a7c7935c9a 100644 --- a/src/google/protobuf/compiler/cpp/field_generators/message_field.cc +++ b/src/google/protobuf/compiler/cpp/field_generators/message_field.cc @@ -431,19 +431,15 @@ void SingularMessage::GenerateSwappingCode(io::Printer* p) const { } void SingularMessage::GenerateDestructorCode(io::Printer* p) const { - if (opts_->opensource_runtime) { - // TODO Remove this when we don't need to destruct default - // instances. In google3 a default instance will never get deleted so we - // don't need to worry about that but in opensource protobuf default - // instances are deleted in shutdown process and we need to take special - // care when handling them. - p->Emit("if (this != internal_default_instance()) "); - } if (should_split()) { - p->Emit("delete $cached_split_ptr$->$name$_;\n"); - return; + p->Emit(R"cc( + delete $cached_split_ptr$->$name$_; + )cc"); + } else { + p->Emit(R"cc( + delete $field_$; + )cc"); } - p->Emit("delete $field_$;\n"); } using internal::cpp::HasHasbit; diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index 1b18575e14..684bdd31d7 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -689,7 +689,7 @@ CodeGeneratorRequest::~CodeGeneratorRequest() { inline void CodeGeneratorRequest::SharedDtor() { ABSL_DCHECK(GetArena() == nullptr); _impl_.parameter_.Destroy(); - if (this != internal_default_instance()) delete _impl_.compiler_version_; + delete _impl_.compiler_version_; _impl_.~Impl_(); } @@ -1037,7 +1037,7 @@ inline void CodeGeneratorResponse_File::SharedDtor() { _impl_.name_.Destroy(); _impl_.insertion_point_.Destroy(); _impl_.content_.Destroy(); - if (this != internal_default_instance()) delete _impl_.generated_code_info_; + delete _impl_.generated_code_info_; _impl_.~Impl_(); } diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index 140eadd3e9..8e880a77c7 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -2640,8 +2640,8 @@ inline void FileDescriptorProto::SharedDtor() { _impl_.name_.Destroy(); _impl_.package_.Destroy(); _impl_.syntax_.Destroy(); - if (this != internal_default_instance()) delete _impl_.options_; - if (this != internal_default_instance()) delete _impl_.source_code_info_; + delete _impl_.options_; + delete _impl_.source_code_info_; _impl_.~Impl_(); } @@ -3208,7 +3208,7 @@ DescriptorProto_ExtensionRange::~DescriptorProto_ExtensionRange() { } inline void DescriptorProto_ExtensionRange::SharedDtor() { ABSL_DCHECK(GetArena() == nullptr); - if (this != internal_default_instance()) delete _impl_.options_; + delete _impl_.options_; _impl_.~Impl_(); } @@ -3725,7 +3725,7 @@ DescriptorProto::~DescriptorProto() { inline void DescriptorProto::SharedDtor() { ABSL_DCHECK(GetArena() == nullptr); _impl_.name_.Destroy(); - if (this != internal_default_instance()) delete _impl_.options_; + delete _impl_.options_; _impl_.~Impl_(); } @@ -4547,7 +4547,7 @@ ExtensionRangeOptions::~ExtensionRangeOptions() { } inline void ExtensionRangeOptions::SharedDtor() { ABSL_DCHECK(GetArena() == nullptr); - if (this != internal_default_instance()) delete _impl_.features_; + delete _impl_.features_; _impl_.~Impl_(); } @@ -4920,7 +4920,7 @@ inline void FieldDescriptorProto::SharedDtor() { _impl_.type_name_.Destroy(); _impl_.default_value_.Destroy(); _impl_.json_name_.Destroy(); - if (this != internal_default_instance()) delete _impl_.options_; + delete _impl_.options_; _impl_.~Impl_(); } @@ -5421,7 +5421,7 @@ OneofDescriptorProto::~OneofDescriptorProto() { inline void OneofDescriptorProto::SharedDtor() { ABSL_DCHECK(GetArena() == nullptr); _impl_.name_.Destroy(); - if (this != internal_default_instance()) delete _impl_.options_; + delete _impl_.options_; _impl_.~Impl_(); } @@ -5906,7 +5906,7 @@ EnumDescriptorProto::~EnumDescriptorProto() { inline void EnumDescriptorProto::SharedDtor() { ABSL_DCHECK(GetArena() == nullptr); _impl_.name_.Destroy(); - if (this != internal_default_instance()) delete _impl_.options_; + delete _impl_.options_; _impl_.~Impl_(); } @@ -6248,7 +6248,7 @@ EnumValueDescriptorProto::~EnumValueDescriptorProto() { inline void EnumValueDescriptorProto::SharedDtor() { ABSL_DCHECK(GetArena() == nullptr); _impl_.name_.Destroy(); - if (this != internal_default_instance()) delete _impl_.options_; + delete _impl_.options_; _impl_.~Impl_(); } @@ -6534,7 +6534,7 @@ ServiceDescriptorProto::~ServiceDescriptorProto() { inline void ServiceDescriptorProto::SharedDtor() { ABSL_DCHECK(GetArena() == nullptr); _impl_.name_.Destroy(); - if (this != internal_default_instance()) delete _impl_.options_; + delete _impl_.options_; _impl_.~Impl_(); } @@ -6846,7 +6846,7 @@ inline void MethodDescriptorProto::SharedDtor() { _impl_.name_.Destroy(); _impl_.input_type_.Destroy(); _impl_.output_type_.Destroy(); - if (this != internal_default_instance()) delete _impl_.options_; + delete _impl_.options_; _impl_.~Impl_(); } @@ -7312,7 +7312,7 @@ inline void FileOptions::SharedDtor() { _impl_.php_namespace_.Destroy(); _impl_.php_metadata_namespace_.Destroy(); _impl_.ruby_package_.Destroy(); - if (this != internal_default_instance()) delete _impl_.features_; + delete _impl_.features_; _impl_.~Impl_(); } @@ -8128,7 +8128,7 @@ MessageOptions::~MessageOptions() { } inline void MessageOptions::SharedDtor() { ABSL_DCHECK(GetArena() == nullptr); - if (this != internal_default_instance()) delete _impl_.features_; + delete _impl_.features_; _impl_.~Impl_(); } @@ -8781,7 +8781,7 @@ FieldOptions::~FieldOptions() { } inline void FieldOptions::SharedDtor() { ABSL_DCHECK(GetArena() == nullptr); - if (this != internal_default_instance()) delete _impl_.features_; + delete _impl_.features_; _impl_.~Impl_(); } @@ -9308,7 +9308,7 @@ OneofOptions::~OneofOptions() { } inline void OneofOptions::SharedDtor() { ABSL_DCHECK(GetArena() == nullptr); - if (this != internal_default_instance()) delete _impl_.features_; + delete _impl_.features_; _impl_.~Impl_(); } @@ -9585,7 +9585,7 @@ EnumOptions::~EnumOptions() { } inline void EnumOptions::SharedDtor() { ABSL_DCHECK(GetArena() == nullptr); - if (this != internal_default_instance()) delete _impl_.features_; + delete _impl_.features_; _impl_.~Impl_(); } @@ -9935,7 +9935,7 @@ EnumValueOptions::~EnumValueOptions() { } inline void EnumValueOptions::SharedDtor() { ABSL_DCHECK(GetArena() == nullptr); - if (this != internal_default_instance()) delete _impl_.features_; + delete _impl_.features_; _impl_.~Impl_(); } @@ -10258,7 +10258,7 @@ ServiceOptions::~ServiceOptions() { } inline void ServiceOptions::SharedDtor() { ABSL_DCHECK(GetArena() == nullptr); - if (this != internal_default_instance()) delete _impl_.features_; + delete _impl_.features_; _impl_.~Impl_(); } @@ -10565,7 +10565,7 @@ MethodOptions::~MethodOptions() { } inline void MethodOptions::SharedDtor() { ABSL_DCHECK(GetArena() == nullptr); - if (this != internal_default_instance()) delete _impl_.features_; + delete _impl_.features_; _impl_.~Impl_(); } @@ -11900,7 +11900,7 @@ FeatureSetDefaults_FeatureSetEditionDefault::~FeatureSetDefaults_FeatureSetEditi } inline void FeatureSetDefaults_FeatureSetEditionDefault::SharedDtor() { ABSL_DCHECK(GetArena() == nullptr); - if (this != internal_default_instance()) delete _impl_.features_; + delete _impl_.features_; _impl_.~Impl_(); }