Skip to content

Commit

Permalink
Block subclassing
Browse files Browse the repository at this point in the history
Add GPB_FINAL macro to block subclassing of generated ObjC classes.
  • Loading branch information
dmaclach authored and thomasvl committed Jan 24, 2020
1 parent 6f9d488 commit f4a6b99
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 40 deletions.
5 changes: 5 additions & 0 deletions objectivec/GPBBootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@
// Meant to be used internally by generated code.
#define GPB_METHOD_FAMILY_NONE __attribute__((objc_method_family(none)))

// Prevent subclassing of generated proto classes.
#ifndef GPB_FINAL
#define GPB_FINAL __attribute__((objc_subclassing_restricted))
#endif // GPB_FINAL

// ----------------------------------------------------------------------------
// These version numbers are all internal to the ObjC Protobuf runtime; they
// are used to ensure compatibility between the generated sources and the
Expand Down
4 changes: 2 additions & 2 deletions objectivec/Tests/GPBMessageTests+ClassNames.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
#import "GPBRootObject_PackagePrivate.h"

// Support classes for tests using old class name (vs classrefs) interfaces.
@interface MessageLackingClazzRoot : GPBRootObject
GPB_FINAL @interface MessageLackingClazzRoot : GPBRootObject
@end

@interface MessageLackingClazzRoot (DynamicMethods)
+ (GPBExtensionDescriptor *)ext1;
@end

@interface MessageLackingClazz : GPBMessage
GPB_FINAL @interface MessageLackingClazz : GPBMessage
@property(copy, nonatomic) NSString *foo;
@end

Expand Down
4 changes: 2 additions & 2 deletions objectivec/google/protobuf/Any.pbobjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions objectivec/google/protobuf/Api.pbobjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions objectivec/google/protobuf/Duration.pbobjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions objectivec/google/protobuf/Empty.pbobjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions objectivec/google/protobuf/FieldMask.pbobjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions objectivec/google/protobuf/SourceContext.pbobjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions objectivec/google/protobuf/Struct.pbobjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions objectivec/google/protobuf/Timestamp.pbobjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions objectivec/google/protobuf/Type.pbobjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions objectivec/google/protobuf/Wrappers.pbobjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/objectivec/objectivec_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ void FileGenerator::GenerateHeader(io::Printer *printer) {
" * which is a @c GPBExtensionRegistry that includes all the extensions defined by\n"
" * this file and all files that it depends on.\n"
" **/\n"
"@interface $root_class_name$ : GPBRootObject\n"
"GPB_FINAL @interface $root_class_name$ : GPBRootObject\n"
"@end\n"
"\n",
"root_class_name", root_class_name_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ void MessageGenerator::GenerateMessageHeader(io::Printer* printer) {
}

printer->Print(
"$comments$$deprecated_attribute$@interface $classname$ : GPBMessage\n\n",
"$comments$$deprecated_attribute$GPB_FINAL @interface $classname$ : GPBMessage\n\n",
"classname", class_name_,
"deprecated_attribute", deprecated_attribute_,
"comments", message_comments);
Expand Down

0 comments on commit f4a6b99

Please sign in to comment.