Explorar el Código

Add -Woverriding-method-mismatch.

Fixes up the code to avoid some issues with isEqual: methods.

Opened https://github.com/google/protobuf/issues/1616 to track the KVC
collision.
Thomas Van Lenten hace 9 años
padre
commit
38b9e74691

+ 36 - 27
objectivec/GPBArray.m

@@ -164,15 +164,16 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) {
 //%  [super dealloc];
 //%}
 //%
-//%- (BOOL)isEqual:(GPB##NAME##Array *)other {
+//%- (BOOL)isEqual:(id)other {
 //%  if (self == other) {
 //%    return YES;
 //%  }
 //%  if (![other isKindOfClass:[GPB##NAME##Array class]]) {
 //%    return NO;
 //%  }
-//%  return (_count == other->_count
-//%          && memcmp(_values, other->_values, (_count * sizeof(TYPE))) == 0);
+//%  GPB##NAME##Array *otherArray = other;
+//%  return (_count == otherArray->_count
+//%          && memcmp(_values, otherArray->_values, (_count * sizeof(TYPE))) == 0);
 //%}
 //%
 //%- (NSUInteger)hash {
@@ -374,15 +375,16 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) {
   [super dealloc];
 }
 
-- (BOOL)isEqual:(GPBInt32Array *)other {
+- (BOOL)isEqual:(id)other {
   if (self == other) {
     return YES;
   }
   if (![other isKindOfClass:[GPBInt32Array class]]) {
     return NO;
   }
-  return (_count == other->_count
-          && memcmp(_values, other->_values, (_count * sizeof(int32_t))) == 0);
+  GPBInt32Array *otherArray = other;
+  return (_count == otherArray->_count
+          && memcmp(_values, otherArray->_values, (_count * sizeof(int32_t))) == 0);
 }
 
 - (NSUInteger)hash {
@@ -621,15 +623,16 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) {
   [super dealloc];
 }
 
-- (BOOL)isEqual:(GPBUInt32Array *)other {
+- (BOOL)isEqual:(id)other {
   if (self == other) {
     return YES;
   }
   if (![other isKindOfClass:[GPBUInt32Array class]]) {
     return NO;
   }
-  return (_count == other->_count
-          && memcmp(_values, other->_values, (_count * sizeof(uint32_t))) == 0);
+  GPBUInt32Array *otherArray = other;
+  return (_count == otherArray->_count
+          && memcmp(_values, otherArray->_values, (_count * sizeof(uint32_t))) == 0);
 }
 
 - (NSUInteger)hash {
@@ -868,15 +871,16 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) {
   [super dealloc];
 }
 
-- (BOOL)isEqual:(GPBInt64Array *)other {
+- (BOOL)isEqual:(id)other {
   if (self == other) {
     return YES;
   }
   if (![other isKindOfClass:[GPBInt64Array class]]) {
     return NO;
   }
-  return (_count == other->_count
-          && memcmp(_values, other->_values, (_count * sizeof(int64_t))) == 0);
+  GPBInt64Array *otherArray = other;
+  return (_count == otherArray->_count
+          && memcmp(_values, otherArray->_values, (_count * sizeof(int64_t))) == 0);
 }
 
 - (NSUInteger)hash {
@@ -1115,15 +1119,16 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) {
   [super dealloc];
 }
 
-- (BOOL)isEqual:(GPBUInt64Array *)other {
+- (BOOL)isEqual:(id)other {
   if (self == other) {
     return YES;
   }
   if (![other isKindOfClass:[GPBUInt64Array class]]) {
     return NO;
   }
-  return (_count == other->_count
-          && memcmp(_values, other->_values, (_count * sizeof(uint64_t))) == 0);
+  GPBUInt64Array *otherArray = other;
+  return (_count == otherArray->_count
+          && memcmp(_values, otherArray->_values, (_count * sizeof(uint64_t))) == 0);
 }
 
 - (NSUInteger)hash {
@@ -1362,15 +1367,16 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) {
   [super dealloc];
 }
 
-- (BOOL)isEqual:(GPBFloatArray *)other {
+- (BOOL)isEqual:(id)other {
   if (self == other) {
     return YES;
   }
   if (![other isKindOfClass:[GPBFloatArray class]]) {
     return NO;
   }
-  return (_count == other->_count
-          && memcmp(_values, other->_values, (_count * sizeof(float))) == 0);
+  GPBFloatArray *otherArray = other;
+  return (_count == otherArray->_count
+          && memcmp(_values, otherArray->_values, (_count * sizeof(float))) == 0);
 }
 
 - (NSUInteger)hash {
@@ -1609,15 +1615,16 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) {
   [super dealloc];
 }
 
-- (BOOL)isEqual:(GPBDoubleArray *)other {
+- (BOOL)isEqual:(id)other {
   if (self == other) {
     return YES;
   }
   if (![other isKindOfClass:[GPBDoubleArray class]]) {
     return NO;
   }
-  return (_count == other->_count
-          && memcmp(_values, other->_values, (_count * sizeof(double))) == 0);
+  GPBDoubleArray *otherArray = other;
+  return (_count == otherArray->_count
+          && memcmp(_values, otherArray->_values, (_count * sizeof(double))) == 0);
 }
 
 - (NSUInteger)hash {
@@ -1856,15 +1863,16 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) {
   [super dealloc];
 }
 
-- (BOOL)isEqual:(GPBBoolArray *)other {
+- (BOOL)isEqual:(id)other {
   if (self == other) {
     return YES;
   }
   if (![other isKindOfClass:[GPBBoolArray class]]) {
     return NO;
   }
-  return (_count == other->_count
-          && memcmp(_values, other->_values, (_count * sizeof(BOOL))) == 0);
+  GPBBoolArray *otherArray = other;
+  return (_count == otherArray->_count
+          && memcmp(_values, otherArray->_values, (_count * sizeof(BOOL))) == 0);
 }
 
 - (NSUInteger)hash {
@@ -2127,15 +2135,16 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) {
   [super dealloc];
 }
 
-- (BOOL)isEqual:(GPBEnumArray *)other {
+- (BOOL)isEqual:(id)other {
   if (self == other) {
     return YES;
   }
   if (![other isKindOfClass:[GPBEnumArray class]]) {
     return NO;
   }
-  return (_count == other->_count
-          && memcmp(_values, other->_values, (_count * sizeof(int32_t))) == 0);
+  GPBEnumArray *otherArray = other;
+  return (_count == otherArray->_count
+          && memcmp(_values, otherArray->_values, (_count * sizeof(int32_t))) == 0);
 }
 
 - (NSUInteger)hash {

+ 8 - 0
objectivec/GPBDictionary.h

@@ -39,6 +39,12 @@
 
 NS_ASSUME_NONNULL_BEGIN
 
+// Disable -Woverriding-method-mismatch until resolving the accidental conflict
+// with NSObject's KVC category.
+// https://github.com/google/protobuf/issues/1616 opened to resolve this.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Woverriding-method-mismatch"
+
 //%PDDM-EXPAND DECLARE_DICTIONARIES()
 // This block of code is generated, do not edit it directly.
 
@@ -2085,6 +2091,8 @@ NS_ASSUME_NONNULL_BEGIN
 
 //%PDDM-EXPAND-END DECLARE_DICTIONARIES()
 
+#pragma clang diagnostic pop
+
 NS_ASSUME_NONNULL_END
 
 //%PDDM-DEFINE DECLARE_DICTIONARIES()

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 183 - 130
objectivec/GPBDictionary.m


+ 6 - 5
objectivec/GPBMessage.m

@@ -2563,7 +2563,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
 
 #pragma mark - isEqual: & hash Support
 
-- (BOOL)isEqual:(GPBMessage *)other {
+- (BOOL)isEqual:(id)other {
   if (other == self) {
     return YES;
   }
@@ -2572,9 +2572,10 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
     return NO;
   }
 
+  GPBMessage *otherMsg = other;
   GPBDescriptor *descriptor = [[self class] descriptor];
   uint8_t *selfStorage = (uint8_t *)messageStorage_;
-  uint8_t *otherStorage = (uint8_t *)other->messageStorage_;
+  uint8_t *otherStorage = (uint8_t *)otherMsg->messageStorage_;
 
   for (GPBFieldDescriptor *field in descriptor->fields_) {
     if (GPBFieldIsMapOrArray(field)) {
@@ -2668,14 +2669,14 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
   }  // for(fields)
 
   // nil and empty are equal
-  if (extensionMap_.count != 0 || other->extensionMap_.count != 0) {
-    if (![extensionMap_ isEqual:other->extensionMap_]) {
+  if (extensionMap_.count != 0 || otherMsg->extensionMap_.count != 0) {
+    if (![extensionMap_ isEqual:otherMsg->extensionMap_]) {
       return NO;
     }
   }
 
   // nil and empty are equal
-  GPBUnknownFieldSet *otherUnknowns = other->unknownFields_;
+  GPBUnknownFieldSet *otherUnknowns = otherMsg->unknownFields_;
   if ([unknownFields_ countOfFields] != 0 ||
       [otherUnknowns countOfFields] != 0) {
     if (![unknownFields_ isEqual:otherUnknowns]) {

+ 2 - 0
objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj

@@ -836,6 +836,7 @@
 					"-Wreserved-id-macro",
 					"-Wswitch-enum",
 					"-Wdirect-ivar-access",
+					"-Woverriding-method-mismatch",
 				);
 			};
 			name = Debug;
@@ -892,6 +893,7 @@
 					"-Wreserved-id-macro",
 					"-Wswitch-enum",
 					"-Wdirect-ivar-access",
+					"-Woverriding-method-mismatch",
 				);
 			};
 			name = Release;

+ 2 - 0
objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj

@@ -999,6 +999,7 @@
 					"-Wreserved-id-macro",
 					"-Wswitch-enum",
 					"-Wdirect-ivar-access",
+					"-Woverriding-method-mismatch",
 				);
 			};
 			name = Debug;
@@ -1056,6 +1057,7 @@
 					"-Wreserved-id-macro",
 					"-Wswitch-enum",
 					"-Wdirect-ivar-access",
+					"-Woverriding-method-mismatch",
 				);
 			};
 			name = Release;

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio