diff options
author | Thomas Van Lenten <thomasvl@google.com> | 2018-01-23 13:38:28 -0500 |
---|---|---|
committer | Thomas Van Lenten <thomasvl@google.com> | 2018-01-25 12:18:39 -0500 |
commit | 3e1587fd4bcfaa447aa5fb43198f4f8709c673e4 (patch) | |
tree | f571c57d9196fa2e2768fdb1843e9e7cc66e0727 /src | |
parent | 6fd2ae7e45584493446b5afe13e8e998e6c9338c (diff) | |
download | protobuf-3e1587fd4bcfaa447aa5fb43198f4f8709c673e4.tar.gz protobuf-3e1587fd4bcfaa447aa5fb43198f4f8709c673e4.tar.bz2 protobuf-3e1587fd4bcfaa447aa5fb43198f4f8709c673e4.zip |
Add an explicit import of stdatomic.h.
The generated code for enums needs atomics support, so generate the
import instead of relying on it via transitive imports. This will
make future changes to this likely likely to break generated code
and runtime support are mixed.
Followup to https://github.com/google/protobuf/pull/4184.
Diffstat (limited to 'src')
-rw-r--r-- | src/google/protobuf/compiler/objectivec/objectivec_file.cc | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.cc b/src/google/protobuf/compiler/objectivec/objectivec_file.cc index 954b2688..a249c71b 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_file.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_file.cc @@ -56,6 +56,20 @@ const int32 GOOGLE_PROTOBUF_OBJC_VERSION = 30002; const char* kHeaderExtension = ".pbobjc.h"; +// Checks if a message contains any enums definitions (on the message or +// a nested message under it). +bool MessageContainsEnums(const Descriptor* message) { + if (message->enum_type_count() > 0) { + return true; + } + for (int i = 0; i < message->nested_type_count(); i++) { + if (MessageContainsEnums(message->nested_type(i))) { + return true; + } + } + return false; +} + // Checks if a message contains any extension definitions (on the message or // a nested message under it). bool MessageContainsExtensions(const Descriptor* message) { @@ -70,6 +84,20 @@ bool MessageContainsExtensions(const Descriptor* message) { return false; } +// Checks if the file contains any enum definitions (at the root or +// nested under a message). +bool FileContainsEnums(const FileDescriptor* file) { + if (file->enum_type_count() > 0) { + return true; + } + for (int i = 0; i < file->message_type_count(); i++) { + if (MessageContainsEnums(file->message_type(i))) { + return true; + } + } + return false; +} + // Checks if the file contains any extensions definitions (at the root or // nested under a message). bool FileContainsExtensions(const FileDescriptor* file) { @@ -311,6 +339,13 @@ void FileGenerator::GenerateSource(io::Printer *printer) { // #import the runtime support. PrintFileRuntimePreamble(printer, "GPBProtocolBuffers_RuntimeSupport.h"); + // Enums use atomic in the generated code, so add the system import as needed. + if (FileContainsEnums(file_)) { + printer->Print( + "#import <stdatomic.h>\n" + "\n"); + } + vector<const FileDescriptor*> deps_with_extensions; CollectMinimalFileDepsContainingExtensions(file_, &deps_with_extensions); |