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

@ -52,7 +52,7 @@ typedef NS_OPTIONS(uint16_t, GPBFieldFlags) {
// Indicates the field needs custom handling for the TextFormat name, if not
// set, the name can be derived from the ObjC name.
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,
// 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.
char *className; // Name of the class of the message.
Class clazz; // Class of the message.
// For enums only: If EnumDescriptors are compiled in, it will be that,
// otherwise it will be the verifier.
// For enums only.
GPBEnumDescriptorFunc enumDescFunc;
GPBEnumValidationFunc enumVerifier;
} dataTypeSpecific;
// The field number for the ivar.
uint32_t number;

Loading…
Cancel
Save