Skip to content

Commit 2d5c729

Browse files
authored
Merge pull request #17787 from thomasvl/patch_objc_to_28
CherryPick the lastest work for Objective-C over the the 28 branch
2 parents 49dc63b + 9f6ee72 commit 2d5c729

19 files changed

+244
-37
lines changed

objectivec/GPBCodedInputStream.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ - (void)readGroup:(int32_t)fieldNumber
494494
--state_.recursionDepth;
495495
}
496496

497+
#pragma clang diagnostic push
498+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
497499
- (void)readUnknownGroup:(int32_t)fieldNumber message:(GPBUnknownFieldSet *)message {
498500
CheckRecursionLimit(&state_);
499501
++state_.recursionDepth;
@@ -502,6 +504,7 @@ - (void)readUnknownGroup:(int32_t)fieldNumber message:(GPBUnknownFieldSet *)mess
502504
GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup));
503505
--state_.recursionDepth;
504506
}
507+
#pragma clang diagnostic pop
505508

506509
- (void)readMessage:(GPBMessage *)message
507510
extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry {

objectivec/GPBCodedInputStream_PackagePrivate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ typedef struct GPBCodedInputStreamState {
4242

4343
// Reads a group field value from the stream and merges it into the given
4444
// UnknownFieldSet.
45+
#pragma clang diagnostic push
46+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
4547
- (void)readUnknownGroup:(int32_t)fieldNumber message:(GPBUnknownFieldSet *)message;
48+
#pragma clang diagnostic pop
4649

4750
// Reads a map entry.
4851
- (void)readMapEntry:(id)mapDictionary

objectivec/GPBCodedOutputStream.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -589,34 +589,39 @@ __attribute__((objc_subclassing_restricted))
589589
- (void)writeGroupNoTag:(int32_t)fieldNumber
590590
value:(GPBMessage *)value;
591591

592+
//%PDDM-EXPAND-END _WRITE_DECLS()
593+
594+
// clang-format on
595+
592596
/**
593597
* Write a GPBUnknownFieldSet for the given field number.
594598
*
595599
* @param fieldNumber The field number assigned to the value.
596600
* @param value The value to write out.
597601
**/
598602
- (void)writeUnknownGroup:(int32_t)fieldNumber
599-
value:(GPBUnknownFieldSet *)value;
603+
value:(GPBUnknownFieldSet *)value
604+
__attribute__((deprecated("GPBUnknownFieldSet is going away.")));
605+
600606
/**
601607
* Write an array of GPBUnknownFieldSet for the given field number.
602608
*
603609
* @param fieldNumber The field number assigned to the values.
604610
* @param values The values to write out.
605611
**/
606612
- (void)writeUnknownGroupArray:(int32_t)fieldNumber
607-
values:(NSArray<GPBUnknownFieldSet*> *)values;
613+
values:(NSArray<GPBUnknownFieldSet *> *)values
614+
__attribute__((deprecated("GPBUnknownFieldSet is going away.")));
615+
608616
/**
609617
* Write a GPBUnknownFieldSet without any tag (but does write the endGroup tag).
610618
*
611619
* @param fieldNumber The field number assigned to the value.
612620
* @param value The value to write out.
613621
**/
614622
- (void)writeUnknownGroupNoTag:(int32_t)fieldNumber
615-
value:(GPBUnknownFieldSet *)value;
616-
617-
//%PDDM-EXPAND-END _WRITE_DECLS()
618-
619-
// clang-format on
623+
value:(GPBUnknownFieldSet *)value
624+
__attribute__((deprecated("GPBUnknownFieldSet is going away.")));
620625

621626
/**
622627
Write a MessageSet extension field to the stream. For historical reasons,
@@ -741,6 +746,5 @@ NS_ASSUME_NONNULL_END
741746
//%_WRITE_UNPACKABLE_DECLS(Message, GPBMessage)
742747
//%_WRITE_UNPACKABLE_DECLS(Bytes, NSData)
743748
//%_WRITE_GROUP_DECLS(Group, GPBMessage)
744-
//%_WRITE_GROUP_DECLS(UnknownGroup, GPBUnknownFieldSet)
745749

746750
// clang-format on

objectivec/GPBCodedOutputStream.m

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ - (void)writeGroup:(int32_t)fieldNumber value:(GPBMessage *)value {
352352
[self writeGroupNoTag:fieldNumber value:value];
353353
}
354354

355+
#pragma clang diagnostic push
356+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
357+
355358
- (void)writeUnknownGroupNoTag:(int32_t)fieldNumber value:(const GPBUnknownFieldSet *)value {
356359
[value writeToCodedOutputStream:self];
357360
GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatEndGroup);
@@ -362,6 +365,8 @@ - (void)writeUnknownGroup:(int32_t)fieldNumber value:(GPBUnknownFieldSet *)value
362365
[self writeUnknownGroupNoTag:fieldNumber value:value];
363366
}
364367

368+
#pragma clang diagnostic pop
369+
365370
- (void)writeMessageNoTag:(GPBMessage *)value {
366371
GPBWriteRawVarint32(&state_, (int32_t)[value serializedSize]);
367372
[value writeToCodedOutputStream:self];
@@ -838,18 +843,20 @@ - (void)writeGroupArray:(int32_t)fieldNumber values:(NSArray *)values {
838843
}
839844
}
840845

841-
//%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(UnknownGroup, GPBUnknownFieldSet)
842-
// This block of code is generated, do not edit it directly.
846+
//%PDDM-EXPAND-END (19 expansions)
847+
848+
// clang-format on
849+
850+
#pragma clang diagnostic push
851+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
843852

844853
- (void)writeUnknownGroupArray:(int32_t)fieldNumber values:(NSArray *)values {
845854
for (GPBUnknownFieldSet *value in values) {
846855
[self writeUnknownGroup:fieldNumber value:value];
847856
}
848857
}
849858

850-
//%PDDM-EXPAND-END (19 expansions)
851-
852-
// clang-format on
859+
#pragma clang diagnostic pop
853860

854861
- (void)writeMessageSetExtension:(int32_t)fieldNumber value:(GPBMessage *)value {
855862
GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem, GPBWireFormatStartGroup);
@@ -982,7 +989,10 @@ size_t GPBComputeStringSizeNoTag(NSString *value) {
982989

983990
size_t GPBComputeGroupSizeNoTag(GPBMessage *value) { return [value serializedSize]; }
984991

992+
#pragma clang diagnostic push
993+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
985994
size_t GPBComputeUnknownGroupSizeNoTag(GPBUnknownFieldSet *value) { return value.serializedSize; }
995+
#pragma clang diagnostic pop
986996

987997
size_t GPBComputeMessageSizeNoTag(GPBMessage *value) {
988998
size_t size = [value serializedSize];
@@ -1050,9 +1060,12 @@ size_t GPBComputeGroupSize(int32_t fieldNumber, GPBMessage *value) {
10501060
return GPBComputeTagSize(fieldNumber) * 2 + GPBComputeGroupSizeNoTag(value);
10511061
}
10521062

1063+
#pragma clang diagnostic push
1064+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
10531065
size_t GPBComputeUnknownGroupSize(int32_t fieldNumber, GPBUnknownFieldSet *value) {
10541066
return GPBComputeTagSize(fieldNumber) * 2 + GPBComputeUnknownGroupSizeNoTag(value);
10551067
}
1068+
#pragma clang diagnostic pop
10561069

10571070
size_t GPBComputeMessageSize(int32_t fieldNumber, GPBMessage *value) {
10581071
return GPBComputeTagSize(fieldNumber) + GPBComputeMessageSizeNoTag(value);

objectivec/GPBCodedOutputStream_PackagePrivate.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ size_t GPBComputeFixed32Size(int32_t fieldNumber, uint32_t value) __attribute__(
2121
size_t GPBComputeBoolSize(int32_t fieldNumber, BOOL value) __attribute__((const));
2222
size_t GPBComputeStringSize(int32_t fieldNumber, NSString *value) __attribute__((const));
2323
size_t GPBComputeGroupSize(int32_t fieldNumber, GPBMessage *value) __attribute__((const));
24+
#pragma clang diagnostic push
25+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
2426
size_t GPBComputeUnknownGroupSize(int32_t fieldNumber, GPBUnknownFieldSet *value)
2527
__attribute__((const));
28+
#pragma clang diagnostic pop
2629
size_t GPBComputeMessageSize(int32_t fieldNumber, GPBMessage *value) __attribute__((const));
2730
size_t GPBComputeBytesSize(int32_t fieldNumber, NSData *value) __attribute__((const));
2831
size_t GPBComputeUInt32Size(int32_t fieldNumber, uint32_t value) __attribute__((const));
@@ -43,7 +46,10 @@ size_t GPBComputeFixed32SizeNoTag(uint32_t value) __attribute__((const));
4346
size_t GPBComputeBoolSizeNoTag(BOOL value) __attribute__((const));
4447
size_t GPBComputeStringSizeNoTag(NSString *value) __attribute__((const));
4548
size_t GPBComputeGroupSizeNoTag(GPBMessage *value) __attribute__((const));
49+
#pragma clang diagnostic push
50+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
4651
size_t GPBComputeUnknownGroupSizeNoTag(GPBUnknownFieldSet *value) __attribute__((const));
52+
#pragma clang diagnostic pop
4753
size_t GPBComputeMessageSizeNoTag(GPBMessage *value) __attribute__((const));
4854
size_t GPBComputeBytesSizeNoTag(NSData *value) __attribute__((const));
4955
size_t GPBComputeUInt32SizeNoTag(int32_t value) __attribute__((const));

objectivec/GPBMessage.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ CF_EXTERN_C_END
5555
* exist in two places, you don't want a sub message to be a property
5656
* property of two other messages.
5757
*
58-
* @note While the class support NSSecureCoding, if the message has any
59-
* extensions, they will end up reloaded in @c unknownFields as there is
58+
* @note While the class supports NSSecureCoding, if the message has any
59+
* extensions, they will end up reloaded in the unknown fields as there is
6060
* no way for the @c NSCoding plumbing to pass through a
6161
* @c GPBExtensionRegistry. To support extensions, instead of passing the
6262
* calls off to the Message, simple store the result of @c data, and then
@@ -73,7 +73,9 @@ CF_EXTERN_C_END
7373
/**
7474
* The set of unknown fields for this message.
7575
**/
76-
@property(nonatomic, copy, nullable) GPBUnknownFieldSet *unknownFields;
76+
@property(nonatomic, copy, nullable) GPBUnknownFieldSet *unknownFields __attribute__((
77+
deprecated("Use GPBUnknownFields and the -initFromMessage: initializer and "
78+
"mergeUnknownFields:extensionRegistry:error: to add the data back to a message.")));
7779

7880
/**
7981
* Whether the message, along with all submessages, have the required fields
@@ -510,10 +512,11 @@ CF_EXTERN_C_END
510512
* If the intent is to *replace* the message's unknown fields, call `-clearUnknownFields` first.
511513
*
512514
* Since the data from the GPBUnknownFields will always be well formed, this call will almost never
513-
* fail. What could cause it to fail is if the GPBUnknownFields contains a field values it is
514-
* and error for the message's schema - i.e.: if it contains a length delimited field where the
515+
* fail. What could cause it to fail is if the GPBUnknownFields contains a field value that is
516+
* an error for the message's schema - i.e.: if it contains a length delimited field where the
515517
* field number for the message is defined to be a _string_ field, however the length delimited
516-
* data provide is not a valid UTF8 string.
518+
* data provide is not a valid UTF8 string, or if the field is a _packed_ number field, but the
519+
* data provided is not a valid for that field.
517520
*
518521
* @param unknownFields The unknown fields to merge the data from.
519522
* @param extensionRegistry The extension registry to use to look up extensions, can be `nil`.

objectivec/GPBMessage.m

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ @interface GPBMessage () {
7979
// be protected with an @synchronized(self) block (that way the code also doesn't have to
8080
// worry about throws).
8181
NSMutableData *unknownFieldData_;
82+
#pragma clang diagnostic push
83+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
8284
GPBUnknownFieldSet *unknownFields_;
85+
#pragma clang diagnostic pop
8386

8487
NSMutableDictionary *extensionMap_;
8588
// Readonly access to autocreatedExtensionMap_ is protected via readOnlyLock_.
@@ -1106,6 +1109,8 @@ void GPBClearMessageAutocreator(GPBMessage *self) {
11061109
self->autocreatorExtension_ = nil;
11071110
}
11081111

1112+
#pragma clang diagnostic push
1113+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
11091114
GPB_NOINLINE
11101115
static void MergeUnknownFieldDataIntoFieldSet(GPBMessage *self, NSData *data,
11111116
GPBUnknownFieldSet *targetSet) {
@@ -1151,6 +1156,7 @@ static void MergeUnknownFieldDataIntoFieldSet(GPBMessage *self, NSData *data,
11511156
[decodeInto release];
11521157
}
11531158
}
1159+
#pragma clang diagnostic pop
11541160

11551161
@implementation GPBMessage
11561162

@@ -1481,7 +1487,14 @@ - (void)internalClear:(BOOL)zeroStorage {
14811487
}
14821488

14831489
- (void)clearUnknownFields {
1484-
self.unknownFields = nil;
1490+
[unknownFieldData_ release];
1491+
unknownFieldData_ = nil;
1492+
#pragma clang diagnostic push
1493+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
1494+
[unknownFields_ release];
1495+
unknownFields_ = nil;
1496+
#pragma clang diagnostic pop
1497+
GPBBecomeVisibleToAutocreator(self);
14851498
}
14861499

14871500
- (BOOL)mergeUnknownFields:(GPBUnknownFields *)unknownFields
@@ -3149,6 +3162,8 @@ - (BOOL)isEqual:(id)other {
31493162
// need to guard against is concurrent r/o access, so we can grab the values (and retain them)
31503163
// so we have a version to compare against safely incase the second access causes the transform
31513164
// between internal states.
3165+
#pragma clang diagnostic push
3166+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
31523167
GPBUnknownFieldSet *selfUnknownFields;
31533168
NSData *selfUnknownFieldData;
31543169
@synchronized(self) {
@@ -3161,6 +3176,7 @@ - (BOOL)isEqual:(id)other {
31613176
otherUnknownFields = [otherMsg->unknownFields_ retain];
31623177
otherUnknownFieldData = [otherMsg->unknownFieldData_ retain];
31633178
}
3179+
#pragma clang diagnostic pop
31643180
#if defined(DEBUG) && DEBUG && !defined(NS_BLOCK_ASSERTIONS)
31653181
if (selfUnknownFields) {
31663182
NSAssert(selfUnknownFieldData == nil, @"Internal error both unknown states were set");
@@ -3189,6 +3205,8 @@ - (BOOL)isEqual:(id)other {
31893205
result = [selfUnknownFields isEqual:otherUnknownFields];
31903206
} else {
31913207
// At this point, we're done to one have a set/nothing, and the other having data/nothing.
3208+
#pragma clang diagnostic push
3209+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
31923210
GPBUnknownFieldSet *theSet = selfUnknownFields ? selfUnknownFields : otherUnknownFields;
31933211
NSData *theData = selfUnknownFieldData ? selfUnknownFieldData : otherUnknownFieldData;
31943212
if (theSet) {
@@ -3204,6 +3222,7 @@ - (BOOL)isEqual:(id)other {
32043222
// It was a data/nothing and nothing, so they equal if the other didn't have data.
32053223
result = theData == nil;
32063224
}
3225+
#pragma clang diagnostic pop
32073226
}
32083227

32093228
[selfUnknownFields release];
@@ -4015,7 +4034,10 @@ id GPBGetObjectIvarWithField(GPBMessage *self, GPBFieldDescriptor *field) {
40154034
NSData *GPBMessageUnknownFieldsData(GPBMessage *self) {
40164035
NSData *result = nil;
40174036
@synchronized(self) {
4037+
#pragma clang diagnostic push
4038+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
40184039
GPBUnknownFieldSet *unknownFields = self->unknownFields_;
4040+
#pragma clang diagnostic pop
40194041
if (unknownFields) {
40204042
#if defined(DEBUG) && DEBUG
40214043
NSCAssert(self->unknownFieldData_ == nil, @"Internal error both unknown states were set");

0 commit comments

Comments
 (0)