From 8c88957ef375f3b739b6e72ea5c2fb71b12e1fc2 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Tue, 16 Jun 2015 16:45:14 -0400 Subject: Add nonnil markup to ObjC library. Add the clang annotations to the objc library and generated code to help with Swift bridging and compiler checks. --- .../protobuf/compiler/objectivec/objectivec_field.cc | 4 ++-- .../protobuf/compiler/objectivec/objectivec_file.cc | 18 +++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'src/google') diff --git a/src/google/protobuf/compiler/objectivec/objectivec_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_field.cc index 0f96a4e6..cf5d8cfb 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_field.cc @@ -331,7 +331,7 @@ void ObjCObjFieldGenerator::GeneratePropertyDeclaration( } printer->Print( variables_, - "@property(nonatomic, readwrite, $property_storage_attribute$) $property_type$ *$name$$storage_attribute$;\n"); + "@property(nonatomic, readwrite, $property_storage_attribute$, null_resettable) $property_type$ *$name$$storage_attribute$;\n"); if (IsInitName(variables_.find("name")->second)) { // If property name starts with init we need to annotate it to get past ARC. // http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227 @@ -379,7 +379,7 @@ void RepeatedFieldGenerator::GeneratePropertyDeclaration( variables_, "$comments$" "$array_comment$" - "@property(nonatomic, readwrite, strong) $array_storage_type$ *$name$$storage_attribute$;\n" + "@property(nonatomic, readwrite, strong, null_resettable) $array_storage_type$ *$name$$storage_attribute$;\n" "@property(nonatomic, readonly) NSUInteger $name$_Count;\n"); if (IsInitName(variables_.find("name")->second)) { // If property name starts with init we need to annotate it to get past ARC. diff --git a/src/google/protobuf/compiler/objectivec/objectivec_file.cc b/src/google/protobuf/compiler/objectivec/objectivec_file.cc index 1955c053..5a5c9e9b 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_file.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_file.cc @@ -117,10 +117,10 @@ void FileGenerator::GenerateHeader(io::Printer *printer) { printer->Print( "// @@protoc_insertion_point(imports)\n" + "\n" + "CF_EXTERN_C_BEGIN\n" "\n"); - printer->Print("CF_EXTERN_C_BEGIN\n\n"); - set fwd_decls; for (vector::iterator iter = message_generators_.begin(); iter != message_generators_.end(); ++iter) { @@ -134,6 +134,10 @@ void FileGenerator::GenerateHeader(io::Printer *printer) { printer->Print("\n"); } + printer->Print( + "NS_ASSUME_NONNULL_BEGIN\n" + "\n"); + // need to write out all enums first for (vector::iterator iter = enum_generators_.begin(); iter != enum_generators_.end(); ++iter) { @@ -148,7 +152,6 @@ void FileGenerator::GenerateHeader(io::Printer *printer) { // For extensions to chain together, the Root gets created even if there // are no extensions. printer->Print( - "\n" "#pragma mark - $root_class_name$\n" "\n" "@interface $root_class_name$ : GPBRootObject\n" @@ -182,11 +185,12 @@ void FileGenerator::GenerateHeader(io::Printer *printer) { (*iter)->GenerateMessageHeader(printer); } - printer->Print("CF_EXTERN_C_END\n"); - printer->Print( - "\n" - "// @@protoc_insertion_point(global_scope)\n"); + "NS_ASSUME_NONNULL_END\n" + "\n" + "CF_EXTERN_C_END\n" + "\n" + "// @@protoc_insertion_point(global_scope)\n"); } void FileGenerator::GenerateSource(io::Printer *printer) { -- cgit v1.2.3