diff --git a/objectivec/GPBCodedInputStream.m b/objectivec/GPBCodedInputStream.m index 4ee03ef580..6b98ad7bc9 100644 --- a/objectivec/GPBCodedInputStream.m +++ b/objectivec/GPBCodedInputStream.m @@ -494,6 +494,8 @@ void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, int32_t --state_.recursionDepth; } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" - (void)readUnknownGroup:(int32_t)fieldNumber message:(GPBUnknownFieldSet *)message { CheckRecursionLimit(&state_); ++state_.recursionDepth; @@ -502,6 +504,7 @@ void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, int32_t GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup)); --state_.recursionDepth; } +#pragma clang diagnostic pop - (void)readMessage:(GPBMessage *)message extensionRegistry:(id)extensionRegistry { diff --git a/objectivec/GPBCodedInputStream_PackagePrivate.h b/objectivec/GPBCodedInputStream_PackagePrivate.h index 720bd60ee8..b2f8f8e50f 100644 --- a/objectivec/GPBCodedInputStream_PackagePrivate.h +++ b/objectivec/GPBCodedInputStream_PackagePrivate.h @@ -42,7 +42,10 @@ typedef struct GPBCodedInputStreamState { // Reads a group field value from the stream and merges it into the given // UnknownFieldSet. +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" - (void)readUnknownGroup:(int32_t)fieldNumber message:(GPBUnknownFieldSet *)message; +#pragma clang diagnostic pop // Reads a map entry. - (void)readMapEntry:(id)mapDictionary diff --git a/objectivec/GPBCodedOutputStream.h b/objectivec/GPBCodedOutputStream.h index cf55d58f61..3e14517011 100644 --- a/objectivec/GPBCodedOutputStream.h +++ b/objectivec/GPBCodedOutputStream.h @@ -589,6 +589,10 @@ __attribute__((objc_subclassing_restricted)) - (void)writeGroupNoTag:(int32_t)fieldNumber value:(GPBMessage *)value; +//%PDDM-EXPAND-END _WRITE_DECLS() + +// clang-format on + /** * Write a GPBUnknownFieldSet for the given field number. * @@ -596,7 +600,9 @@ __attribute__((objc_subclassing_restricted)) * @param value The value to write out. **/ - (void)writeUnknownGroup:(int32_t)fieldNumber - value:(GPBUnknownFieldSet *)value; + value:(GPBUnknownFieldSet *)value + __attribute__((deprecated("GPBUnknownFieldSet is going away."))); + /** * Write an array of GPBUnknownFieldSet for the given field number. * @@ -604,7 +610,9 @@ __attribute__((objc_subclassing_restricted)) * @param values The values to write out. **/ - (void)writeUnknownGroupArray:(int32_t)fieldNumber - values:(NSArray *)values; + values:(NSArray *)values + __attribute__((deprecated("GPBUnknownFieldSet is going away."))); + /** * Write a GPBUnknownFieldSet without any tag (but does write the endGroup tag). * @@ -612,11 +620,8 @@ __attribute__((objc_subclassing_restricted)) * @param value The value to write out. **/ - (void)writeUnknownGroupNoTag:(int32_t)fieldNumber - value:(GPBUnknownFieldSet *)value; - -//%PDDM-EXPAND-END _WRITE_DECLS() - -// clang-format on + value:(GPBUnknownFieldSet *)value + __attribute__((deprecated("GPBUnknownFieldSet is going away."))); /** Write a MessageSet extension field to the stream. For historical reasons, @@ -741,6 +746,5 @@ NS_ASSUME_NONNULL_END //%_WRITE_UNPACKABLE_DECLS(Message, GPBMessage) //%_WRITE_UNPACKABLE_DECLS(Bytes, NSData) //%_WRITE_GROUP_DECLS(Group, GPBMessage) -//%_WRITE_GROUP_DECLS(UnknownGroup, GPBUnknownFieldSet) // clang-format on diff --git a/objectivec/GPBCodedOutputStream.m b/objectivec/GPBCodedOutputStream.m index 7f81821413..99af261b90 100644 --- a/objectivec/GPBCodedOutputStream.m +++ b/objectivec/GPBCodedOutputStream.m @@ -352,6 +352,9 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value [self writeGroupNoTag:fieldNumber value:value]; } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + - (void)writeUnknownGroupNoTag:(int32_t)fieldNumber value:(const GPBUnknownFieldSet *)value { [value writeToCodedOutputStream:self]; GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatEndGroup); @@ -362,6 +365,8 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value [self writeUnknownGroupNoTag:fieldNumber value:value]; } +#pragma clang diagnostic pop + - (void)writeMessageNoTag:(GPBMessage *)value { GPBWriteRawVarint32(&state_, (int32_t)[value serializedSize]); [value writeToCodedOutputStream:self]; @@ -838,8 +843,12 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value } } -//%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(UnknownGroup, GPBUnknownFieldSet) -// This block of code is generated, do not edit it directly. +//%PDDM-EXPAND-END (19 expansions) + +// clang-format on + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" - (void)writeUnknownGroupArray:(int32_t)fieldNumber values:(NSArray *)values { for (GPBUnknownFieldSet *value in values) { @@ -847,9 +856,7 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value } } -//%PDDM-EXPAND-END (19 expansions) - -// clang-format on +#pragma clang diagnostic pop - (void)writeMessageSetExtension:(int32_t)fieldNumber value:(GPBMessage *)value { GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem, GPBWireFormatStartGroup); @@ -982,7 +989,10 @@ size_t GPBComputeStringSizeNoTag(NSString *value) { size_t GPBComputeGroupSizeNoTag(GPBMessage *value) { return [value serializedSize]; } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" size_t GPBComputeUnknownGroupSizeNoTag(GPBUnknownFieldSet *value) { return value.serializedSize; } +#pragma clang diagnostic pop size_t GPBComputeMessageSizeNoTag(GPBMessage *value) { size_t size = [value serializedSize]; @@ -1050,9 +1060,12 @@ size_t GPBComputeGroupSize(int32_t fieldNumber, GPBMessage *value) { return GPBComputeTagSize(fieldNumber) * 2 + GPBComputeGroupSizeNoTag(value); } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" size_t GPBComputeUnknownGroupSize(int32_t fieldNumber, GPBUnknownFieldSet *value) { return GPBComputeTagSize(fieldNumber) * 2 + GPBComputeUnknownGroupSizeNoTag(value); } +#pragma clang diagnostic pop size_t GPBComputeMessageSize(int32_t fieldNumber, GPBMessage *value) { return GPBComputeTagSize(fieldNumber) + GPBComputeMessageSizeNoTag(value); diff --git a/objectivec/GPBCodedOutputStream_PackagePrivate.h b/objectivec/GPBCodedOutputStream_PackagePrivate.h index 988b320d12..208ad9e11b 100644 --- a/objectivec/GPBCodedOutputStream_PackagePrivate.h +++ b/objectivec/GPBCodedOutputStream_PackagePrivate.h @@ -21,8 +21,11 @@ size_t GPBComputeFixed32Size(int32_t fieldNumber, uint32_t value) __attribute__( size_t GPBComputeBoolSize(int32_t fieldNumber, BOOL value) __attribute__((const)); size_t GPBComputeStringSize(int32_t fieldNumber, NSString *value) __attribute__((const)); size_t GPBComputeGroupSize(int32_t fieldNumber, GPBMessage *value) __attribute__((const)); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" size_t GPBComputeUnknownGroupSize(int32_t fieldNumber, GPBUnknownFieldSet *value) __attribute__((const)); +#pragma clang diagnostic pop size_t GPBComputeMessageSize(int32_t fieldNumber, GPBMessage *value) __attribute__((const)); size_t GPBComputeBytesSize(int32_t fieldNumber, NSData *value) __attribute__((const)); size_t GPBComputeUInt32Size(int32_t fieldNumber, uint32_t value) __attribute__((const)); @@ -43,7 +46,10 @@ size_t GPBComputeFixed32SizeNoTag(uint32_t value) __attribute__((const)); size_t GPBComputeBoolSizeNoTag(BOOL value) __attribute__((const)); size_t GPBComputeStringSizeNoTag(NSString *value) __attribute__((const)); size_t GPBComputeGroupSizeNoTag(GPBMessage *value) __attribute__((const)); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" size_t GPBComputeUnknownGroupSizeNoTag(GPBUnknownFieldSet *value) __attribute__((const)); +#pragma clang diagnostic pop size_t GPBComputeMessageSizeNoTag(GPBMessage *value) __attribute__((const)); size_t GPBComputeBytesSizeNoTag(NSData *value) __attribute__((const)); size_t GPBComputeUInt32SizeNoTag(int32_t value) __attribute__((const)); diff --git a/objectivec/GPBMessage.h b/objectivec/GPBMessage.h index 90d6991de2..2fbc797bf6 100644 --- a/objectivec/GPBMessage.h +++ b/objectivec/GPBMessage.h @@ -55,8 +55,8 @@ CF_EXTERN_C_END * exist in two places, you don't want a sub message to be a property * property of two other messages. * - * @note While the class support NSSecureCoding, if the message has any - * extensions, they will end up reloaded in @c unknownFields as there is + * @note While the class supports NSSecureCoding, if the message has any + * extensions, they will end up reloaded in the unknown fields as there is * no way for the @c NSCoding plumbing to pass through a * @c GPBExtensionRegistry. To support extensions, instead of passing the * calls off to the Message, simple store the result of @c data, and then @@ -73,7 +73,9 @@ CF_EXTERN_C_END /** * The set of unknown fields for this message. **/ -@property(nonatomic, copy, nullable) GPBUnknownFieldSet *unknownFields; +@property(nonatomic, copy, nullable) GPBUnknownFieldSet *unknownFields __attribute__(( + deprecated("Use GPBUnknownFields and the -initFromMessage: initializer and " + "mergeUnknownFields:extensionRegistry:error: to add the data back to a message."))); /** * Whether the message, along with all submessages, have the required fields @@ -510,10 +512,11 @@ CF_EXTERN_C_END * If the intent is to *replace* the message's unknown fields, call `-clearUnknownFields` first. * * Since the data from the GPBUnknownFields will always be well formed, this call will almost never - * fail. What could cause it to fail is if the GPBUnknownFields contains a field values it is - * and error for the message's schema - i.e.: if it contains a length delimited field where the + * fail. What could cause it to fail is if the GPBUnknownFields contains a field value that is + * an error for the message's schema - i.e.: if it contains a length delimited field where the * field number for the message is defined to be a _string_ field, however the length delimited - * data provide is not a valid UTF8 string. + * data provide is not a valid UTF8 string, or if the field is a _packed_ number field, but the + * data provided is not a valid for that field. * * @param unknownFields The unknown fields to merge the data from. * @param extensionRegistry The extension registry to use to look up extensions, can be `nil`. diff --git a/objectivec/GPBMessage.m b/objectivec/GPBMessage.m index 384bf5b0d8..591ac47bd6 100644 --- a/objectivec/GPBMessage.m +++ b/objectivec/GPBMessage.m @@ -79,7 +79,10 @@ NSString *const GPBMessageExceptionMessageTooLarge = // be protected with an @synchronized(self) block (that way the code also doesn't have to // worry about throws). NSMutableData *unknownFieldData_; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" GPBUnknownFieldSet *unknownFields_; +#pragma clang diagnostic pop NSMutableDictionary *extensionMap_; // Readonly access to autocreatedExtensionMap_ is protected via readOnlyLock_. @@ -1106,6 +1109,8 @@ void GPBClearMessageAutocreator(GPBMessage *self) { self->autocreatorExtension_ = nil; } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" GPB_NOINLINE static void MergeUnknownFieldDataIntoFieldSet(GPBMessage *self, NSData *data, GPBUnknownFieldSet *targetSet) { @@ -1151,6 +1156,7 @@ static void MergeUnknownFieldDataIntoFieldSet(GPBMessage *self, NSData *data, [decodeInto release]; } } +#pragma clang diagnostic pop @implementation GPBMessage @@ -1481,7 +1487,14 @@ static void MergeUnknownFieldDataIntoFieldSet(GPBMessage *self, NSData *data, } - (void)clearUnknownFields { - self.unknownFields = nil; + [unknownFieldData_ release]; + unknownFieldData_ = nil; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + [unknownFields_ release]; + unknownFields_ = nil; +#pragma clang diagnostic pop + GPBBecomeVisibleToAutocreator(self); } - (BOOL)mergeUnknownFields:(GPBUnknownFields *)unknownFields @@ -3149,6 +3162,8 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( // need to guard against is concurrent r/o access, so we can grab the values (and retain them) // so we have a version to compare against safely incase the second access causes the transform // between internal states. +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" GPBUnknownFieldSet *selfUnknownFields; NSData *selfUnknownFieldData; @synchronized(self) { @@ -3161,6 +3176,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( otherUnknownFields = [otherMsg->unknownFields_ retain]; otherUnknownFieldData = [otherMsg->unknownFieldData_ retain]; } +#pragma clang diagnostic pop #if defined(DEBUG) && DEBUG && !defined(NS_BLOCK_ASSERTIONS) if (selfUnknownFields) { NSAssert(selfUnknownFieldData == nil, @"Internal error both unknown states were set"); @@ -3189,6 +3205,8 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( result = [selfUnknownFields isEqual:otherUnknownFields]; } else { // At this point, we're done to one have a set/nothing, and the other having data/nothing. +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" GPBUnknownFieldSet *theSet = selfUnknownFields ? selfUnknownFields : otherUnknownFields; NSData *theData = selfUnknownFieldData ? selfUnknownFieldData : otherUnknownFieldData; if (theSet) { @@ -3204,6 +3222,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( // It was a data/nothing and nothing, so they equal if the other didn't have data. result = theData == nil; } +#pragma clang diagnostic pop } [selfUnknownFields release]; @@ -4015,7 +4034,10 @@ id GPBGetObjectIvarWithField(GPBMessage *self, GPBFieldDescriptor *field) { NSData *GPBMessageUnknownFieldsData(GPBMessage *self) { NSData *result = nil; @synchronized(self) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" GPBUnknownFieldSet *unknownFields = self->unknownFields_; +#pragma clang diagnostic pop if (unknownFields) { #if defined(DEBUG) && DEBUG NSCAssert(self->unknownFieldData_ == nil, @"Internal error both unknown states were set"); diff --git a/objectivec/GPBUnknownField.h b/objectivec/GPBUnknownField.h index a1455936bd..6728ed0830 100644 --- a/objectivec/GPBUnknownField.h +++ b/objectivec/GPBUnknownField.h @@ -31,14 +31,15 @@ typedef NS_ENUM(uint8_t, GPBUnknownFieldType) { }; /** - * Store an unknown field. These are used in conjunction with - * GPBUnknownFieldSet. + * Store an unknown field. These are used in conjunction with GPBUnknownFields. **/ __attribute__((objc_subclassing_restricted)) @interface GPBUnknownField : NSObject /** Initialize a field with the given number. */ -- (instancetype)initWithNumber:(int32_t)number; +- (instancetype)initWithNumber:(int32_t)number + __attribute__((deprecated( + "Use the apis on GPBUnknownFields to add new fields instead of making them directly."))); /** The field number the data is stored under. */ @property(nonatomic, readonly, assign) int32_t number; @@ -88,7 +89,8 @@ __attribute__((objc_subclassing_restricted)) * Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error * to use with any other type. */ -@property(nonatomic, readonly, strong) GPBUInt64Array *varintList; +@property(nonatomic, readonly, strong) GPBUInt64Array *varintList + __attribute__((deprecated("See the new apis on GPBUnknownFields and thus reduced api here."))); /** * An array of fixed32 values for this field. @@ -96,7 +98,8 @@ __attribute__((objc_subclassing_restricted)) * Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error * to use with any other type. */ -@property(nonatomic, readonly, strong) GPBUInt32Array *fixed32List; +@property(nonatomic, readonly, strong) GPBUInt32Array *fixed32List + __attribute__((deprecated("See the new apis on GPBUnknownFields and thus reduced api here."))); /** * An array of fixed64 values for this field. @@ -104,7 +107,8 @@ __attribute__((objc_subclassing_restricted)) * Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error * to use with any other type. */ -@property(nonatomic, readonly, strong) GPBUInt64Array *fixed64List; +@property(nonatomic, readonly, strong) GPBUInt64Array *fixed64List + __attribute__((deprecated("See the new apis on GPBUnknownFields and thus reduced api here."))); /** * An array of data values for this field. @@ -112,7 +116,8 @@ __attribute__((objc_subclassing_restricted)) * Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error * to use with any other type. */ -@property(nonatomic, readonly, strong) NSArray *lengthDelimitedList; +@property(nonatomic, readonly, strong) NSArray *lengthDelimitedList + __attribute__((deprecated("See the new apis on GPBUnknownFields and thus reduced api here."))); /** * An array of groups of values for this field. @@ -120,7 +125,8 @@ __attribute__((objc_subclassing_restricted)) * Only valid for type == GPBUnknownFieldTypeLegacy, it is a programming error * to use with any other type. */ -@property(nonatomic, readonly, strong) NSArray *groupList; +@property(nonatomic, readonly, strong) NSArray *groupList + __attribute__((deprecated("See the new apis on GPBUnknownFields and thus reduced api here."))); /** * Add a value to the varintList. @@ -130,7 +136,9 @@ __attribute__((objc_subclassing_restricted)) * * @param value The value to add. **/ -- (void)addVarint:(uint64_t)value; +- (void)addVarint:(uint64_t)value + __attribute__((deprecated("See the new apis on GPBUnknownFields and thus reduced api here."))); + /** * Add a value to the fixed32List. * @@ -139,7 +147,9 @@ __attribute__((objc_subclassing_restricted)) * * @param value The value to add. **/ -- (void)addFixed32:(uint32_t)value; +- (void)addFixed32:(uint32_t)value + __attribute__((deprecated("See the new apis on GPBUnknownFields and thus reduced api here."))); + /** * Add a value to the fixed64List. * @@ -148,7 +158,9 @@ __attribute__((objc_subclassing_restricted)) * * @param value The value to add. **/ -- (void)addFixed64:(uint64_t)value; +- (void)addFixed64:(uint64_t)value + __attribute__((deprecated("See the new apis on GPBUnknownFields and thus reduced api here."))); + /** * Add a value to the lengthDelimitedList. * @@ -157,7 +169,9 @@ __attribute__((objc_subclassing_restricted)) * * @param value The value to add. **/ -- (void)addLengthDelimited:(NSData *)value; +- (void)addLengthDelimited:(NSData *)value + __attribute__((deprecated("See the new apis on GPBUnknownFields and thus reduced api here."))); + /** * Add a value to the groupList. * @@ -166,7 +180,8 @@ __attribute__((objc_subclassing_restricted)) * * @param value The value to add. **/ -- (void)addGroup:(GPBUnknownFieldSet *)value; +- (void)addGroup:(GPBUnknownFieldSet *)value + __attribute__((deprecated("See the new apis on GPBUnknownFields and thus reduced api here."))); @end diff --git a/objectivec/GPBUnknownField.m b/objectivec/GPBUnknownField.m index a3f579501a..ba70dfe599 100644 --- a/objectivec/GPBUnknownField.m +++ b/objectivec/GPBUnknownField.m @@ -169,6 +169,8 @@ // In these modes, the object isn't mutable, so just return self. return [self retain]; case GPBUnknownFieldTypeLegacy: { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" GPBUnknownField *result = [[GPBUnknownField allocWithZone:zone] initWithNumber:number_]; result->storage_.legacy.mutableFixed32List = [storage_.legacy.mutableFixed32List copyWithZone:zone]; @@ -187,6 +189,7 @@ [copied release]; } } +#pragma clang diagnostic pop return result; } } @@ -264,6 +267,8 @@ } - (void)writeToOutput:(GPBCodedOutputStream *)output { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" ASSERT_FIELD_TYPE(GPBUnknownFieldTypeLegacy); NSUInteger count = storage_.legacy.mutableVarintList.count; if (count > 0) { @@ -285,10 +290,13 @@ if (count > 0) { [output writeUnknownGroupArray:number_ values:storage_.legacy.mutableGroupList]; } +#pragma clang diagnostic pop } - (size_t)serializedSize { ASSERT_FIELD_TYPE(GPBUnknownFieldTypeLegacy); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" __block size_t result = 0; int32_t number = number_; [storage_.legacy.mutableVarintList @@ -313,6 +321,7 @@ for (GPBUnknownFieldSet *set in storage_.legacy.mutableGroupList) { result += GPBComputeUnknownGroupSize(number, set); } +#pragma clang diagnostic pop return result; } @@ -353,6 +362,8 @@ [description appendFormat:@" group: %@", storage_.group]; break; case GPBUnknownFieldTypeLegacy: +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" [description appendString:@" {\n"]; [storage_.legacy.mutableVarintList enumerateValuesWithBlock:^(uint64_t value, __unused NSUInteger idx, __unused BOOL *stop) { @@ -373,12 +384,15 @@ [description appendFormat:@"\t%@\n", set]; } [description appendString:@"}"]; +#pragma clang diagnostic pop break; } return description; } - (void)mergeFromField:(GPBUnknownField *)other { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" ASSERT_FIELD_TYPE(GPBUnknownFieldTypeLegacy); GPBUInt64Array *otherVarintList = other.varintList; if (otherVarintList.count > 0) { @@ -429,6 +443,7 @@ [copied release]; } } +#pragma clang diagnostic pop } - (void)addVarint:(uint64_t)value { diff --git a/objectivec/GPBUnknownFieldSet.h b/objectivec/GPBUnknownFieldSet.h index bbe364c3aa..cb64ae13fe 100644 --- a/objectivec/GPBUnknownFieldSet.h +++ b/objectivec/GPBUnknownFieldSet.h @@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN * A collection of unknown fields. Fields parsed from the binary representation * of a message that are unknown end up in an instance of this set. **/ +__attribute__((deprecated("Use GPBUnknownFields instead.", "GPBUnknownFields"))) __attribute__((objc_subclassing_restricted)) @interface GPBUnknownFieldSet : NSObject diff --git a/objectivec/GPBUnknownFieldSet.m b/objectivec/GPBUnknownFieldSet.m index 6ec70b8925..bdf6d0b9d3 100644 --- a/objectivec/GPBUnknownFieldSet.m +++ b/objectivec/GPBUnknownFieldSet.m @@ -13,6 +13,10 @@ #import "GPBUtilities.h" #import "GPBWireFormat.h" +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#pragma clang diagnostic ignored "-Wdeprecated-implementations" + #pragma mark Helpers static void checkNumber(int32_t number) { @@ -154,10 +158,7 @@ static void CopyWorker(__unused const void *key, const void *value, void *contex - (NSString *)description { NSMutableString *description = [NSMutableString stringWithFormat:@"<%@ %p>: TextFormat: {\n", [self class], self]; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" NSString *textFormat = GPBTextFormatForUnknownFieldSet(self, @" "); -#pragma clang diagnostic pop [description appendString:textFormat]; [description appendString:@"}"]; return description; @@ -340,3 +341,5 @@ static void GPBUnknownFieldSetMergeUnknownFields(__unused const void *key, const #pragma clang diagnostic pop @end + +#pragma clang diagnostic pop // -Wdeprecated-declarations suppression diff --git a/objectivec/GPBUnknownField_PackagePrivate.h b/objectivec/GPBUnknownField_PackagePrivate.h index 117dcb9018..dbcba75a4e 100644 --- a/objectivec/GPBUnknownField_PackagePrivate.h +++ b/objectivec/GPBUnknownField_PackagePrivate.h @@ -25,7 +25,10 @@ GPBUInt32Array *_Null_unspecified mutableFixed32List; GPBUInt64Array *_Null_unspecified mutableFixed64List; NSMutableArray *_Null_unspecified mutableLengthDelimitedList; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" NSMutableArray *_Null_unspecified mutableGroupList; +#pragma clang diagnostic pop } legacy; } storage_; } diff --git a/objectivec/Tests/GPBCodedInputStreamTests.m b/objectivec/Tests/GPBCodedInputStreamTests.m index 29802eb15a..c6b019a343 100644 --- a/objectivec/Tests/GPBCodedInputStreamTests.m +++ b/objectivec/Tests/GPBCodedInputStreamTests.m @@ -305,7 +305,10 @@ // skipping as expected (this covers the tags within a group also). GPBCodedInputStream* input1 = [GPBCodedInputStream streamWithData:rawBytes]; GPBCodedInputStream* input2 = [GPBCodedInputStream streamWithData:rawBytes]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" GPBUnknownFieldSet* unknownFields = [[[GPBUnknownFieldSet alloc] init] autorelease]; +#pragma clang diagnostic pop NSUInteger idx = 0; while (YES) { diff --git a/objectivec/Tests/GPBMessageTests+Serialization.m b/objectivec/Tests/GPBMessageTests+Serialization.m index b42bfdd564..5f11640fd1 100644 --- a/objectivec/Tests/GPBMessageTests+Serialization.m +++ b/objectivec/Tests/GPBMessageTests+Serialization.m @@ -430,6 +430,9 @@ XCTAssertEqual(varint, (uint64_t)Message3_Enum_Extra3); [ufs release]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + GPBUnknownFieldSet *unknownFields = msg.unknownFields; XCTAssertEqual([unknownFields countOfFields], 3U); @@ -449,6 +452,8 @@ XCTAssertEqual(field.varintList.count, 1U); XCTAssertEqual([field.varintList valueAtIndex:0], (uint64_t)Message3_Enum_Extra3); +#pragma clang diagnostic pop + [msg release]; [orig release]; } @@ -1412,7 +1417,10 @@ GPBUnknownFields *ufs = [[GPBUnknownFields alloc] initFromMessage:msg1]; XCTAssertEqual(ufs.count, 1U); [ufs release]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" XCTAssertEqual(msg1.unknownFields.countOfFields, 1U); +#pragma clang diagnostic pop data = [msg1 data]; TestEnumMapPlusExtra *msg2 = [TestEnumMapPlusExtra parseFromData:data error:NULL]; @@ -1427,7 +1435,10 @@ ufs = [[GPBUnknownFields alloc] initFromMessage:msg2]; XCTAssertTrue(ufs.empty); [ufs release]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" XCTAssertEqual(msg2.unknownFields.countOfFields, 0U); +#pragma clang diagnostic pop XCTAssertEqualObjects(orig, msg2); diff --git a/objectivec/Tests/GPBMessageTests.m b/objectivec/Tests/GPBMessageTests.m index ab51091564..45b5c28915 100644 --- a/objectivec/Tests/GPBMessageTests.m +++ b/objectivec/Tests/GPBMessageTests.m @@ -493,6 +493,8 @@ TestAllTypes *message = [TestAllTypes message]; [self setAllFields:message repeatedCount:kGPBDefaultRepeatCount]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" GPBUnknownFieldSet *unknownFields = [[[GPBUnknownFieldSet alloc] init] autorelease]; GPBUnknownField *field = [[[GPBUnknownField alloc] initWithNumber:2] autorelease]; [field addVarint:2]; @@ -502,6 +504,7 @@ [unknownFields addField:field]; [message setUnknownFields:unknownFields]; +#pragma clang diagnostic pop GPBUnknownFields *ufs = [[[GPBUnknownFields alloc] init] autorelease]; [ufs addFieldNumber:1234 fixed32:1234]; @@ -976,6 +979,9 @@ } - (void)testAutocreatedUnknownFields { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + // Doing anything with (except reading) unknown fields should cause the // submessage to become visible. TestAllTypes *message = [TestAllTypes message]; @@ -1009,6 +1015,8 @@ extensionRegistry:nil error:NULL]); XCTAssertTrue([message hasOptionalNestedMessage]); + +#pragma clang diagnostic pop } - (void)testSetAutocreatedSubmessageToSelf { @@ -1518,6 +1526,8 @@ varint:&varint]); XCTAssertEqual(varint, 12); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" GPBUnknownFieldSet *unknownFields = msg.unknownFields; GPBUnknownField *field = [unknownFields getField:[UnittestRoot optionalNestedEnumExtension].fieldNumber]; @@ -1532,6 +1542,7 @@ XCTAssertNotNil(field); XCTAssertEqual(field.varintList.count, 1); XCTAssertEqual([field.varintList valueAtIndex:0], 12); +#pragma clang diagnostic pop // Unknown and known, the known come though an unknown go to unknown fields. @@ -1572,6 +1583,8 @@ varint:&varint]); XCTAssertEqual(varint, 12); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" unknownFields = msg.unknownFields; field = [unknownFields getField:[UnittestRoot optionalNestedEnumExtension].fieldNumber]; XCTAssertNotNil(field); @@ -1585,6 +1598,7 @@ XCTAssertNotNil(field); XCTAssertEqual(field.varintList.count, 1); XCTAssertEqual([field.varintList valueAtIndex:0], 12); +#pragma clang diagnostic pop } - (void)testDefaultingExtensionMessages { @@ -1885,10 +1899,13 @@ } - (void)testGenerateAndParseUnknownMessage { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" GPBUnknownFieldSet *unknowns = [[[GPBUnknownFieldSet alloc] init] autorelease]; [unknowns mergeVarintField:123 value:456]; GPBMessage *message = [GPBMessage message]; [message setUnknownFields:unknowns]; +#pragma clang diagnostic pop GPBUnknownFields *ufs = [[[GPBUnknownFields alloc] init] autorelease]; [ufs addFieldNumber:1234 varint:5678]; XCTAssertTrue([message mergeUnknownFields:ufs extensionRegistry:nil error:NULL]); @@ -1898,19 +1915,25 @@ } - (void)testDelimitedWriteAndParseMultipleMessages { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" GPBUnknownFieldSet *unknowns1 = [[[GPBUnknownFieldSet alloc] init] autorelease]; [unknowns1 mergeVarintField:123 value:456]; GPBMessage *message1 = [GPBMessage message]; [message1 setUnknownFields:unknowns1]; +#pragma clang diagnostic pop GPBUnknownFields *ufs1 = [[[GPBUnknownFields alloc] init] autorelease]; [ufs1 addFieldNumber:1234 varint:5678]; XCTAssertTrue([message1 mergeUnknownFields:ufs1 extensionRegistry:nil error:NULL]); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" GPBUnknownFieldSet *unknowns2 = [[[GPBUnknownFieldSet alloc] init] autorelease]; [unknowns2 mergeVarintField:789 value:987]; [unknowns2 mergeVarintField:654 value:321]; GPBMessage *message2 = [GPBMessage message]; [message2 setUnknownFields:unknowns2]; +#pragma clang diagnostic pop GPBUnknownFields *ufs2 = [[[GPBUnknownFields alloc] init] autorelease]; [ufs2 addFieldNumber:2345 fixed32:6789]; [ufs2 addFieldNumber:3456 fixed32:7890]; @@ -2111,6 +2134,8 @@ XCTAssertEqual(fields[0].varint, (uint64_t)EnumTestMsg_MyEnum_Two); XCTAssertEqual(fields[1].varint, (uint64_t)EnumTestMsg_MyEnum_NegTwo); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" GPBUnknownFieldSet *unknownFields = msg2.unknownFields; XCTAssertNotNil(unknownFields); XCTAssertEqual(unknownFields.countOfFields, 3U); @@ -2127,6 +2152,7 @@ XCTAssertEqual(field.varintList.count, 2U); XCTAssertEqual([field.varintList valueAtIndex:0], (uint64_t)EnumTestMsg_MyEnum_Two); XCTAssertEqual([field.varintList valueAtIndex:1], (uint64_t)EnumTestMsg_MyEnum_NegTwo); +#pragma clang diagnostic pop } - (void)testReservedWordNaming { diff --git a/objectivec/Tests/GPBUnknownFieldSetTest.m b/objectivec/Tests/GPBUnknownFieldSetTest.m index 890ce8f4ad..71a375b53a 100644 --- a/objectivec/Tests/GPBUnknownFieldSetTest.m +++ b/objectivec/Tests/GPBUnknownFieldSetTest.m @@ -12,6 +12,9 @@ #import "GPBUnknownField_PackagePrivate.h" #import "objectivec/Tests/Unittest.pbobjc.h" +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + @interface GPBUnknownFieldSet (GPBUnknownFieldSetTest) - (void)getTags:(int32_t*)tags; @end @@ -668,3 +671,5 @@ static NSData* DataForGroupsOfDepth(NSUInteger depth) { } @end + +#pragma clang diagnostic pop diff --git a/objectivec/Tests/GPBUnknownFieldsTest.m b/objectivec/Tests/GPBUnknownFieldsTest.m index c1e5e10634..42c3f7dc87 100644 --- a/objectivec/Tests/GPBUnknownFieldsTest.m +++ b/objectivec/Tests/GPBUnknownFieldsTest.m @@ -911,16 +911,32 @@ } - (void)testMergeFailures { - // Valid data, pushes to the string just fine. + // Valid data, pushes to the fields just fine. { GPBUnknownFields* ufs = [[[GPBUnknownFields alloc] init] autorelease]; [ufs addFieldNumber:TestAllTypes_FieldNumber_OptionalString lengthDelimited:DataFromCStr("abc")]; + [ufs addFieldNumber:TestAllTypes_FieldNumber_RepeatedInt32Array + lengthDelimited:DataFromBytes(0x01, 0x02)]; + [ufs addFieldNumber:TestAllTypes_FieldNumber_RepeatedFixed32Array + lengthDelimited:DataFromBytes(0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00)]; + [ufs addFieldNumber:TestAllTypes_FieldNumber_RepeatedFixed64Array + lengthDelimited:DataFromBytes(0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)]; TestAllTypes* msg = [TestAllTypes message]; NSError* error = nil; XCTAssertTrue([msg mergeUnknownFields:ufs extensionRegistry:nil error:&error]); XCTAssertNil(error); XCTAssertEqualObjects(msg.optionalString, @"abc"); + XCTAssertEqual(msg.repeatedInt32Array.count, 2); + XCTAssertEqual([msg.repeatedInt32Array valueAtIndex:0], 1); + XCTAssertEqual([msg.repeatedInt32Array valueAtIndex:1], 2); + XCTAssertEqual(msg.repeatedFixed32Array.count, 2); + XCTAssertEqual([msg.repeatedFixed32Array valueAtIndex:0], 3); + XCTAssertEqual([msg.repeatedFixed32Array valueAtIndex:1], 4); + XCTAssertEqual(msg.repeatedFixed64Array.count, 2); + XCTAssertEqual([msg.repeatedFixed64Array valueAtIndex:0], 5); + XCTAssertEqual([msg.repeatedFixed64Array valueAtIndex:1], 6); } // Invalid UTF-8 causes a failure when pushed to the message. @@ -933,6 +949,39 @@ XCTAssertFalse([msg mergeUnknownFields:ufs extensionRegistry:nil error:&error]); XCTAssertNotNil(error); } + + // Invalid packed varint causes a failure when pushed to the message. + { + GPBUnknownFields* ufs = [[[GPBUnknownFields alloc] init] autorelease]; + [ufs addFieldNumber:TestAllTypes_FieldNumber_RepeatedInt32Array + lengthDelimited:DataFromBytes(0xff)]; // Invalid varint + TestAllTypes* msg = [TestAllTypes message]; + NSError* error = nil; + XCTAssertFalse([msg mergeUnknownFields:ufs extensionRegistry:nil error:&error]); + XCTAssertNotNil(error); + } + + // Invalid packed fixed32 causes a failure when pushed to the message. + { + GPBUnknownFields* ufs = [[[GPBUnknownFields alloc] init] autorelease]; + [ufs addFieldNumber:TestAllTypes_FieldNumber_RepeatedFixed32Array + lengthDelimited:DataFromBytes(0x01, 0x00, 0x00)]; // Truncated fixed32 + TestAllTypes* msg = [TestAllTypes message]; + NSError* error = nil; + XCTAssertFalse([msg mergeUnknownFields:ufs extensionRegistry:nil error:&error]); + XCTAssertNotNil(error); + } + + // Invalid packed fixed64 causes a failure when pushed to the message. + { + GPBUnknownFields* ufs = [[[GPBUnknownFields alloc] init] autorelease]; + [ufs addFieldNumber:TestAllTypes_FieldNumber_RepeatedFixed64Array + lengthDelimited:DataFromBytes(0x01, 0x00, 0x00, 0x00, 0x00)]; // Truncated fixed64 + TestAllTypes* msg = [TestAllTypes message]; + NSError* error = nil; + XCTAssertFalse([msg mergeUnknownFields:ufs extensionRegistry:nil error:&error]); + XCTAssertNotNil(error); + } } - (void)testLargeVarint { diff --git a/objectivec/Tests/GPBUtilitiesTests.m b/objectivec/Tests/GPBUtilitiesTests.m index 6db22a3d37..66fcad7d4f 100644 --- a/objectivec/Tests/GPBUtilitiesTests.m +++ b/objectivec/Tests/GPBUtilitiesTests.m @@ -240,6 +240,8 @@ } } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" // Helper to make an unknown field set with something in it. static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { GPBUnknownFieldSet *result = [[[GPBUnknownFieldSet alloc] init] autorelease]; @@ -250,6 +252,7 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { return result; } +#pragma clang diagnostic pop // Helper to add an unknown field data to messages. static void AddUnknownFields(GPBMessage *message, int num) { @@ -270,6 +273,9 @@ static BOOL HasUnknownFields(GPBMessage *message) { - (void)testDropMessageUnknownFieldsRecursively { TestAllExtensions *message = [TestAllExtensions message]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + // Give it unknownFields. message.unknownFields = UnknownFieldsSetHelper(777); AddUnknownFields(message, 1777); @@ -412,11 +418,16 @@ static BOOL HasUnknownFields(GPBMessage *message) { XCTAssertFalse(HasUnknownFields(repeatedNestedMessage)); XCTAssertNil(repeatedNestedMessage.unknownFields); } + +#pragma clang diagnostic pop } - (void)testDropMessageUnknownFieldsRecursively_Maps { TestMap *message = [TestMap message]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + { ForeignMessage *foreignMessage = [ForeignMessage message]; foreignMessage.unknownFields = UnknownFieldsSetHelper(100); @@ -466,6 +477,8 @@ static BOOL HasUnknownFields(GPBMessage *message) { XCTAssertFalse(HasUnknownFields(foreignMessage)); XCTAssertNil(foreignMessage.unknownFields); } + +#pragma clang diagnostic pop } @end diff --git a/objectivec/Tests/GPBWireFormatTests.m b/objectivec/Tests/GPBWireFormatTests.m index 2df9f2d6b6..552c48b803 100644 --- a/objectivec/Tests/GPBWireFormatTests.m +++ b/objectivec/Tests/GPBWireFormatTests.m @@ -120,12 +120,15 @@ const int kUnknownTypeId2 = 1550056; [[message_set getExtension:[MSetMessageExtension1 messageSetExtension]] setI:123]; [[message_set getExtension:[MSetMessageExtension2 messageSetExtension]] setStr:@"foo"]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" GPBUnknownField* unknownField = [[[GPBUnknownField alloc] initWithNumber:kUnknownTypeId] autorelease]; [unknownField addLengthDelimited:DataFromCStr("bar")]; GPBUnknownFieldSet* unknownFieldSet = [[[GPBUnknownFieldSet alloc] init] autorelease]; [unknownFieldSet addField:unknownField]; [message_set setUnknownFields:unknownFieldSet]; +#pragma clang diagnostic pop GPBUnknownFields* ufs = [[[GPBUnknownFields alloc] init] autorelease]; GPBUnknownFields* group = [ufs addGroupWithFieldNumber:GPBWireFormatMessageSetItem]; @@ -142,7 +145,10 @@ const int kUnknownTypeId2 = 1550056; GPBUnknownFields* ufs2 = [[[GPBUnknownFields alloc] initFromMessage:raw] autorelease]; XCTAssertTrue(ufs2.empty); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" XCTAssertEqual([raw.unknownFields countOfFields], (NSUInteger)0); +#pragma clang diagnostic pop XCTAssertEqual(raw.itemArray.count, (NSUInteger)4); XCTAssertEqual((uint32_t)[raw.itemArray[0] typeId], @@ -217,11 +223,14 @@ const int kUnknownTypeId2 = 1550056; XCTAssertEqualObjects([group firstLengthDelimited:GPBWireFormatMessageSetMessage], DataFromCStr("bar")); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" XCTAssertEqual([messageSet.unknownFields countOfFields], (NSUInteger)1); GPBUnknownField* unknownField = [messageSet.unknownFields getField:kUnknownTypeId]; XCTAssertNotNil(unknownField); XCTAssertEqual(unknownField.lengthDelimitedList.count, (NSUInteger)1); XCTAssertEqualObjects(unknownField.lengthDelimitedList[0], DataFromCStr("bar")); +#pragma clang diagnostic pop } - (void)testParseMessageSet_FirstValueSticks {