aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJisi Liu <jisi.liu@gmail.com>2016-09-23 11:17:00 -0700
committerJisi Liu <jisi.liu@gmail.com>2016-09-23 11:17:00 -0700
commitf184cb60358d89924b057a6cebf0485e9ff665d0 (patch)
tree039028caa8b6b29c58c097fc858bada92dbb5426
parent34996c31b7842d4b32f51b3d112d43de84c5fa02 (diff)
downloadprotobuf-f184cb60358d89924b057a6cebf0485e9ff665d0.tar.gz
protobuf-f184cb60358d89924b057a6cebf0485e9ff665d0.tar.bz2
protobuf-f184cb60358d89924b057a6cebf0485e9ff665d0.zip
Fix default instance destructor
-rw-r--r--src/google/protobuf/any.pb.cc1
-rw-r--r--src/google/protobuf/api.pb.cc7
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_message.cc15
-rw-r--r--src/google/protobuf/compiler/plugin.pb.cc3
-rw-r--r--src/google/protobuf/descriptor.pb.cc59
-rw-r--r--src/google/protobuf/duration.pb.cc1
-rw-r--r--src/google/protobuf/empty.pb.cc1
-rw-r--r--src/google/protobuf/field_mask.pb.cc1
-rw-r--r--src/google/protobuf/generated_message_util.h6
-rw-r--r--src/google/protobuf/source_context.pb.cc1
-rw-r--r--src/google/protobuf/struct.pb.cc3
-rw-r--r--src/google/protobuf/timestamp.pb.cc1
-rw-r--r--src/google/protobuf/type.pb.cc17
-rw-r--r--src/google/protobuf/wrappers.pb.cc9
14 files changed, 112 insertions, 13 deletions
diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc
index fa9d18a2..bc56164c 100644
--- a/src/google/protobuf/any.pb.cc
+++ b/src/google/protobuf/any.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_;
}
diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc
index bd85bbdb..c7ed9fb7 100644
--- a/src/google/protobuf/api.pb.cc
+++ b/src/google/protobuf/api.pb.cc
@@ -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,7 +250,9 @@ Api::~Api() {
void Api::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
version_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- delete source_context_;
+ if (this != &default_instance_.get()) {
+ delete source_context_;
+ }
}
void Api::SetCachedSize(int size) const {
diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc
index f5648663..f3dd8067 100644
--- a/src/google/protobuf/compiler/cpp/cpp_message.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_message.cc
@@ -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(
diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc
index 1c19d46a..4fc7c432 100644
--- a/src/google/protobuf/compiler/plugin.pb.cc
+++ b/src/google/protobuf/compiler/plugin.pb.cc
@@ -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_;
}
diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc
index 43556237..acd5491a 100644
--- a/src/google/protobuf/descriptor.pb.cc
+++ b/src/google/protobuf/descriptor.pb.cc
@@ -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,8 +1256,10 @@ void FileDescriptorProto::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
package_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
syntax_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- delete options_;
- delete source_code_info_;
+ if (this != &default_instance_.get()) {
+ delete options_;
+ delete source_code_info_;
+ }
}
void FileDescriptorProto::SetCachedSize(int size) const {
@@ -3137,7 +3164,9 @@ DescriptorProto::~DescriptorProto() {
void DescriptorProto::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- delete options_;
+ if (this != &default_instance_.get()) {
+ delete options_;
+ }
}
void DescriptorProto::SetCachedSize(int size) const {
@@ -4380,7 +4409,9 @@ void FieldDescriptorProto::SharedDtor() {
extendee_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
default_value_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
json_name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- delete options_;
+ if (this != &default_instance_.get()) {
+ delete options_;
+ }
}
void FieldDescriptorProto::SetCachedSize(int size) const {
@@ -5511,7 +5542,9 @@ OneofDescriptorProto::~OneofDescriptorProto() {
void OneofDescriptorProto::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- delete options_;
+ if (this != &default_instance_.get()) {
+ delete options_;
+ }
}
void OneofDescriptorProto::SetCachedSize(int size) const {
@@ -5932,7 +5965,9 @@ EnumDescriptorProto::~EnumDescriptorProto() {
void EnumDescriptorProto::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- delete options_;
+ if (this != &default_instance_.get()) {
+ delete options_;
+ }
}
void EnumDescriptorProto::SetCachedSize(int size) const {
@@ -6429,7 +6464,9 @@ EnumValueDescriptorProto::~EnumValueDescriptorProto() {
void EnumValueDescriptorProto::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- delete options_;
+ if (this != &default_instance_.get()) {
+ delete options_;
+ }
}
void EnumValueDescriptorProto::SetCachedSize(int size) const {
@@ -6911,7 +6948,9 @@ ServiceDescriptorProto::~ServiceDescriptorProto() {
void ServiceDescriptorProto::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- delete options_;
+ if (this != &default_instance_.get()) {
+ delete options_;
+ }
}
void ServiceDescriptorProto::SetCachedSize(int size) const {
@@ -7416,7 +7455,9 @@ void MethodDescriptorProto::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
input_type_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
output_type_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- delete options_;
+ if (this != &default_instance_.get()) {
+ delete options_;
+ }
}
void MethodDescriptorProto::SetCachedSize(int size) const {
diff --git a/src/google/protobuf/duration.pb.cc b/src/google/protobuf/duration.pb.cc
index 0e1be63c..29b60820 100644
--- a/src/google/protobuf/duration.pb.cc
+++ b/src/google/protobuf/duration.pb.cc
@@ -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_;
}
diff --git a/src/google/protobuf/empty.pb.cc b/src/google/protobuf/empty.pb.cc
index 45bba99b..c2c6283a 100644
--- a/src/google/protobuf/empty.pb.cc
+++ b/src/google/protobuf/empty.pb.cc
@@ -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_;
}
diff --git a/src/google/protobuf/field_mask.pb.cc b/src/google/protobuf/field_mask.pb.cc
index ffe513d3..b5545f23 100644
--- a/src/google/protobuf/field_mask.pb.cc
+++ b/src/google/protobuf/field_mask.pb.cc
@@ -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_;
}
diff --git a/src/google/protobuf/generated_message_util.h b/src/google/protobuf/generated_message_util.h
index 871acca5..8dc64c49 100644
--- a/src/google/protobuf/generated_message_util.h
+++ b/src/google/protobuf/generated_message_util.h
@@ -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_); }
diff --git a/src/google/protobuf/source_context.pb.cc b/src/google/protobuf/source_context.pb.cc
index 195a5d49..eac4775c 100644
--- a/src/google/protobuf/source_context.pb.cc
+++ b/src/google/protobuf/source_context.pb.cc
@@ -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_;
}
diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc
index c609f879..7ef736e2 100644
--- a/src/google/protobuf/struct.pb.cc
+++ b/src/google/protobuf/struct.pb.cc
@@ -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_;
}
diff --git a/src/google/protobuf/timestamp.pb.cc b/src/google/protobuf/timestamp.pb.cc
index 54c6e868..cbf87425 100644
--- a/src/google/protobuf/timestamp.pb.cc
+++ b/src/google/protobuf/timestamp.pb.cc
@@ -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_;
}
diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc
index 0c6de296..c2e5dc35 100644
--- a/src/google/protobuf/type.pb.cc
+++ b/src/google/protobuf/type.pb.cc
@@ -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,7 +395,9 @@ void Type::SharedDtor() {
}
name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena);
- delete source_context_;
+ if (this != &default_instance_.get()) {
+ delete source_context_;
+ }
}
void Type::ArenaDtor(void* object) {
@@ -2295,7 +2302,9 @@ void Enum::SharedDtor() {
}
name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena);
- delete source_context_;
+ if (this != &default_instance_.get()) {
+ delete source_context_;
+ }
}
void Enum::ArenaDtor(void* object) {
@@ -3424,7 +3433,9 @@ void Option::SharedDtor() {
}
name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena);
- delete value_;
+ if (this != &default_instance_.get()) {
+ delete value_;
+ }
}
void Option::ArenaDtor(void* object) {
diff --git a/src/google/protobuf/wrappers.pb.cc b/src/google/protobuf/wrappers.pb.cc
index 41f1a271..4e3ffbb9 100644
--- a/src/google/protobuf/wrappers.pb.cc
+++ b/src/google/protobuf/wrappers.pb.cc
@@ -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_;
}