mirror of
https://github.com/protocolbuffers/protobuf
synced 2026-08-26 02:23:14 -04:00
[ObjC] Retire GPBRuntimeMatchFailure()
Make it an assert at runtime instead since it is just a sanity check. PiperOrigin-RevId: 729565587
This commit is contained in:
parent
58fc18e6b4
commit
1f21b164b1
3 changed files with 12 additions and 33 deletions
|
|
@ -104,16 +104,14 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageField
|
|||
format:@"Proto generation source appears to have been from a version newer than "
|
||||
@"this runtime."];
|
||||
}
|
||||
#if defined(DEBUG) && DEBUG
|
||||
#if defined(DEBUG) && DEBUG && !defined(NS_BLOCK_ASSERTIONS)
|
||||
// Compute the unknown options by this version of the runtime and then check the passed in
|
||||
// descriptor's options (from the generated code). If this does fire either something was
|
||||
// added incorrectly to the runtime or some sorta corruption has happened.
|
||||
GPBDescriptorInitializationFlags unknownFlags =
|
||||
(GPBDescriptorInitializationFlags)(~(GPBDescriptorInitializationFlag_FieldsWithDefault |
|
||||
GPBDescriptorInitializationFlag_WireFormat));
|
||||
if ((flags & unknownFlags) != 0) {
|
||||
GPBRuntimeMatchFailure();
|
||||
}
|
||||
NSAssert((flags & unknownFlags) == 0, @"Internal error: unknown descriptor flags set");
|
||||
GPBFieldFlags mergedFieldFlags = GPBFieldNone;
|
||||
#endif // defined(DEBUG) && DEBUG
|
||||
|
||||
|
|
@ -126,13 +124,13 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageField
|
|||
// Need correctly typed pointer for array indexing below to work.
|
||||
if (fieldsIncludeDefault) {
|
||||
desc = &(((GPBMessageFieldDescriptionWithDefault *)fieldDescriptions)[i]);
|
||||
#if defined(DEBUG) && DEBUG
|
||||
#if defined(DEBUG) && DEBUG && !defined(NS_BLOCK_ASSERTIONS)
|
||||
mergedFieldFlags |=
|
||||
(((GPBMessageFieldDescriptionWithDefault *)fieldDescriptions)[i]).core.flags;
|
||||
#endif
|
||||
} else {
|
||||
desc = &(((GPBMessageFieldDescription *)fieldDescriptions)[i]);
|
||||
#if defined(DEBUG) && DEBUG
|
||||
#if defined(DEBUG) && DEBUG && !defined(NS_BLOCK_ASSERTIONS)
|
||||
mergedFieldFlags |= (((GPBMessageFieldDescription *)fieldDescriptions)[i]).flags;
|
||||
#endif
|
||||
}
|
||||
|
|
@ -141,16 +139,14 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageField
|
|||
[fields addObject:fieldDescriptor];
|
||||
[fieldDescriptor release];
|
||||
}
|
||||
#if defined(DEBUG) && DEBUG
|
||||
#if defined(DEBUG) && DEBUG && !defined(NS_BLOCK_ASSERTIONS)
|
||||
// No real value in checking all the fields individually, just check the combined flags at the
|
||||
// end.
|
||||
GPBFieldFlags unknownFieldFlags =
|
||||
(GPBFieldFlags)(~(GPBFieldRequired | GPBFieldRepeated | GPBFieldPacked | GPBFieldOptional |
|
||||
GPBFieldHasDefaultValue | GPBFieldClearHasIvarOnZero |
|
||||
GPBFieldTextFormatNameCustom | GPBFieldMapKeyMask));
|
||||
if ((mergedFieldFlags & unknownFieldFlags) != 0) {
|
||||
GPBRuntimeMatchFailure();
|
||||
}
|
||||
NSAssert((mergedFieldFlags & unknownFieldFlags) == 0, @"Internal error: unknown field flags set");
|
||||
#endif // defined(DEBUG) && DEBUG
|
||||
|
||||
BOOL wireFormat = (flags & GPBDescriptorInitializationFlag_WireFormat) != 0;
|
||||
|
|
@ -787,16 +783,14 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) {
|
|||
format:@"Proto generation source appears to have been from a version newer than "
|
||||
@"this runtime."];
|
||||
}
|
||||
#if defined(DEBUG) && DEBUG
|
||||
#if defined(DEBUG) && DEBUG && !defined(NS_BLOCK_ASSERTIONS)
|
||||
// Compute the unknown options by this version of the runtime and then check the passed in
|
||||
// descriptor's options (from the generated code). If this does fire either something was
|
||||
// added incorrectly to the runtime or some sorta corruption has happened.
|
||||
GPBEnumDescriptorInitializationFlags unknownFlags =
|
||||
(GPBEnumDescriptorInitializationFlags)(~(GPBEnumDescriptorInitializationFlag_IsClosed));
|
||||
if ((flags & unknownFlags) != 0) {
|
||||
GPBRuntimeMatchFailure();
|
||||
}
|
||||
#endif // defined(DEBUG) && DEBUG
|
||||
NSAssert((flags & unknownFlags) == 0, @"Internal error: unknown enum flags set");
|
||||
#endif // defined(DEBUG) && DEBUG && !defined(NS_BLOCK_ASSERTIONS)
|
||||
GPBEnumDescriptor *descriptor = [[self alloc] initWithName:name
|
||||
valueNames:valueNames
|
||||
values:values
|
||||
|
|
@ -1054,16 +1048,14 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) {
|
|||
format:@"Proto generation source appears to have been from a version newer than "
|
||||
@"this runtime."];
|
||||
}
|
||||
#if defined(DEBUG) && DEBUG
|
||||
#if defined(DEBUG) && DEBUG && !defined(NS_BLOCK_ASSERTIONS)
|
||||
// Compute the unknown options by this version of the runtime and then check the passed in
|
||||
// descriptor's options (from the generated code). If this does fire either something was
|
||||
// added incorrectly to the runtime or some sorta corruption has happened.
|
||||
GPBExtensionOptions unknownOptions =
|
||||
(GPBExtensionOptions)(~(GPBExtensionRepeated | GPBExtensionPacked));
|
||||
if ((desc->options & unknownOptions) != 0) {
|
||||
GPBRuntimeMatchFailure();
|
||||
}
|
||||
#endif // defined(DEBUG) && DEBUG
|
||||
NSAssert((desc->options & unknownOptions) == 0, @"Internal error: unknown extension flags set");
|
||||
#endif // defined(DEBUG) && DEBUG && !defined(NS_BLOCK_ASSERTIONS)
|
||||
if ((self = [super init])) {
|
||||
description_ = desc;
|
||||
|
||||
|
|
|
|||
|
|
@ -223,13 +223,6 @@ void GPBCheckRuntimeVersionSupport(int32_t objcRuntimeVersion) {
|
|||
|
||||
#endif // GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION > 30007
|
||||
|
||||
void GPBRuntimeMatchFailure(void) {
|
||||
[NSException raise:NSInternalInconsistencyException
|
||||
format:@"Proto generation source appears to have been from a"
|
||||
@" version newer that this runtime (%d).",
|
||||
GOOGLE_PROTOBUF_OBJC_VERSION];
|
||||
}
|
||||
|
||||
BOOL GPBMessageHasFieldNumberSet(GPBMessage *self, uint32_t fieldNumber) {
|
||||
GPBDescriptor *descriptor = [self descriptor];
|
||||
GPBFieldDescriptor *field = [descriptor fieldWithNumber:fieldNumber];
|
||||
|
|
|
|||
|
|
@ -49,12 +49,6 @@ GPB_INLINE void GPB_DEBUG_CHECK_RUNTIME_VERSIONS(void) {
|
|||
#endif
|
||||
}
|
||||
|
||||
// Helper called within the library when the runtime detects something that
|
||||
// indicates a older runtime is being used with newer generated code. Normally
|
||||
// GPB_DEBUG_CHECK_RUNTIME_VERSIONS() gates this with a better message; this
|
||||
// is just a final safety net to prevent otherwise hard to diagnose errors.
|
||||
void GPBRuntimeMatchFailure(void);
|
||||
|
||||
// Conversion functions for de/serializing floating point types.
|
||||
|
||||
GPB_INLINE int64_t GPBConvertDoubleToInt64(double v) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue