From 7140f6f1e1f8926ce4ba8ea67227fbd0e40a73f4 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 14 Nov 2022 09:04:23 -0800 Subject: [PATCH] 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 --- objectivec/GPBDescriptor.m | 30 +++++------------------ objectivec/GPBDescriptor_PackagePrivate.h | 6 ++--- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/objectivec/GPBDescriptor.m b/objectivec/GPBDescriptor.m index bdfd1dfeef..1b75f8e742 100644 --- a/objectivec/GPBDescriptor.m +++ b/objectivec/GPBDescriptor.m @@ -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 { diff --git a/objectivec/GPBDescriptor_PackagePrivate.h b/objectivec/GPBDescriptor_PackagePrivate.h index 4774d4e2cb..a286de6c07 100644 --- a/objectivec/GPBDescriptor_PackagePrivate.h +++ b/objectivec/GPBDescriptor_PackagePrivate.h @@ -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;