Skip to content

Commit cffa590

Browse files
thomasvlcopybara-github
authored andcommitted
[ObjC] Breaking Change: Remove support for older generated code.
Remove runtime methods that support the Objective-C gencode from before the 3.22.x release. PiperOrigin-RevId: 684462445
1 parent 09ac8ca commit cffa590

File tree

10 files changed

+5
-487
lines changed

10 files changed

+5
-487
lines changed

objectivec/GPBBootstrap.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,4 @@
118118

119119
// Minimum runtime version supported for compiling/running against.
120120
// - Gets changed when support for the older generated code is dropped.
121-
#define GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION 30001
122-
123-
// This is a legacy constant now frozen in time for old generated code. If
124-
// GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION ever gets moved above 30001 then
125-
// this should also change to break code compiled with an old runtime that
126-
// can't be supported any more.
127-
#define GOOGLE_PROTOBUF_OBJC_GEN_VERSION 30001
121+
#define GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION 30007

objectivec/GPBDescriptor.m

Lines changed: 4 additions & 237 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ - (instancetype)initWithName:(NSString *)name
5151
// The addresses of these variables are used as keys for objc_getAssociatedObject.
5252
static const char kTextFormatExtraValueKey = 0;
5353
static const char kParentClassValueKey = 0;
54-
static const char kClassNameSuffixKey = 0;
5554
static const char kFileDescriptorCacheKey = 0;
5655

5756
static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageFields)
@@ -156,114 +155,6 @@ + (instancetype)allocDescriptorForClass:(Class)messageClass
156155
return descriptor;
157156
}
158157

159-
+ (instancetype)allocDescriptorForClass:(Class)messageClass
160-
file:(GPBFileDescriptor *)file
161-
fields:(void *)fieldDescriptions
162-
fieldCount:(uint32_t)fieldCount
163-
storageSize:(uint32_t)storageSize
164-
flags:(GPBDescriptorInitializationFlags)flags {
165-
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30006,
166-
time_to_remove_this_old_version_shim);
167-
168-
BOOL fixClassRefs = (flags & GPBDescriptorInitializationFlag_UsesClassRefs) == 0;
169-
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30003,
170-
time_to_remove_non_class_ref_support);
171-
172-
BOOL fixProto3Optional = (flags & GPBDescriptorInitializationFlag_Proto3OptionalKnown) == 0;
173-
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30004,
174-
time_to_remove_proto3_optional_fallback);
175-
176-
BOOL fixClosedEnums = (flags & GPBDescriptorInitializationFlag_ClosedEnumSupportKnown) == 0;
177-
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30005,
178-
time_to_remove_closed_enum_fallback);
179-
180-
if (fixClassRefs || fixProto3Optional || fixClosedEnums) {
181-
BOOL fieldsIncludeDefault = (flags & GPBDescriptorInitializationFlag_FieldsWithDefault) != 0;
182-
#pragma clang diagnostic push
183-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
184-
GPBFileSyntax fileSyntax = file.syntax;
185-
#pragma clang diagnostic pop
186-
187-
for (uint32_t i = 0; i < fieldCount; ++i) {
188-
GPBMessageFieldDescription *coreDesc;
189-
if (fieldsIncludeDefault) {
190-
coreDesc = &((((GPBMessageFieldDescriptionWithDefault *)fieldDescriptions)[i]).core);
191-
} else {
192-
coreDesc = &(((GPBMessageFieldDescription *)fieldDescriptions)[i]);
193-
}
194-
195-
if (fixClassRefs && GPBDataTypeIsMessage(coreDesc->dataType)) {
196-
const char *className = coreDesc->dataTypeSpecific.className;
197-
Class msgClass = objc_getClass(className);
198-
NSAssert(msgClass, @"Class %s not defined", className);
199-
coreDesc->dataTypeSpecific.clazz = msgClass;
200-
}
201-
202-
if (fixProto3Optional) {
203-
// If it was...
204-
// - proto3 syntax
205-
// - not repeated/map
206-
// - not in a oneof (negative has index)
207-
// - not a message (the flag doesn't make sense for messages)
208-
BOOL clearOnZero = ((fileSyntax == GPBFileSyntaxProto3) &&
209-
((coreDesc->flags & (GPBFieldRepeated | GPBFieldMapKeyMask)) == 0) &&
210-
(coreDesc->hasIndex >= 0) && !GPBDataTypeIsMessage(coreDesc->dataType));
211-
if (clearOnZero) {
212-
coreDesc->flags |= GPBFieldClearHasIvarOnZero;
213-
}
214-
}
215-
216-
if (fixClosedEnums) {
217-
// NOTE: This isn't correct, it is using the syntax of the file that
218-
// declared the field, not the syntax of the file that declared the
219-
// enum; but for older generated code, that's all we have and that happens
220-
// to be what the runtime was doing (even though it was wrong). This is
221-
// only wrong in the rare cases an enum is declared in a proto3 syntax
222-
// file but used for a field in the proto2 syntax file.
223-
BOOL isClosedEnum =
224-
(coreDesc->dataType == GPBDataTypeEnum && fileSyntax == GPBFileSyntaxProto2);
225-
if (isClosedEnum) {
226-
coreDesc->flags |= GPBFieldClosedEnum;
227-
}
228-
}
229-
}
230-
flags |= (GPBDescriptorInitializationFlag_UsesClassRefs |
231-
GPBDescriptorInitializationFlag_Proto3OptionalKnown |
232-
GPBDescriptorInitializationFlag_ClosedEnumSupportKnown);
233-
}
234-
235-
GPBDescriptor *result = [self allocDescriptorForClass:messageClass
236-
messageName:nil
237-
fileDescription:NULL
238-
fields:fieldDescriptions
239-
fieldCount:fieldCount
240-
storageSize:storageSize
241-
flags:flags];
242-
objc_setAssociatedObject(result, &kFileDescriptorCacheKey, file,
243-
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
244-
return result;
245-
}
246-
247-
+ (instancetype)allocDescriptorForClass:(Class)messageClass
248-
rootClass:(__unused Class)rootClass
249-
file:(GPBFileDescriptor *)file
250-
fields:(void *)fieldDescriptions
251-
fieldCount:(uint32_t)fieldCount
252-
storageSize:(uint32_t)storageSize
253-
flags:(GPBDescriptorInitializationFlags)flags {
254-
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30006,
255-
time_to_remove_this_old_version_shim);
256-
// The rootClass is no longer used, but it is passed as [ROOT class] to
257-
// ensure it was started up during initialization also when the message
258-
// scopes extensions.
259-
return [self allocDescriptorForClass:messageClass
260-
file:file
261-
fields:fieldDescriptions
262-
fieldCount:fieldCount
263-
storageSize:storageSize
264-
flags:flags];
265-
}
266-
267158
- (instancetype)initWithClass:(Class)messageClass
268159
messageName:(NSString *)messageName
269160
fileDescription:(GPBFileDescription *)fileDescription
@@ -339,25 +230,6 @@ - (void)setupContainingMessageClass:(Class)messageClass {
339230
objc_setAssociatedObject(self, &kParentClassValueKey, messageClass, OBJC_ASSOCIATION_ASSIGN);
340231
}
341232

342-
- (void)setupContainingMessageClassName:(const char *)msgClassName {
343-
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30003,
344-
time_to_remove_this_old_version_shim);
345-
// Note: Only fetch the class here, can't send messages to it because
346-
// that could cause cycles back to this class within +initialize if
347-
// two messages have each other in fields (i.e. - they build a graph).
348-
Class clazz = objc_getClass(msgClassName);
349-
NSAssert(clazz, @"Class %s not defined", msgClassName);
350-
[self setupContainingMessageClass:clazz];
351-
}
352-
353-
- (void)setupMessageClassNameSuffix:(NSString *)suffix {
354-
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30007,
355-
time_to_remove_this_old_version_shim);
356-
if (suffix.length) {
357-
objc_setAssociatedObject(self, &kClassNameSuffixKey, suffix, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
358-
}
359-
}
360-
361233
- (NSString *)name {
362234
return NSStringFromClass(messageClass_);
363235
}
@@ -404,62 +276,10 @@ - (NSString *)fullName {
404276
return messageName_;
405277
}
406278

407-
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30007,
408-
time_to_remove_this_old_approach);
409-
// NOTE: When this code path is removed, this also means this api can't return nil any more but
410-
// that would be a breaking code change (not longer a Swift optional), so changing that will be
411-
// harder.
412-
413-
NSString *className = NSStringFromClass(self.messageClass);
414-
GPBFileDescriptor *file = self.file;
415-
NSString *objcPrefix = file.objcPrefix;
416-
if (objcPrefix && ![className hasPrefix:objcPrefix]) {
417-
NSAssert(0, @"Class didn't have correct prefix? (%@ - %@)", className, objcPrefix);
418-
return nil;
419-
}
420-
421-
NSString *name = nil;
422-
if (parent) {
423-
NSString *parentClassName = NSStringFromClass(parent.messageClass);
424-
// The generator will add _Class to avoid reserved words, drop it.
425-
NSString *suffix = objc_getAssociatedObject(parent, &kClassNameSuffixKey);
426-
if (suffix) {
427-
if (![parentClassName hasSuffix:suffix]) {
428-
NSAssert(0, @"ParentMessage class didn't have correct suffix? (%@ - %@)", className,
429-
suffix);
430-
return nil;
431-
}
432-
parentClassName = [parentClassName substringToIndex:(parentClassName.length - suffix.length)];
433-
}
434-
NSString *parentPrefix = [parentClassName stringByAppendingString:@"_"];
435-
if (![className hasPrefix:parentPrefix]) {
436-
NSAssert(0, @"Class didn't have the correct parent name prefix? (%@ - %@)", parentPrefix,
437-
className);
438-
return nil;
439-
}
440-
name = [className substringFromIndex:parentPrefix.length];
441-
} else {
442-
name = [className substringFromIndex:objcPrefix.length];
443-
}
444-
445-
// The generator will add _Class to avoid reserved words, drop it.
446-
NSString *suffix = objc_getAssociatedObject(self, &kClassNameSuffixKey);
447-
if (suffix) {
448-
if (![name hasSuffix:suffix]) {
449-
NSAssert(0, @"Message class didn't have correct suffix? (%@ - %@)", name, suffix);
450-
return nil;
451-
}
452-
name = [name substringToIndex:(name.length - suffix.length)];
453-
}
454-
455-
NSString *prefix = (parent != nil ? parent.fullName : file.package);
456-
NSString *result;
457-
if (prefix.length > 0) {
458-
result = [NSString stringWithFormat:@"%@.%@", prefix, name];
459-
} else {
460-
result = name;
461-
}
462-
return result;
279+
#if defined(DEBUG) && DEBUG
280+
NSAssert(NO, @"Missing messageName_");
281+
#endif
282+
return nil;
463283
}
464284

465285
- (GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber {
@@ -927,38 +747,6 @@ + (instancetype)allocDescriptorForName:(NSString *)name
927747
return descriptor;
928748
}
929749

930-
+ (instancetype)allocDescriptorForName:(NSString *)name
931-
valueNames:(const char *)valueNames
932-
values:(const int32_t *)values
933-
count:(uint32_t)valueCount
934-
enumVerifier:(GPBEnumValidationFunc)enumVerifier {
935-
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30005,
936-
time_to_remove_this_old_version_shim);
937-
return [self allocDescriptorForName:name
938-
valueNames:valueNames
939-
values:values
940-
count:valueCount
941-
enumVerifier:enumVerifier
942-
flags:GPBEnumDescriptorInitializationFlag_None];
943-
}
944-
945-
+ (instancetype)allocDescriptorForName:(NSString *)name
946-
valueNames:(const char *)valueNames
947-
values:(const int32_t *)values
948-
count:(uint32_t)valueCount
949-
enumVerifier:(GPBEnumValidationFunc)enumVerifier
950-
extraTextFormatInfo:(const char *)extraTextFormatInfo {
951-
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30005,
952-
time_to_remove_this_old_version_shim);
953-
return [self allocDescriptorForName:name
954-
valueNames:valueNames
955-
values:values
956-
count:valueCount
957-
enumVerifier:enumVerifier
958-
flags:GPBEnumDescriptorInitializationFlag_None
959-
extraTextFormatInfo:extraTextFormatInfo];
960-
}
961-
962750
- (instancetype)initWithName:(NSString *)name
963751
valueNames:(const char *)valueNames
964752
values:(const int32_t *)values
@@ -1186,27 +974,6 @@ - (instancetype)initWithExtensionDescription:(GPBExtensionDescription *)desc
1186974
return self;
1187975
}
1188976

1189-
- (instancetype)initWithExtensionDescription:(GPBExtensionDescription *)desc {
1190-
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30003,
1191-
time_to_remove_this_old_version_shim);
1192-
1193-
const char *className = desc->messageOrGroupClass.name;
1194-
if (className) {
1195-
Class clazz = objc_lookUpClass(className);
1196-
NSAssert(clazz != Nil, @"Class %s not defined", className);
1197-
desc->messageOrGroupClass.clazz = clazz;
1198-
}
1199-
1200-
const char *extendedClassName = desc->extendedClass.name;
1201-
if (extendedClassName) {
1202-
Class clazz = objc_lookUpClass(extendedClassName);
1203-
NSAssert(clazz, @"Class %s not defined", extendedClassName);
1204-
desc->extendedClass.clazz = clazz;
1205-
}
1206-
1207-
return [self initWithExtensionDescription:desc usesClassRefs:YES];
1208-
}
1209-
1210977
- (void)dealloc {
1211978
if ((description_->dataType == GPBDataTypeBytes) && !GPBExtensionIsRepeated(description_)) {
1212979
[defaultValue_.valueData release];

objectivec/GPBDescriptor_PackagePrivate.h

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -209,31 +209,6 @@ typedef NS_OPTIONS(uint32_t, GPBDescriptorInitializationFlags) {
209209
- (void)setupExtensionRanges:(const GPBExtensionRange *)ranges count:(int32_t)count;
210210
- (void)setupContainingMessageClass:(Class)msgClass;
211211

212-
// Deprecated, these remain to support older versions of source generation.
213-
+ (instancetype)allocDescriptorForClass:(Class)messageClass
214-
file:(GPBFileDescriptor *)file
215-
fields:(void *)fieldDescriptions
216-
fieldCount:(uint32_t)fieldCount
217-
storageSize:(uint32_t)storageSize
218-
flags:(GPBDescriptorInitializationFlags)flags
219-
__attribute__((deprecated("Please use a newer version of protoc to regenerate your sources. "
220-
"Support for this version will go away in the future.")));
221-
+ (instancetype)allocDescriptorForClass:(Class)messageClass
222-
rootClass:(Class)rootClass
223-
file:(GPBFileDescriptor *)file
224-
fields:(void *)fieldDescriptions
225-
fieldCount:(uint32_t)fieldCount
226-
storageSize:(uint32_t)storageSize
227-
flags:(GPBDescriptorInitializationFlags)flags
228-
__attribute__((deprecated("Please use a newer version of protoc to regenerate your sources. "
229-
"Support for this version will go away in the future.")));
230-
- (void)setupContainingMessageClassName:(const char *)msgClassName
231-
__attribute__((deprecated("Please use a newer version of protoc to regenerate your sources. "
232-
"Support for this version will go away in the future.")));
233-
- (void)setupMessageClassNameSuffix:(NSString *)suffix
234-
__attribute__((deprecated("Please use a newer version of protoc to regenerate your sources. "
235-
"Support for this version will go away in the future.")));
236-
237212
@end
238213

239214
@interface GPBFileDescriptor ()
@@ -285,22 +260,6 @@ typedef NS_OPTIONS(uint32_t, GPBEnumDescriptorInitializationFlags) {
285260
flags:(GPBEnumDescriptorInitializationFlags)flags
286261
extraTextFormatInfo:(const char *)extraTextFormatInfo;
287262

288-
// Deprecated, these remain to support older versions of source generation.
289-
+ (instancetype)allocDescriptorForName:(NSString *)name
290-
valueNames:(const char *)valueNames
291-
values:(const int32_t *)values
292-
count:(uint32_t)valueCount
293-
enumVerifier:(GPBEnumValidationFunc)enumVerifier
294-
__attribute__((deprecated("Please use a newer version of protoc to regenerate your sources. "
295-
"Support for this version will go away in the future.")));
296-
+ (instancetype)allocDescriptorForName:(NSString *)name
297-
valueNames:(const char *)valueNames
298-
values:(const int32_t *)values
299-
count:(uint32_t)valueCount
300-
enumVerifier:(GPBEnumValidationFunc)enumVerifier
301-
extraTextFormatInfo:(const char *)extraTextFormatInfo
302-
__attribute__((deprecated("Please use a newer version of protoc to regenerate your sources. "
303-
"Support for this version will go away in the future.")));
304263
@end
305264

306265
@interface GPBExtensionDescriptor () {
@@ -318,10 +277,6 @@ typedef NS_OPTIONS(uint32_t, GPBEnumDescriptorInitializationFlags) {
318277
// description has to be long lived, it is held as a raw pointer.
319278
- (instancetype)initWithExtensionDescription:(GPBExtensionDescription *)desc
320279
usesClassRefs:(BOOL)usesClassRefs;
321-
// Deprecated. Calls above with `usesClassRefs = NO`
322-
- (instancetype)initWithExtensionDescription:(GPBExtensionDescription *)desc
323-
__attribute__((deprecated("Please use a newer version of protoc to regenerate your sources. "
324-
"Support for this version will go away in the future.")));
325280

326281
- (NSComparisonResult)compareByFieldNumber:(GPBExtensionDescriptor *)other;
327282
@end

objectivec/GPBMessage_PackagePrivate.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111

1212
#import "GPBMessage.h"
1313

14-
// TODO: Remove this import. Older generated code use the OSAtomic* apis,
15-
// so anyone that hasn't regenerated says building by having this. After
16-
// enough time has passed, this likely can be removed as folks should have
17-
// regenerated.
18-
#import <libkern/OSAtomic.h>
19-
2014
#import "GPBBootstrap.h"
2115

2216
typedef struct GPBMessage_Storage {

0 commit comments

Comments
 (0)