Enforce GPBFieldHasEnumDescriptor always being set.

Going back to the first ObjC support commit, there never really was support for
not have the EnumDescriptors, so start removing that partial support.

PiperOrigin-RevId: 488381501
pull/10927/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent 38fb1080b4
commit 7140f6f1e1
  1. 30
      objectivec/GPBDescriptor.m
  2. 6
      objectivec/GPBDescriptor_PackagePrivate.h

@ -443,16 +443,12 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) {
Class msgClass_; Class msgClass_;
// Enum ivars. // Enum ivars.
// If protos are generated with GenerateEnumDescriptors on then it will GPBEnumDescriptor *enumDescriptor_;
// be a enumDescriptor, otherwise it will be a enumVerifier.
union {
GPBEnumDescriptor *enumDescriptor_;
GPBEnumValidationFunc enumVerifier_;
} enumHandling_;
} }
@synthesize msgClass = msgClass_; @synthesize msgClass = msgClass_;
@synthesize containingOneof = containingOneof_; @synthesize containingOneof = containingOneof_;
@synthesize enumDescriptor = enumDescriptor_;
- (instancetype)initWithFieldDescription:(void *)description - (instancetype)initWithFieldDescription:(void *)description
includesDefault:(BOOL)includesDefault includesDefault:(BOOL)includesDefault
@ -518,11 +514,9 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) {
NSAssert(msgClass_, @"Class %s not defined", className); NSAssert(msgClass_, @"Class %s not defined", className);
} }
} else if (dataType == GPBDataTypeEnum) { } else if (dataType == GPBDataTypeEnum) {
if ((coreDesc->flags & GPBFieldHasEnumDescriptor) != 0) { NSAssert((coreDesc->flags & GPBFieldHasEnumDescriptor) != 0,
enumHandling_.enumDescriptor_ = coreDesc->dataTypeSpecific.enumDescFunc(); @"Field must have GPBFieldHasEnumDescriptor set");
} else { enumDescriptor_ = coreDesc->dataTypeSpecific.enumDescFunc();
enumHandling_.enumVerifier_ = coreDesc->dataTypeSpecific.enumVerifier;
}
} }
// Non map<>/repeated fields can have defaults in proto2 syntax. // Non map<>/repeated fields can have defaults in proto2 syntax.
@ -626,19 +620,7 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) {
- (BOOL)isValidEnumValue:(int32_t)value { - (BOOL)isValidEnumValue:(int32_t)value {
NSAssert(description_->dataType == GPBDataTypeEnum, @"Field Must be of type GPBDataTypeEnum"); NSAssert(description_->dataType == GPBDataTypeEnum, @"Field Must be of type GPBDataTypeEnum");
if (description_->flags & GPBFieldHasEnumDescriptor) { return enumDescriptor_.enumVerifier(value);
return enumHandling_.enumDescriptor_.enumVerifier(value);
} else {
return enumHandling_.enumVerifier_(value);
}
}
- (GPBEnumDescriptor *)enumDescriptor {
if (description_->flags & GPBFieldHasEnumDescriptor) {
return enumHandling_.enumDescriptor_;
} else {
return nil;
}
} }
- (GPBGenericValue)defaultValue { - (GPBGenericValue)defaultValue {

@ -52,7 +52,7 @@ typedef NS_OPTIONS(uint16_t, GPBFieldFlags) {
// Indicates the field needs custom handling for the TextFormat name, if not // Indicates the field needs custom handling for the TextFormat name, if not
// set, the name can be derived from the ObjC name. // set, the name can be derived from the ObjC name.
GPBFieldTextFormatNameCustom = 1 << 6, GPBFieldTextFormatNameCustom = 1 << 6,
// Indicates the field has an enum descriptor. // This flag has never had any meaning, it was set on all enum fields.
GPBFieldHasEnumDescriptor = 1 << 7, GPBFieldHasEnumDescriptor = 1 << 7,
// These are not standard protobuf concepts, they are specific to the // These are not standard protobuf concepts, they are specific to the
@ -89,10 +89,8 @@ typedef struct GPBMessageFieldDescription {
// clazz is used iff GPBDescriptorInitializationFlag_UsesClassRefs is set. // clazz is used iff GPBDescriptorInitializationFlag_UsesClassRefs is set.
char *className; // Name of the class of the message. char *className; // Name of the class of the message.
Class clazz; // Class of the message. Class clazz; // Class of the message.
// For enums only: If EnumDescriptors are compiled in, it will be that, // For enums only.
// otherwise it will be the verifier.
GPBEnumDescriptorFunc enumDescFunc; GPBEnumDescriptorFunc enumDescFunc;
GPBEnumValidationFunc enumVerifier;
} dataTypeSpecific; } dataTypeSpecific;
// The field number for the ivar. // The field number for the ivar.
uint32_t number; uint32_t number;

Loading…
Cancel
Save