From 83c59e705f461cc08e5844d62514dff27c33a74f Mon Sep 17 00:00:00 2001 From: Robert Edmonds Date: Mon, 13 Aug 2018 21:26:00 -0400 Subject: [PATCH] Convert uses of protobuf's scoped_ptr.h to C++11 std::unique_ptr Upstream protobuf removed scoped_ptr.h, which provided the scoped_ptr that we depended on, in commit 67952fab2c766ac5eacc15bb78e5af4039a3d398 (https://github.com/google/protobuf/commit/67952fab2c766ac5eacc15bb78e5af4039a3d398). This commit converts uses of scoped_ptr type to idiomatic C++11 std::unique_ptr, similar to the changes in the protobuf commit. This has been tested on protobuf 3.0.0 (the version currently in Debian) as well as the latest protobuf 3.6.1 release. --- protoc-c/c_field.cc | 2 +- protoc-c/c_field.h | 3 ++- protoc-c/c_file.cc | 8 ++++---- protoc-c/c_file.h | 9 +++++---- protoc-c/c_generator.cc | 5 +++-- protoc-c/c_helpers.cc | 3 ++- protoc-c/c_message.cc | 7 ++++--- protoc-c/c_message.h | 7 ++++--- 8 files changed, 25 insertions(+), 19 deletions(-) diff --git a/protoc-c/c_field.cc b/protoc-c/c_field.cc index 9fa56ef..eaa38d2 100644 --- a/protoc-c/c_field.cc +++ b/protoc-c/c_field.cc @@ -189,7 +189,7 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer, FieldGeneratorMap::FieldGeneratorMap(const Descriptor* descriptor) : descriptor_(descriptor), field_generators_( - new scoped_ptr[descriptor->field_count()]) { + new std::unique_ptr[descriptor->field_count()]) { // Construct all the FieldGenerators. for (int i = 0; i < descriptor->field_count(); i++) { field_generators_[i].reset(MakeGenerator(descriptor->field(i))); diff --git a/protoc-c/c_field.h b/protoc-c/c_field.h index 91f1a03..8a61634 100644 --- a/protoc-c/c_field.h +++ b/protoc-c/c_field.h @@ -63,6 +63,7 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_C_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_C_FIELD_H__ +#include #include #include @@ -117,7 +118,7 @@ class FieldGeneratorMap { private: const Descriptor* descriptor_; - scoped_array > field_generators_; + std::unique_ptr[]> field_generators_; static FieldGenerator* MakeGenerator(const FieldDescriptor* field); diff --git a/protoc-c/c_file.cc b/protoc-c/c_file.cc index 0f1d770..90f18b4 100644 --- a/protoc-c/c_file.cc +++ b/protoc-c/c_file.cc @@ -83,13 +83,13 @@ FileGenerator::FileGenerator(const FileDescriptor* file, const string& dllexport_decl) : file_(file), message_generators_( - new scoped_ptr[file->message_type_count()]), + new std::unique_ptr[file->message_type_count()]), enum_generators_( - new scoped_ptr[file->enum_type_count()]), + new std::unique_ptr[file->enum_type_count()]), service_generators_( - new scoped_ptr[file->service_count()]), + new std::unique_ptr[file->service_count()]), extension_generators_( - new scoped_ptr[file->extension_count()]) { + new std::unique_ptr[file->extension_count()]) { for (int i = 0; i < file->message_type_count(); i++) { message_generators_[i].reset( diff --git a/protoc-c/c_file.h b/protoc-c/c_file.h index 84df522..1101794 100644 --- a/protoc-c/c_file.h +++ b/protoc-c/c_file.h @@ -63,6 +63,7 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_C_FILE_H__ #define GOOGLE_PROTOBUF_COMPILER_C_FILE_H__ +#include #include #include #include @@ -98,10 +99,10 @@ class FileGenerator { private: const FileDescriptor* file_; - scoped_array > message_generators_; - scoped_array > enum_generators_; - scoped_array > service_generators_; - scoped_array > extension_generators_; + std::unique_ptr[]> message_generators_; + std::unique_ptr[]> enum_generators_; + std::unique_ptr[]> service_generators_; + std::unique_ptr[]> extension_generators_; // E.g. if the package is foo.bar, package_parts_ is {"foo", "bar"}. std::vector package_parts_; diff --git a/protoc-c/c_generator.cc b/protoc-c/c_generator.cc index 79a272f..46ad477 100644 --- a/protoc-c/c_generator.cc +++ b/protoc-c/c_generator.cc @@ -62,6 +62,7 @@ #include +#include #include #include @@ -149,7 +150,7 @@ bool CGenerator::Generate(const FileDescriptor* file, // Generate header. { - scoped_ptr output( + std::unique_ptr output( output_directory->Open(basename + ".h")); io::Printer printer(output.get(), '$'); file_generator.GenerateHeader(&printer); @@ -157,7 +158,7 @@ bool CGenerator::Generate(const FileDescriptor* file, // Generate cc file. { - scoped_ptr output( + std::unique_ptr output( output_directory->Open(basename + ".c")); io::Printer printer(output.get(), '$'); file_generator.GenerateSource(&printer); diff --git a/protoc-c/c_helpers.cc b/protoc-c/c_helpers.cc index 71b8682..90aeb53 100644 --- a/protoc-c/c_helpers.cc +++ b/protoc-c/c_helpers.cc @@ -60,6 +60,7 @@ // Modified to implement C code by Dave Benson. +#include #include #include #include // for snprintf @@ -559,7 +560,7 @@ static int CEscapeInternal(const char* src, int src_len, char* dest, } string CEscape(const string& src) { const int dest_length = src.size() * 4 + 1; // Maximum possible expansion - scoped_array dest(new char[dest_length]); + std::unique_ptr dest(new char[dest_length]); const int len = CEscapeInternal(src.data(), src.size(), dest.get(), dest_length, false); GOOGLE_DCHECK_GE(len, 0); diff --git a/protoc-c/c_message.cc b/protoc-c/c_message.cc index 6b22c71..d9a6a33 100755 --- a/protoc-c/c_message.cc +++ b/protoc-c/c_message.cc @@ -62,6 +62,7 @@ #include #include +#include #include #include #include @@ -83,11 +84,11 @@ MessageGenerator::MessageGenerator(const Descriptor* descriptor, : descriptor_(descriptor), dllexport_decl_(dllexport_decl), field_generators_(descriptor), - nested_generators_(new scoped_ptr[ + nested_generators_(new std::unique_ptr[ descriptor->nested_type_count()]), - enum_generators_(new scoped_ptr[ + enum_generators_(new std::unique_ptr[ descriptor->enum_type_count()]), - extension_generators_(new scoped_ptr[ + extension_generators_(new std::unique_ptr[ descriptor->extension_count()]) { for (int i = 0; i < descriptor->nested_type_count(); i++) { diff --git a/protoc-c/c_message.h b/protoc-c/c_message.h index 8b115d1..a30d78b 100644 --- a/protoc-c/c_message.h +++ b/protoc-c/c_message.h @@ -63,6 +63,7 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_C_MESSAGE_H__ #define GOOGLE_PROTOBUF_COMPILER_C_MESSAGE_H__ +#include #include #include #include @@ -126,9 +127,9 @@ class MessageGenerator { const Descriptor* descriptor_; string dllexport_decl_; FieldGeneratorMap field_generators_; - scoped_array > nested_generators_; - scoped_array > enum_generators_; - scoped_array > extension_generators_; + std::unique_ptr[]> nested_generators_; + std::unique_ptr[]> enum_generators_; + std::unique_ptr[]> extension_generators_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator); };