Skip to content

Commit

Permalink
[ObjC] Make debug runtime tell developers to update their generated c…
Browse files Browse the repository at this point in the history
…ode.

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
  • Loading branch information
thomasvl authored and copybara-github committed Aug 27, 2024
1 parent 9d73796 commit cdd3cf7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
20 changes: 15 additions & 5 deletions objectivec/GPBDescriptor_PackagePrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 () {
Expand All @@ -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
Expand Down
23 changes: 12 additions & 11 deletions objectivec/GPBMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -1196,18 +1196,19 @@ + (instancetype)alloc {
+ (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;
}
Expand Down
8 changes: 8 additions & 0 deletions objectivec/GPBUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions objectivec/Tests/GPBMessageTests+ClassNames.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -107,6 +110,8 @@ + (GPBExtensionRegistry *)extensionRegistry {
}
@end

#pragma clang diagnostic pop

@interface MessageClassNameTests : GPBTestCase
@end

Expand Down

0 comments on commit cdd3cf7

Please sign in to comment.