Skip to content

Commit

Permalink
[ObjC] Mark classes that shouldn't be subclassed as such.
Browse files Browse the repository at this point in the history
Several of the classes vended by the runtime don't really support subclassing,
so mark them as such to get compiler enforcement just in case.

PiperOrigin-RevId: 505221732
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Jan 27, 2023
1 parent 55d2123 commit a185a6e
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 5 deletions.
10 changes: 10 additions & 0 deletions objectivec/GPBArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @note This class is not meant to be subclassed.
**/
__attribute__((objc_subclassing_restricted))
@interface GPBInt32Array : NSObject <NSCopying>

/** The number of elements contained in the array. */
Expand Down Expand Up @@ -222,6 +223,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @note This class is not meant to be subclassed.
**/
__attribute__((objc_subclassing_restricted))
@interface GPBUInt32Array : NSObject <NSCopying>

/** The number of elements contained in the array. */
Expand Down Expand Up @@ -396,6 +398,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @note This class is not meant to be subclassed.
**/
__attribute__((objc_subclassing_restricted))
@interface GPBInt64Array : NSObject <NSCopying>

/** The number of elements contained in the array. */
Expand Down Expand Up @@ -570,6 +573,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @note This class is not meant to be subclassed.
**/
__attribute__((objc_subclassing_restricted))
@interface GPBUInt64Array : NSObject <NSCopying>

/** The number of elements contained in the array. */
Expand Down Expand Up @@ -744,6 +748,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @note This class is not meant to be subclassed.
**/
__attribute__((objc_subclassing_restricted))
@interface GPBFloatArray : NSObject <NSCopying>

/** The number of elements contained in the array. */
Expand Down Expand Up @@ -918,6 +923,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @note This class is not meant to be subclassed.
**/
__attribute__((objc_subclassing_restricted))
@interface GPBDoubleArray : NSObject <NSCopying>

/** The number of elements contained in the array. */
Expand Down Expand Up @@ -1092,6 +1098,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @note This class is not meant to be subclassed.
**/
__attribute__((objc_subclassing_restricted))
@interface GPBBoolArray : NSObject <NSCopying>

/** The number of elements contained in the array. */
Expand Down Expand Up @@ -1266,6 +1273,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @note This class is not meant to be subclassed.
**/
__attribute__((objc_subclassing_restricted))
@interface GPBEnumArray : NSObject <NSCopying>

/** The number of elements contained in the array. */
Expand Down Expand Up @@ -1583,6 +1591,7 @@ NS_ASSUME_NONNULL_END
//% *
//% * @note This class is not meant to be subclassed.
//% **/
//%__attribute__((objc_subclassing_restricted))
//%@interface GPB##NAME##Array : NSObject <NSCopying>
//%
//%/** The number of elements contained in the array. */
Expand Down Expand Up @@ -1675,6 +1684,7 @@ NS_ASSUME_NONNULL_END
//% *
//% * @note This class is not meant to be subclassed.
//% **/
//%__attribute__((objc_subclassing_restricted))
//%@interface GPB##NAME##Array : NSObject <NSCopying>
//%
//%/** The number of elements contained in the array. */
Expand Down
1 change: 1 addition & 0 deletions objectivec/GPBCodedInputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ CF_EXTERN_C_END
*
* @note Subclassing of @c GPBCodedInputStream is NOT supported.
**/
__attribute__((objc_subclassing_restricted))
@interface GPBCodedInputStream : NSObject

/**
Expand Down
1 change: 1 addition & 0 deletions objectivec/GPBCodedOutputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ extern NSString *const GPBCodedOutputStreamException_WriteFailed;
*
* @note Subclassing of GPBCodedOutputStream is NOT supported.
**/
__attribute__((objc_subclassing_restricted))
@interface GPBCodedOutputStream : NSObject

/**
Expand Down
10 changes: 8 additions & 2 deletions objectivec/GPBDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ typedef NS_ENUM(uint8_t, GPBFieldType) {
/**
* Describes a proto message.
**/
@interface GPBDescriptor : NSObject <NSCopying>
__attribute__((objc_subclassing_restricted))
@interface GPBDescriptor : NSObject<NSCopying>

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
Expand Down Expand Up @@ -124,6 +125,7 @@ typedef NS_ENUM(uint8_t, GPBFieldType) {
/**
* Describes a proto file.
**/
__attribute__((objc_subclassing_restricted))
@interface GPBFileDescriptor : NSObject

- (instancetype)init NS_UNAVAILABLE;
Expand All @@ -149,6 +151,7 @@ typedef NS_ENUM(uint8_t, GPBFieldType) {
/**
* Describes a oneof field.
**/
__attribute__((objc_subclassing_restricted))
@interface GPBOneofDescriptor : NSObject

- (instancetype)init NS_UNAVAILABLE;
Expand Down Expand Up @@ -182,6 +185,7 @@ typedef NS_ENUM(uint8_t, GPBFieldType) {
/**
* Describes a proto field.
**/
__attribute__((objc_subclassing_restricted))
@interface GPBFieldDescriptor : NSObject

- (instancetype)init NS_UNAVAILABLE;
Expand Down Expand Up @@ -234,6 +238,7 @@ typedef NS_ENUM(uint8_t, GPBFieldType) {
/**
* Describes a proto enum.
**/
__attribute__((objc_subclassing_restricted))
@interface GPBEnumDescriptor : NSObject

- (instancetype)init NS_UNAVAILABLE;
Expand Down Expand Up @@ -329,7 +334,8 @@ typedef NS_ENUM(uint8_t, GPBFieldType) {
/**
* Describes a proto extension.
**/
@interface GPBExtensionDescriptor : NSObject <NSCopying>
__attribute__((objc_subclassing_restricted))
@interface GPBExtensionDescriptor : NSObject<NSCopying>

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
Expand Down
Loading

0 comments on commit a185a6e

Please sign in to comment.