Skip to content

Commit

Permalink
Enforce GPBFieldHasEnumDescriptor always being set.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Nov 14, 2022
1 parent 38fb108 commit 7140f6f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 28 deletions.
30 changes: 6 additions & 24 deletions objectivec/GPBDescriptor.m
Original file line number Diff line number Diff line change
Expand Up @@ -443,16 +443,12 @@ @implementation GPBFieldDescriptor {
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
Expand Down Expand Up @@ -518,11 +514,9 @@ - (instancetype)initWithFieldDescription:(void *)description
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.
Expand Down Expand Up @@ -626,19 +620,7 @@ - (BOOL)isPackable {

- (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 {
Expand Down
6 changes: 2 additions & 4 deletions objectivec/GPBDescriptor_PackagePrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7140f6f

Please sign in to comment.