Fix default instance destructor

pull/2170/head
Jisi Liu 8 years ago
parent 34996c31b7
commit f184cb6035
  1. 1
      src/google/protobuf/any.pb.cc
  2. 5
      src/google/protobuf/api.pb.cc
  3. 15
      src/google/protobuf/compiler/cpp/cpp_message.cc
  4. 3
      src/google/protobuf/compiler/plugin.pb.cc
  5. 41
      src/google/protobuf/descriptor.pb.cc
  6. 1
      src/google/protobuf/duration.pb.cc
  7. 1
      src/google/protobuf/empty.pb.cc
  8. 1
      src/google/protobuf/field_mask.pb.cc
  9. 6
      src/google/protobuf/generated_message_util.h
  10. 1
      src/google/protobuf/source_context.pb.cc
  11. 3
      src/google/protobuf/struct.pb.cc
  12. 1
      src/google/protobuf/timestamp.pb.cc
  13. 11
      src/google/protobuf/type.pb.cc
  14. 9
      src/google/protobuf/wrappers.pb.cc

@ -71,6 +71,7 @@ void protobuf_RegisterTypes(const ::std::string&) {
} // namespace
void protobuf_ShutdownFile_google_2fprotobuf_2fany_2eproto() {
Any::default_instance_.Shutdown();
delete Any_reflection_;
}

@ -121,8 +121,11 @@ void protobuf_RegisterTypes(const ::std::string&) {
} // namespace
void protobuf_ShutdownFile_google_2fprotobuf_2fapi_2eproto() {
Api::default_instance_.Shutdown();
delete Api_reflection_;
Method::default_instance_.Shutdown();
delete Method_reflection_;
Mixin::default_instance_.Shutdown();
delete Mixin_reflection_;
}
@ -247,8 +250,10 @@ Api::~Api() {
void Api::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
version_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
if (this != &default_instance_.get()) {
delete source_context_;
}
}
void Api::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();

@ -1815,6 +1815,9 @@ GenerateDefaultInstanceInitializer(io::Printer* printer) {
void MessageGenerator::
GenerateShutdownCode(io::Printer* printer) {
printer->Print(
"$classname$::default_instance_.Shutdown();\n",
"classname", classname_);
if (HasDescriptorMethods(descriptor_->file(), options_)) {
if (descriptor_->oneof_decl_count() > 0) {
printer->Print(
@ -2151,6 +2154,7 @@ GenerateSharedDestructorCode(io::Printer* printer) {
// TODO(kenton): If we make unset messages point at default instances
// instead of NULL, then it would make sense to move this code into
// MessageFieldGenerator::GenerateDestructorCode().
bool need_delete_message_field = false;
for (int i = 0; i < descriptor_->field_count(); i++) {
const FieldDescriptor* field = descriptor_->field(i);
@ -2158,10 +2162,21 @@ GenerateSharedDestructorCode(io::Printer* printer) {
field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
// Skip oneof members
if (!field->containing_oneof()) {
if (!need_delete_message_field) {
need_delete_message_field = true;
printer->Print(
"if (this != &default_instance_.get()) {\n");
printer->Indent();
}
printer->Print("delete $name$_;\n", "name", FieldName(field));
}
}
}
if (need_delete_message_field) {
printer->Outdent();
printer->Print(
"}\n");
}
printer->Outdent();
printer->Print(

@ -114,8 +114,11 @@ void protobuf_RegisterTypes(const ::std::string&) {
} // namespace
void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto() {
CodeGeneratorRequest::default_instance_.Shutdown();
delete CodeGeneratorRequest_reflection_;
CodeGeneratorResponse::default_instance_.Shutdown();
delete CodeGeneratorResponse_reflection_;
CodeGeneratorResponse_File::default_instance_.Shutdown();
delete CodeGeneratorResponse_File_reflection_;
}

@ -622,30 +622,55 @@ void protobuf_RegisterTypes(const ::std::string&) {
} // namespace
void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto() {
FileDescriptorSet::default_instance_.Shutdown();
delete FileDescriptorSet_reflection_;
FileDescriptorProto::default_instance_.Shutdown();
delete FileDescriptorProto_reflection_;
DescriptorProto::default_instance_.Shutdown();
delete DescriptorProto_reflection_;
DescriptorProto_ExtensionRange::default_instance_.Shutdown();
delete DescriptorProto_ExtensionRange_reflection_;
DescriptorProto_ReservedRange::default_instance_.Shutdown();
delete DescriptorProto_ReservedRange_reflection_;
FieldDescriptorProto::default_instance_.Shutdown();
delete FieldDescriptorProto_reflection_;
OneofDescriptorProto::default_instance_.Shutdown();
delete OneofDescriptorProto_reflection_;
EnumDescriptorProto::default_instance_.Shutdown();
delete EnumDescriptorProto_reflection_;
EnumValueDescriptorProto::default_instance_.Shutdown();
delete EnumValueDescriptorProto_reflection_;
ServiceDescriptorProto::default_instance_.Shutdown();
delete ServiceDescriptorProto_reflection_;
MethodDescriptorProto::default_instance_.Shutdown();
delete MethodDescriptorProto_reflection_;
FileOptions::default_instance_.Shutdown();
delete FileOptions_reflection_;
MessageOptions::default_instance_.Shutdown();
delete MessageOptions_reflection_;
FieldOptions::default_instance_.Shutdown();
delete FieldOptions_reflection_;
OneofOptions::default_instance_.Shutdown();
delete OneofOptions_reflection_;
EnumOptions::default_instance_.Shutdown();
delete EnumOptions_reflection_;
EnumValueOptions::default_instance_.Shutdown();
delete EnumValueOptions_reflection_;
ServiceOptions::default_instance_.Shutdown();
delete ServiceOptions_reflection_;
MethodOptions::default_instance_.Shutdown();
delete MethodOptions_reflection_;
UninterpretedOption::default_instance_.Shutdown();
delete UninterpretedOption_reflection_;
UninterpretedOption_NamePart::default_instance_.Shutdown();
delete UninterpretedOption_NamePart_reflection_;
SourceCodeInfo::default_instance_.Shutdown();
delete SourceCodeInfo_reflection_;
SourceCodeInfo_Location::default_instance_.Shutdown();
delete SourceCodeInfo_Location_reflection_;
GeneratedCodeInfo::default_instance_.Shutdown();
delete GeneratedCodeInfo_reflection_;
GeneratedCodeInfo_Annotation::default_instance_.Shutdown();
delete GeneratedCodeInfo_Annotation_reflection_;
}
@ -1231,9 +1256,11 @@ void FileDescriptorProto::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
package_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
syntax_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
if (this != &default_instance_.get()) {
delete options_;
delete source_code_info_;
}
}
void FileDescriptorProto::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
@ -3137,8 +3164,10 @@ DescriptorProto::~DescriptorProto() {
void DescriptorProto::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
if (this != &default_instance_.get()) {
delete options_;
}
}
void DescriptorProto::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
@ -4380,8 +4409,10 @@ void FieldDescriptorProto::SharedDtor() {
extendee_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
default_value_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
json_name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
if (this != &default_instance_.get()) {
delete options_;
}
}
void FieldDescriptorProto::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
@ -5511,8 +5542,10 @@ OneofDescriptorProto::~OneofDescriptorProto() {
void OneofDescriptorProto::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
if (this != &default_instance_.get()) {
delete options_;
}
}
void OneofDescriptorProto::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
@ -5932,8 +5965,10 @@ EnumDescriptorProto::~EnumDescriptorProto() {
void EnumDescriptorProto::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
if (this != &default_instance_.get()) {
delete options_;
}
}
void EnumDescriptorProto::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
@ -6429,8 +6464,10 @@ EnumValueDescriptorProto::~EnumValueDescriptorProto() {
void EnumValueDescriptorProto::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
if (this != &default_instance_.get()) {
delete options_;
}
}
void EnumValueDescriptorProto::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
@ -6911,8 +6948,10 @@ ServiceDescriptorProto::~ServiceDescriptorProto() {
void ServiceDescriptorProto::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
if (this != &default_instance_.get()) {
delete options_;
}
}
void ServiceDescriptorProto::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
@ -7416,8 +7455,10 @@ void MethodDescriptorProto::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
input_type_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
output_type_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
if (this != &default_instance_.get()) {
delete options_;
}
}
void MethodDescriptorProto::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();

@ -71,6 +71,7 @@ void protobuf_RegisterTypes(const ::std::string&) {
} // namespace
void protobuf_ShutdownFile_google_2fprotobuf_2fduration_2eproto() {
Duration::default_instance_.Shutdown();
delete Duration_reflection_;
}

@ -69,6 +69,7 @@ void protobuf_RegisterTypes(const ::std::string&) {
} // namespace
void protobuf_ShutdownFile_google_2fprotobuf_2fempty_2eproto() {
Empty::default_instance_.Shutdown();
delete Empty_reflection_;
}

@ -70,6 +70,7 @@ void protobuf_RegisterTypes(const ::std::string&) {
} // namespace
void protobuf_ShutdownFile_google_2fprotobuf_2ffield_5fmask_2eproto() {
FieldMask::default_instance_.Shutdown();
delete FieldMask_reflection_;
}

@ -84,6 +84,12 @@ class ExplicitlyConstructed {
}
bool IsInitialized() { return init_; }
void Shutdown() {
if (init_) {
init_ = false;
get_mutable()->~T();
}
}
const T& get() const { return reinterpret_cast<const T&>(union_); }
T* get_mutable() { return reinterpret_cast<T*>(&union_); }

@ -70,6 +70,7 @@ void protobuf_RegisterTypes(const ::std::string&) {
} // namespace
void protobuf_ShutdownFile_google_2fprotobuf_2fsource_5fcontext_2eproto() {
SourceContext::default_instance_.Shutdown();
delete SourceContext_reflection_;
}

@ -137,9 +137,12 @@ void protobuf_RegisterTypes(const ::std::string&) {
} // namespace
void protobuf_ShutdownFile_google_2fprotobuf_2fstruct_2eproto() {
Struct::default_instance_.Shutdown();
delete Struct_reflection_;
Value::default_instance_.Shutdown();
delete Value_default_oneof_instance_;
delete Value_reflection_;
ListValue::default_instance_.Shutdown();
delete ListValue_reflection_;
}

@ -71,6 +71,7 @@ void protobuf_RegisterTypes(const ::std::string&) {
} // namespace
void protobuf_ShutdownFile_google_2fprotobuf_2ftimestamp_2eproto() {
Timestamp::default_instance_.Shutdown();
delete Timestamp_reflection_;
}

@ -173,10 +173,15 @@ void protobuf_RegisterTypes(const ::std::string&) {
} // namespace
void protobuf_ShutdownFile_google_2fprotobuf_2ftype_2eproto() {
Type::default_instance_.Shutdown();
delete Type_reflection_;
Field::default_instance_.Shutdown();
delete Field_reflection_;
Enum::default_instance_.Shutdown();
delete Enum_reflection_;
EnumValue::default_instance_.Shutdown();
delete EnumValue_reflection_;
Option::default_instance_.Shutdown();
delete Option_reflection_;
}
@ -390,8 +395,10 @@ void Type::SharedDtor() {
}
name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena);
if (this != &default_instance_.get()) {
delete source_context_;
}
}
void Type::ArenaDtor(void* object) {
Type* _this = reinterpret_cast< Type* >(object);
@ -2295,8 +2302,10 @@ void Enum::SharedDtor() {
}
name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena);
if (this != &default_instance_.get()) {
delete source_context_;
}
}
void Enum::ArenaDtor(void* object) {
Enum* _this = reinterpret_cast< Enum* >(object);
@ -3424,8 +3433,10 @@ void Option::SharedDtor() {
}
name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena);
if (this != &default_instance_.get()) {
delete value_;
}
}
void Option::ArenaDtor(void* object) {
Option* _this = reinterpret_cast< Option* >(object);

@ -222,14 +222,23 @@ void protobuf_RegisterTypes(const ::std::string&) {
} // namespace
void protobuf_ShutdownFile_google_2fprotobuf_2fwrappers_2eproto() {
DoubleValue::default_instance_.Shutdown();
delete DoubleValue_reflection_;
FloatValue::default_instance_.Shutdown();
delete FloatValue_reflection_;
Int64Value::default_instance_.Shutdown();
delete Int64Value_reflection_;
UInt64Value::default_instance_.Shutdown();
delete UInt64Value_reflection_;
Int32Value::default_instance_.Shutdown();
delete Int32Value_reflection_;
UInt32Value::default_instance_.Shutdown();
delete UInt32Value_reflection_;
BoolValue::default_instance_.Shutdown();
delete BoolValue_reflection_;
StringValue::default_instance_.Shutdown();
delete StringValue_reflection_;
BytesValue::default_instance_.Shutdown();
delete BytesValue_reflection_;
}

Loading…
Cancel
Save