Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1041)

Unified Diff: third_party/protobuf/objectivec/GPBMessage.m

Issue 2600753002: Reverts third_party/protobuf: Update to HEAD (f52e188fe4) (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/protobuf/objectivec/GPBMessage.m
diff --git a/third_party/protobuf/objectivec/GPBMessage.m b/third_party/protobuf/objectivec/GPBMessage.m
index 4a6f0612acb95b39d0591d6d95827e1046ef05e8..8134e25962dcb28c3b7b5258142ec251c078489f 100644
--- a/third_party/protobuf/objectivec/GPBMessage.m
+++ b/third_party/protobuf/objectivec/GPBMessage.m
@@ -44,16 +44,13 @@
#import "GPBUnknownFieldSet_PackagePrivate.h"
#import "GPBUtilities_PackagePrivate.h"
-// Direct access is use for speed, to avoid even internally declaring things
-// read/write, etc. The warning is enabled in the project to ensure code calling
-// protos can turn on -Wdirect-ivar-access without issues.
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdirect-ivar-access"
-
NSString *const GPBMessageErrorDomain =
GPBNSStringifySymbol(GPBMessageErrorDomain);
-NSString *const GPBErrorReasonKey = @"Reason";
+#ifdef DEBUG
+NSString *const GPBExceptionMessageKey =
+ GPBNSStringifySymbol(GPBExceptionMessage);
+#endif // DEBUG
static NSString *const kGPBDataCoderKey = @"GPBData";
@@ -98,36 +95,21 @@ static NSMutableDictionary *CloneExtensionMap(NSDictionary *extensionMap,
NSZone *zone)
__attribute__((ns_returns_retained));
-#ifdef DEBUG
static NSError *MessageError(NSInteger code, NSDictionary *userInfo) {
return [NSError errorWithDomain:GPBMessageErrorDomain
code:code
userInfo:userInfo];
}
-#endif
-static NSError *ErrorFromException(NSException *exception) {
- NSError *error = nil;
-
- if ([exception.name isEqual:GPBCodedInputStreamException]) {
- NSDictionary *exceptionInfo = exception.userInfo;
- error = exceptionInfo[GPBCodedInputStreamUnderlyingErrorKey];
+static NSError *MessageErrorWithReason(NSInteger code, NSString *reason) {
+ NSDictionary *userInfo = nil;
+ if ([reason length]) {
+ userInfo = @{ @"Reason" : reason };
}
-
- if (!error) {
- NSString *reason = exception.reason;
- NSDictionary *userInfo = nil;
- if ([reason length]) {
- userInfo = @{ GPBErrorReasonKey : reason };
- }
-
- error = [NSError errorWithDomain:GPBMessageErrorDomain
- code:GPBMessageErrorCodeOther
- userInfo:userInfo];
- }
- return error;
+ return MessageError(code, userInfo);
}
+
static void CheckExtension(GPBMessage *self,
GPBExtensionDescriptor *extension) {
if ([self class] != extension.containingMessageClass) {
@@ -712,7 +694,7 @@ void GPBClearMessageAutocreator(GPBMessage *self) {
return;
}
-#if defined(DEBUG) && DEBUG && !defined(NS_BLOCK_ASSERTIONS)
+#if DEBUG && !defined(NS_BLOCK_ASSERTIONS)
// Either the autocreator must have its "has" flag set to YES, or it must be
// NO and not equal to ourselves.
BOOL autocreatorHas =
@@ -834,7 +816,8 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
[self release];
self = nil;
if (errorPtr) {
- *errorPtr = ErrorFromException(exception);
+ *errorPtr = MessageErrorWithReason(GPBMessageErrorCodeMalformedData,
+ exception.reason);
}
}
#ifdef DEBUG
@@ -865,7 +848,8 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
[self release];
self = nil;
if (errorPtr) {
- *errorPtr = ErrorFromException(exception);
+ *errorPtr = MessageErrorWithReason(GPBMessageErrorCodeMalformedData,
+ exception.reason);
}
}
#ifdef DEBUG
@@ -1752,7 +1736,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
}
- (BOOL)hasExtension:(GPBExtensionDescriptor *)extension {
-#if defined(DEBUG) && DEBUG
+#if DEBUG
CheckExtension(self, extension);
#endif // DEBUG
return nil != [extensionMap_ objectForKey:extension];
@@ -1777,6 +1761,11 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
}
}
+- (NSArray *)sortedExtensionsInUse {
+ return [[extensionMap_ allKeys]
+ sortedArrayUsingSelector:@selector(compareByFieldNumber:)];
+}
+
- (void)setExtension:(GPBExtensionDescriptor *)extension value:(id)value {
if (!value) {
[self clearExtension:extension];
@@ -1933,7 +1922,8 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
@catch (NSException *exception) {
message = nil;
if (errorPtr) {
- *errorPtr = ErrorFromException(exception);
+ *errorPtr = MessageErrorWithReason(GPBMessageErrorCodeMalformedData,
+ exception.reason);
}
}
#ifdef DEBUG
@@ -2274,9 +2264,6 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
while (YES) {
BOOL merged = NO;
tag = GPBCodedInputStreamReadTag(state);
- if (tag == 0) {
- break; // Reached end.
- }
for (NSUInteger i = 0; i < numFields; ++i) {
if (startingIndex >= numFields) startingIndex = 0;
GPBFieldDescriptor *fieldDescriptor = fields[startingIndex];
@@ -2315,7 +2302,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
}
} // for(i < numFields)
- if (!merged && (tag != 0)) {
+ if (!merged) {
// Primitive, repeated types can be packed on unpacked on the wire, and
// are parsed either way. The above loop covered tag in the preferred
// for, so this need to check the alternate form.
@@ -2570,7 +2557,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
#pragma mark - isEqual: & hash Support
-- (BOOL)isEqual:(id)other {
+- (BOOL)isEqual:(GPBMessage *)other {
if (other == self) {
return YES;
}
@@ -2579,10 +2566,9 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
return NO;
}
- GPBMessage *otherMsg = other;
GPBDescriptor *descriptor = [[self class] descriptor];
uint8_t *selfStorage = (uint8_t *)messageStorage_;
- uint8_t *otherStorage = (uint8_t *)otherMsg->messageStorage_;
+ uint8_t *otherStorage = (uint8_t *)other->messageStorage_;
for (GPBFieldDescriptor *field in descriptor->fields_) {
if (GPBFieldIsMapOrArray(field)) {
@@ -2635,7 +2621,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
case GPBDataTypeFixed32:
case GPBDataTypeUInt32:
case GPBDataTypeFloat: {
- GPBInternalCompileAssert(sizeof(float) == sizeof(uint32_t), float_not_32_bits);
+ _GPBCompileAssert(sizeof(float) == sizeof(uint32_t), float_not_32_bits);
// These are all 32bit, signed/unsigned doesn't matter for equality.
uint32_t *selfValPtr = (uint32_t *)&selfStorage[fieldOffset];
uint32_t *otherValPtr = (uint32_t *)&otherStorage[fieldOffset];
@@ -2650,7 +2636,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
case GPBDataTypeFixed64:
case GPBDataTypeUInt64:
case GPBDataTypeDouble: {
- GPBInternalCompileAssert(sizeof(double) == sizeof(uint64_t), double_not_64_bits);
+ _GPBCompileAssert(sizeof(double) == sizeof(uint64_t), double_not_64_bits);
// These are all 64bit, signed/unsigned doesn't matter for equality.
uint64_t *selfValPtr = (uint64_t *)&selfStorage[fieldOffset];
uint64_t *otherValPtr = (uint64_t *)&otherStorage[fieldOffset];
@@ -2676,14 +2662,14 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
} // for(fields)
// nil and empty are equal
- if (extensionMap_.count != 0 || otherMsg->extensionMap_.count != 0) {
- if (![extensionMap_ isEqual:otherMsg->extensionMap_]) {
+ if (extensionMap_.count != 0 || other->extensionMap_.count != 0) {
+ if (![extensionMap_ isEqual:other->extensionMap_]) {
return NO;
}
}
// nil and empty are equal
- GPBUnknownFieldSet *otherUnknowns = otherMsg->unknownFields_;
+ GPBUnknownFieldSet *otherUnknowns = other->unknownFields_;
if ([unknownFields_ countOfFields] != 0 ||
[otherUnknowns countOfFields] != 0) {
if (![unknownFields_ isEqual:otherUnknowns]) {
@@ -2747,7 +2733,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
case GPBDataTypeFixed32:
case GPBDataTypeUInt32:
case GPBDataTypeFloat: {
- GPBInternalCompileAssert(sizeof(float) == sizeof(uint32_t), float_not_32_bits);
+ _GPBCompileAssert(sizeof(float) == sizeof(uint32_t), float_not_32_bits);
// These are all 32bit, just mix it in.
uint32_t *valPtr = (uint32_t *)&storage[fieldOffset];
result = prime * result + *valPtr;
@@ -2759,7 +2745,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
case GPBDataTypeFixed64:
case GPBDataTypeUInt64:
case GPBDataTypeDouble: {
- GPBInternalCompileAssert(sizeof(double) == sizeof(uint64_t), double_not_64_bits);
+ _GPBCompileAssert(sizeof(double) == sizeof(uint64_t), double_not_64_bits);
// These are all 64bit, just mix what fits into an NSUInteger in.
uint64_t *valPtr = (uint64_t *)&storage[fieldOffset];
result = prime * result + (NSUInteger)(*valPtr);
@@ -2806,7 +2792,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
return description;
}
-#if defined(DEBUG) && DEBUG
+#if DEBUG
// Xcode 5.1 added support for custom quick look info.
// https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/CustomClassDisplay_in_QuickLook/CH01-quick_look_for_custom_objects/CH01-quick_look_for_custom_objects.html#//apple_ref/doc/uid/TP40014001-CH2-SW1
@@ -3196,35 +3182,3 @@ static void ResolveIvarSet(GPBFieldDescriptor *field,
}
@end
-
-#pragma mark - Messages from GPBUtilities.h but defined here for access to helpers.
-
-// Only exists for public api, no core code should use this.
-id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field) {
-#if defined(DEBUG) && DEBUG
- if (field.fieldType != GPBFieldTypeRepeated) {
- [NSException raise:NSInvalidArgumentException
- format:@"%@.%@ is not a repeated field.",
- [self class], field.name];
- }
-#endif
- GPBDescriptor *descriptor = [[self class] descriptor];
- GPBFileSyntax syntax = descriptor.file.syntax;
- return GetOrCreateArrayIvarWithField(self, field, syntax);
-}
-
-// Only exists for public api, no core code should use this.
-id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field) {
-#if defined(DEBUG) && DEBUG
- if (field.fieldType != GPBFieldTypeMap) {
- [NSException raise:NSInvalidArgumentException
- format:@"%@.%@ is not a map<> field.",
- [self class], field.name];
- }
-#endif
- GPBDescriptor *descriptor = [[self class] descriptor];
- GPBFileSyntax syntax = descriptor.file.syntax;
- return GetOrCreateMapIvarWithField(self, field, syntax);
-}
-
-#pragma clang diagnostic pop
« no previous file with comments | « third_party/protobuf/objectivec/GPBMessage.h ('k') | third_party/protobuf/objectivec/GPBMessage_PackagePrivate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698