[ObjC] Make debug runtime tell developers to update their generated code.

Migrate some internals of the library off the older apis.

Also mark some of the old apis as deprecated, but the old generated code
suppressed warnings broadly to support protobuf deprecations.

PiperOrigin-RevId: 668003974
pull/17963/head
Thomas Van Lenten 7 months ago committed by Copybara-Service
parent 9d7379677a
commit cdd3cf7ed4
  1. 20
      objectivec/GPBDescriptor_PackagePrivate.h
  2. 23
      objectivec/GPBMessage.m
  3. 8
      objectivec/GPBUtilities.m
  4. 5
      objectivec/Tests/GPBMessageTests+ClassNames.m

@ -215,14 +215,18 @@ typedef NS_OPTIONS(uint32_t, GPBDescriptorInitializationFlags) {
fields:(void *)fieldDescriptions
fieldCount:(uint32_t)fieldCount
storageSize:(uint32_t)storageSize
flags:(GPBDescriptorInitializationFlags)flags;
flags:(GPBDescriptorInitializationFlags)flags
__attribute__((deprecated("Please use a newer version of protoc to regenerate your sources. "
"Support for this version will go away in the future.")));
+ (instancetype)allocDescriptorForClass:(Class)messageClass
rootClass:(Class)rootClass
file:(GPBFileDescriptor *)file
fields:(void *)fieldDescriptions
fieldCount:(uint32_t)fieldCount
storageSize:(uint32_t)storageSize
flags:(GPBDescriptorInitializationFlags)flags;
flags:(GPBDescriptorInitializationFlags)flags
__attribute__((deprecated("Please use a newer version of protoc to regenerate your sources. "
"Support for this version will go away in the future.")));
- (void)setupContainingMessageClassName:(const char *)msgClassName;
- (void)setupMessageClassNameSuffix:(NSString *)suffix;
@ -282,13 +286,17 @@ typedef NS_OPTIONS(uint32_t, GPBEnumDescriptorInitializationFlags) {
valueNames:(const char *)valueNames
values:(const int32_t *)values
count:(uint32_t)valueCount
enumVerifier:(GPBEnumValidationFunc)enumVerifier;
enumVerifier:(GPBEnumValidationFunc)enumVerifier
__attribute__((deprecated("Please use a newer version of protoc to regenerate your sources. "
"Support for this version will go away in the future.")));
+ (instancetype)allocDescriptorForName:(NSString *)name
valueNames:(const char *)valueNames
values:(const int32_t *)values
count:(uint32_t)valueCount
enumVerifier:(GPBEnumValidationFunc)enumVerifier
extraTextFormatInfo:(const char *)extraTextFormatInfo;
extraTextFormatInfo:(const char *)extraTextFormatInfo
__attribute__((deprecated("Please use a newer version of protoc to regenerate your sources. "
"Support for this version will go away in the future.")));
@end
@interface GPBExtensionDescriptor () {
@ -307,7 +315,9 @@ typedef NS_OPTIONS(uint32_t, GPBEnumDescriptorInitializationFlags) {
- (instancetype)initWithExtensionDescription:(GPBExtensionDescription *)desc
usesClassRefs:(BOOL)usesClassRefs;
// Deprecated. Calls above with `usesClassRefs = NO`
- (instancetype)initWithExtensionDescription:(GPBExtensionDescription *)desc;
- (instancetype)initWithExtensionDescription:(GPBExtensionDescription *)desc
__attribute__((deprecated("Please use a newer version of protoc to regenerate your sources. "
"Support for this version will go away in the future.")));
- (NSComparisonResult)compareByFieldNumber:(GPBExtensionDescriptor *)other;
@end

@ -1196,18 +1196,19 @@ static void MergeUnknownFieldDataIntoFieldSet(GPBMessage *self, NSData *data,
+ (GPBDescriptor *)descriptor {
// This is thread safe because it is called from +initialize.
static GPBDescriptor *descriptor = NULL;
static GPBFileDescriptor *fileDescriptor = NULL;
static GPBFileDescription fileDescription = {
.package = "internal", .prefix = "", .syntax = GPBFileSyntaxProto2};
if (!descriptor) {
fileDescriptor = [[GPBFileDescriptor alloc] initWithPackage:@"internal"
syntax:GPBFileSyntaxProto2];
descriptor = [GPBDescriptor allocDescriptorForClass:[GPBMessage class]
rootClass:Nil
file:fileDescriptor
fields:NULL
fieldCount:0
storageSize:0
flags:0];
descriptor = [GPBDescriptor
allocDescriptorForClass:[GPBMessage class]
messageName:@"GPBMessage"
fileDescription:&fileDescription
fields:NULL
fieldCount:0
storageSize:0
flags:(GPBDescriptorInitializationFlag_UsesClassRefs |
GPBDescriptorInitializationFlag_Proto3OptionalKnown |
GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
}
return descriptor;
}

@ -206,6 +206,14 @@ void GPBCheckRuntimeVersionSupport(int32_t objcRuntimeVersion) {
@" supports back to %d!",
objcRuntimeVersion, GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION];
}
#if defined(DEBUG) && DEBUG
if (objcRuntimeVersion < GOOGLE_PROTOBUF_OBJC_VERSION) {
// This is a version we haven't generated for yet.
NSLog(@"WARNING: Code from generated Objective-C proto from an older version of the library is "
@"being used. Please regenerate with the current version as the code will stop working "
@"in a future release.");
}
#endif
}
void GPBRuntimeMatchFailure(void) {

@ -14,6 +14,9 @@
#import "GPBMessage.h"
#import "GPBRootObject_PackagePrivate.h"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// Support classes for tests using old class name (vs classrefs) interfaces.
GPB_FINAL @interface MessageLackingClazzRoot : GPBRootObject
@end
@ -107,6 +110,8 @@ typedef struct MessageLackingClazz_storage_ {
}
@end
#pragma clang diagnostic pop
@interface MessageClassNameTests : GPBTestCase
@end

Loading…
Cancel
Save