diff options
author | 2009-05-06 19:27:03 +0000 | |
---|---|---|
committer | 2009-05-06 19:27:03 +0000 | |
commit | 63e646b7ad6f18228c1807f8d18111ae96e86aa7 (patch) | |
tree | fc524e6f55b32b7d786bd41623402394a2f1af26 /src/google/protobuf/compiler/cpp/cpp_file.cc | |
parent | 9824eda6b558cd88c63064017593521ecad2029f (diff) |
Provide ShutdownProtobufLibrary() which frees all startup-allocated objects.
Diffstat (limited to 'src/google/protobuf/compiler/cpp/cpp_file.cc')
-rw-r--r-- | src/google/protobuf/compiler/cpp/cpp_file.cc | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc index dcc48552..f056ed57 100644 --- a/src/google/protobuf/compiler/cpp/cpp_file.cc +++ b/src/google/protobuf/compiler/cpp/cpp_file.cc @@ -143,20 +143,23 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { // Open namespace. GenerateNamespaceOpeners(printer); - // Forward-declare the AddDescriptors and AssignDescriptors functions, so - // that we can declare them to be friends of each class. + // Forward-declare the AddDescriptors, AssignDescriptors, and ShutdownFile + // functions, so that we can declare them to be friends of each class. printer->Print( "\n" "// Internal implementation detail -- do not call these.\n" "void $dllexport_decl$ $adddescriptorsname$();\n", "adddescriptorsname", GlobalAddDescriptorsName(file_->name()), "dllexport_decl", dllexport_decl_); + printer->Print( - // Note that we don't put dllexport_decl on this because it is only called - // by the .pb.cc file in which it is defined. + // Note that we don't put dllexport_decl on these because they are only + // called by the .pb.cc file in which they are defined. "void $assigndescriptorsname$();\n" + "void $shutdownfilename$();\n" "\n", - "assigndescriptorsname", GlobalAssignDescriptorsName(file_->name())); + "assigndescriptorsname", GlobalAssignDescriptorsName(file_->name()), + "shutdownfilename", GlobalShutdownFileName(file_->name())); // Generate forward declarations of classes. for (int i = 0; i < file_->message_type_count(); i++) { @@ -390,6 +393,23 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { // ----------------------------------------------------------------- + // ShutdownFile(): Deletes descriptors, default instances, etc. on shutdown. + printer->Print( + "\n" + "void $shutdownfilename$() {\n", + "shutdownfilename", GlobalShutdownFileName(file_->name())); + printer->Indent(); + + for (int i = 0; i < file_->message_type_count(); i++) { + message_generators_[i]->GenerateShutdownCode(printer); + } + + printer->Outdent(); + printer->Print( + "}\n"); + + // ----------------------------------------------------------------- + // Now generate the AddDescriptors() function. printer->Print( "\n" @@ -462,6 +482,10 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { message_generators_[i]->GenerateDefaultInstanceInitializer(printer); } + printer->Print( + "::google::protobuf::internal::OnShutdown(&$shutdownfilename$);\n", + "shutdownfilename", GlobalShutdownFileName(file_->name())); + printer->Outdent(); printer->Print( |