Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block subclassing #7124

Merged
merged 1 commit into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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