[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
pull/18759/head
Thomas Van Lenten 2 months ago committed by Copybara-Service
parent 09ac8ca248
commit cffa590260
  1. 8
      objectivec/GPBBootstrap.h
  2. 241
      objectivec/GPBDescriptor.m
  3. 45
      objectivec/GPBDescriptor_PackagePrivate.h
  4. 6
      objectivec/GPBMessage_PackagePrivate.h
  5. 22
      objectivec/GPBUtilities.m
  6. 13
      objectivec/GPBUtilities_PackagePrivate.h
  7. 4
      objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj
  8. 4
      objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj
  9. 4
      objectivec/ProtocolBuffers_tvOS.xcodeproj/project.pbxproj
  10. 145
      objectivec/Tests/GPBMessageTests+ClassNames.m

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

@ -51,7 +51,6 @@
// The addresses of these variables are used as keys for objc_getAssociatedObject.
static const char kTextFormatExtraValueKey = 0;
static const char kParentClassValueKey = 0;
static const char kClassNameSuffixKey = 0;
static const char kFileDescriptorCacheKey = 0;
static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageFields)
@ -156,114 +155,6 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageField
return descriptor;
}
+ (instancetype)allocDescriptorForClass:(Class)messageClass
file:(GPBFileDescriptor *)file
fields:(void *)fieldDescriptions
fieldCount:(uint32_t)fieldCount
storageSize:(uint32_t)storageSize
flags:(GPBDescriptorInitializationFlags)flags {
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30006,
time_to_remove_this_old_version_shim);
BOOL fixClassRefs = (flags & GPBDescriptorInitializationFlag_UsesClassRefs) == 0;
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30003,
time_to_remove_non_class_ref_support);
BOOL fixProto3Optional = (flags & GPBDescriptorInitializationFlag_Proto3OptionalKnown) == 0;
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30004,
time_to_remove_proto3_optional_fallback);
BOOL fixClosedEnums = (flags & GPBDescriptorInitializationFlag_ClosedEnumSupportKnown) == 0;
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30005,
time_to_remove_closed_enum_fallback);
if (fixClassRefs || fixProto3Optional || fixClosedEnums) {
BOOL fieldsIncludeDefault = (flags & GPBDescriptorInitializationFlag_FieldsWithDefault) != 0;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
GPBFileSyntax fileSyntax = file.syntax;
#pragma clang diagnostic pop
for (uint32_t i = 0; i < fieldCount; ++i) {
GPBMessageFieldDescription *coreDesc;
if (fieldsIncludeDefault) {
coreDesc = &((((GPBMessageFieldDescriptionWithDefault *)fieldDescriptions)[i]).core);
} else {
coreDesc = &(((GPBMessageFieldDescription *)fieldDescriptions)[i]);
}
if (fixClassRefs && GPBDataTypeIsMessage(coreDesc->dataType)) {
const char *className = coreDesc->dataTypeSpecific.className;
Class msgClass = objc_getClass(className);
NSAssert(msgClass, @"Class %s not defined", className);
coreDesc->dataTypeSpecific.clazz = msgClass;
}
if (fixProto3Optional) {
// If it was...
// - proto3 syntax
// - not repeated/map
// - not in a oneof (negative has index)
// - not a message (the flag doesn't make sense for messages)
BOOL clearOnZero = ((fileSyntax == GPBFileSyntaxProto3) &&
((coreDesc->flags & (GPBFieldRepeated | GPBFieldMapKeyMask)) == 0) &&
(coreDesc->hasIndex >= 0) && !GPBDataTypeIsMessage(coreDesc->dataType));
if (clearOnZero) {
coreDesc->flags |= GPBFieldClearHasIvarOnZero;
}
}
if (fixClosedEnums) {
// NOTE: This isn't correct, it is using the syntax of the file that
// declared the field, not the syntax of the file that declared the
// enum; but for older generated code, that's all we have and that happens
// to be what the runtime was doing (even though it was wrong). This is
// only wrong in the rare cases an enum is declared in a proto3 syntax
// file but used for a field in the proto2 syntax file.
BOOL isClosedEnum =
(coreDesc->dataType == GPBDataTypeEnum && fileSyntax == GPBFileSyntaxProto2);
if (isClosedEnum) {
coreDesc->flags |= GPBFieldClosedEnum;
}
}
}
flags |= (GPBDescriptorInitializationFlag_UsesClassRefs |
GPBDescriptorInitializationFlag_Proto3OptionalKnown |
GPBDescriptorInitializationFlag_ClosedEnumSupportKnown);
}
GPBDescriptor *result = [self allocDescriptorForClass:messageClass
messageName:nil
fileDescription:NULL
fields:fieldDescriptions
fieldCount:fieldCount
storageSize:storageSize
flags:flags];
objc_setAssociatedObject(result, &kFileDescriptorCacheKey, file,
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
return result;
}
+ (instancetype)allocDescriptorForClass:(Class)messageClass
rootClass:(__unused Class)rootClass
file:(GPBFileDescriptor *)file
fields:(void *)fieldDescriptions
fieldCount:(uint32_t)fieldCount
storageSize:(uint32_t)storageSize
flags:(GPBDescriptorInitializationFlags)flags {
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30006,
time_to_remove_this_old_version_shim);
// The rootClass is no longer used, but it is passed as [ROOT class] to
// ensure it was started up during initialization also when the message
// scopes extensions.
return [self allocDescriptorForClass:messageClass
file:file
fields:fieldDescriptions
fieldCount:fieldCount
storageSize:storageSize
flags:flags];
}
- (instancetype)initWithClass:(Class)messageClass
messageName:(NSString *)messageName
fileDescription:(GPBFileDescription *)fileDescription
@ -339,25 +230,6 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageField
objc_setAssociatedObject(self, &kParentClassValueKey, messageClass, OBJC_ASSOCIATION_ASSIGN);
}
- (void)setupContainingMessageClassName:(const char *)msgClassName {
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30003,
time_to_remove_this_old_version_shim);
// Note: Only fetch the class here, can't send messages to it because
// that could cause cycles back to this class within +initialize if
// two messages have each other in fields (i.e. - they build a graph).
Class clazz = objc_getClass(msgClassName);
NSAssert(clazz, @"Class %s not defined", msgClassName);
[self setupContainingMessageClass:clazz];
}
- (void)setupMessageClassNameSuffix:(NSString *)suffix {
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30007,
time_to_remove_this_old_version_shim);
if (suffix.length) {
objc_setAssociatedObject(self, &kClassNameSuffixKey, suffix, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
}
- (NSString *)name {
return NSStringFromClass(messageClass_);
}
@ -404,62 +276,10 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageField
return messageName_;
}
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30007,
time_to_remove_this_old_approach);
// NOTE: When this code path is removed, this also means this api can't return nil any more but
// that would be a breaking code change (not longer a Swift optional), so changing that will be
// harder.
NSString *className = NSStringFromClass(self.messageClass);
GPBFileDescriptor *file = self.file;
NSString *objcPrefix = file.objcPrefix;
if (objcPrefix && ![className hasPrefix:objcPrefix]) {
NSAssert(0, @"Class didn't have correct prefix? (%@ - %@)", className, objcPrefix);
return nil;
}
NSString *name = nil;
if (parent) {
NSString *parentClassName = NSStringFromClass(parent.messageClass);
// The generator will add _Class to avoid reserved words, drop it.
NSString *suffix = objc_getAssociatedObject(parent, &kClassNameSuffixKey);
if (suffix) {
if (![parentClassName hasSuffix:suffix]) {
NSAssert(0, @"ParentMessage class didn't have correct suffix? (%@ - %@)", className,
suffix);
return nil;
}
parentClassName = [parentClassName substringToIndex:(parentClassName.length - suffix.length)];
}
NSString *parentPrefix = [parentClassName stringByAppendingString:@"_"];
if (![className hasPrefix:parentPrefix]) {
NSAssert(0, @"Class didn't have the correct parent name prefix? (%@ - %@)", parentPrefix,
className);
return nil;
}
name = [className substringFromIndex:parentPrefix.length];
} else {
name = [className substringFromIndex:objcPrefix.length];
}
// The generator will add _Class to avoid reserved words, drop it.
NSString *suffix = objc_getAssociatedObject(self, &kClassNameSuffixKey);
if (suffix) {
if (![name hasSuffix:suffix]) {
NSAssert(0, @"Message class didn't have correct suffix? (%@ - %@)", name, suffix);
return nil;
}
name = [name substringToIndex:(name.length - suffix.length)];
}
NSString *prefix = (parent != nil ? parent.fullName : file.package);
NSString *result;
if (prefix.length > 0) {
result = [NSString stringWithFormat:@"%@.%@", prefix, name];
} else {
result = name;
}
return result;
#if defined(DEBUG) && DEBUG
NSAssert(NO, @"Missing messageName_");
#endif
return nil;
}
- (GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber {
@ -927,38 +747,6 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) {
return descriptor;
}
+ (instancetype)allocDescriptorForName:(NSString *)name
valueNames:(const char *)valueNames
values:(const int32_t *)values
count:(uint32_t)valueCount
enumVerifier:(GPBEnumValidationFunc)enumVerifier {
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30005,
time_to_remove_this_old_version_shim);
return [self allocDescriptorForName:name
valueNames:valueNames
values:values
count:valueCount
enumVerifier:enumVerifier
flags:GPBEnumDescriptorInitializationFlag_None];
}
+ (instancetype)allocDescriptorForName:(NSString *)name
valueNames:(const char *)valueNames
values:(const int32_t *)values
count:(uint32_t)valueCount
enumVerifier:(GPBEnumValidationFunc)enumVerifier
extraTextFormatInfo:(const char *)extraTextFormatInfo {
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30005,
time_to_remove_this_old_version_shim);
return [self allocDescriptorForName:name
valueNames:valueNames
values:values
count:valueCount
enumVerifier:enumVerifier
flags:GPBEnumDescriptorInitializationFlag_None
extraTextFormatInfo:extraTextFormatInfo];
}
- (instancetype)initWithName:(NSString *)name
valueNames:(const char *)valueNames
values:(const int32_t *)values
@ -1186,27 +974,6 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) {
return self;
}
- (instancetype)initWithExtensionDescription:(GPBExtensionDescription *)desc {
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30003,
time_to_remove_this_old_version_shim);
const char *className = desc->messageOrGroupClass.name;
if (className) {
Class clazz = objc_lookUpClass(className);
NSAssert(clazz != Nil, @"Class %s not defined", className);
desc->messageOrGroupClass.clazz = clazz;
}
const char *extendedClassName = desc->extendedClass.name;
if (extendedClassName) {
Class clazz = objc_lookUpClass(extendedClassName);
NSAssert(clazz, @"Class %s not defined", extendedClassName);
desc->extendedClass.clazz = clazz;
}
return [self initWithExtensionDescription:desc usesClassRefs:YES];
}
- (void)dealloc {
if ((description_->dataType == GPBDataTypeBytes) && !GPBExtensionIsRepeated(description_)) {
[defaultValue_.valueData release];

@ -209,31 +209,6 @@ typedef NS_OPTIONS(uint32_t, GPBDescriptorInitializationFlags) {
- (void)setupExtensionRanges:(const GPBExtensionRange *)ranges count:(int32_t)count;
- (void)setupContainingMessageClass:(Class)msgClass;
// Deprecated, these remain to support older versions of source generation.
+ (instancetype)allocDescriptorForClass:(Class)messageClass
file:(GPBFileDescriptor *)file
fields:(void *)fieldDescriptions
fieldCount:(uint32_t)fieldCount
storageSize:(uint32_t)storageSize
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
__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
__attribute__((deprecated("Please use a newer version of protoc to regenerate your sources. "
"Support for this version will go away in the future.")));
- (void)setupMessageClassNameSuffix:(NSString *)suffix
__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 GPBFileDescriptor ()
@ -285,22 +260,6 @@ typedef NS_OPTIONS(uint32_t, GPBEnumDescriptorInitializationFlags) {
flags:(GPBEnumDescriptorInitializationFlags)flags
extraTextFormatInfo:(const char *)extraTextFormatInfo;
// Deprecated, these remain to support older versions of source generation.
+ (instancetype)allocDescriptorForName:(NSString *)name
valueNames:(const char *)valueNames
values:(const int32_t *)values
count:(uint32_t)valueCount
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
__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 () {
@ -318,10 +277,6 @@ typedef NS_OPTIONS(uint32_t, GPBEnumDescriptorInitializationFlags) {
// description has to be long lived, it is held as a raw pointer.
- (instancetype)initWithExtensionDescription:(GPBExtensionDescription *)desc
usesClassRefs:(BOOL)usesClassRefs;
// Deprecated. Calls above with `usesClassRefs = NO`
- (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

@ -11,12 +11,6 @@
#import "GPBMessage.h"
// TODO: Remove this import. Older generated code use the OSAtomic* apis,
// so anyone that hasn't regenerated says building by having this. After
// enough time has passed, this likely can be removed as folks should have
// regenerated.
#import <libkern/OSAtomic.h>
#import "GPBBootstrap.h"
typedef struct GPBMessage_Storage {

@ -210,14 +210,6 @@ 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) {
@ -227,20 +219,6 @@ void GPBRuntimeMatchFailure(void) {
GOOGLE_PROTOBUF_OBJC_VERSION];
}
// This api is no longer used for version checks. 30001 is the last version
// using this old versioning model. When that support is removed, this function
// can be removed (along with the declaration in GPBUtilities_PackagePrivate.h).
void GPBCheckRuntimeVersionInternal(int32_t version) {
GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION <= 30001,
time_to_remove_this_old_version_shim);
if (version != GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION) {
[NSException raise:NSInternalInconsistencyException
format:@"Linked to ProtocolBuffer runtime version %d,"
@" but code compiled with version %d!",
GOOGLE_PROTOBUF_OBJC_GEN_VERSION, version];
}
}
BOOL GPBMessageHasFieldNumberSet(GPBMessage *self, uint32_t fieldNumber) {
GPBDescriptor *descriptor = [self descriptor];
GPBFieldDescriptor *field = [descriptor fieldWithNumber:fieldNumber];

@ -50,19 +50,6 @@ GPB_INLINE void GPB_DEBUG_CHECK_RUNTIME_VERSIONS(void) {
// is just a final safety net to prevent otherwise hard to diagnose errors.
void GPBRuntimeMatchFailure(void);
// Legacy version of the checks, remove when GOOGLE_PROTOBUF_OBJC_GEN_VERSION
// goes away (see more info in GPBBootstrap.h).
void GPBCheckRuntimeVersionInternal(int32_t version)
__attribute__((deprecated("Please use a newer version of protoc to regenerate your sources. "
"Support for this version will go away in the future.")));
__attribute__((deprecated("Please use a newer version of protoc to regenerate your sources. "
"Support for this version will go away in the future."))) GPB_INLINE void
GPBDebugCheckRuntimeVersion(void) {
#if defined(DEBUG) && DEBUG
GPBCheckRuntimeVersionInternal(GOOGLE_PROTOBUF_OBJC_GEN_VERSION);
#endif
}
// Conversion functions for de/serializing floating point types.
GPB_INLINE int64_t GPBConvertDoubleToInt64(double v) {

@ -33,7 +33,6 @@
8BBEA4BB147C729200C4ADB7 /* libProtocolBuffers.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */; };
8BD3981F14BE59D70081D629 /* GPBUnittestProtos.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */; };
8BF8193514A0DDA600A2C982 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
8BFF9D1A23AD582300E63E32 /* GPBMessageTests+ClassNames.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BFF9D1923AD582200E63E32 /* GPBMessageTests+ClassNames.m */; };
F401DC2D1A8D444600FCC765 /* GPBArray.m in Sources */ = {isa = PBXBuildFile; fileRef = F401DC2B1A8D444600FCC765 /* GPBArray.m */; };
F401DC331A8E5C0200FCC765 /* GPBArrayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F401DC321A8E5C0200FCC765 /* GPBArrayTests.m */; };
F40EE4AB206BF8B90071091A /* GPBCompileTest01.m in Sources */ = {isa = PBXBuildFile; fileRef = F40EE488206BF8B00071091A /* GPBCompileTest01.m */; };
@ -168,7 +167,6 @@
8BCF338814ED799900BC5317 /* GPBProtocolBuffers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GPBProtocolBuffers.m; sourceTree = "<group>"; };
8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnittestProtos.m; sourceTree = "<group>"; };
8BEB5AE01498033E0078BF9D /* GPBRuntimeTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBRuntimeTypes.h; sourceTree = "<group>"; };
8BFF9D1923AD582200E63E32 /* GPBMessageTests+ClassNames.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+ClassNames.m"; sourceTree = "<group>"; };
F401DC2A1A8D444600FCC765 /* GPBArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBArray.h; sourceTree = "<group>"; };
F401DC2B1A8D444600FCC765 /* GPBArray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBArray.m; sourceTree = "<group>"; };
F401DC321A8E5C0200FCC765 /* GPBArrayTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBArrayTests.m; sourceTree = "<group>"; };
@ -498,7 +496,6 @@
F4353D321AC06F10005A6198 /* GPBDictionaryTests+UInt64.m */,
F4584D7E1ECCB38900803AB6 /* GPBExtensionRegistryTest.m */,
7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */,
8BFF9D1923AD582200E63E32 /* GPBMessageTests+ClassNames.m */,
F4487C821AAF6AB300531423 /* GPBMessageTests+Merge.m */,
F4487C741AADF7F500531423 /* GPBMessageTests+Runtime.m */,
F4487C7E1AAF62CD00531423 /* GPBMessageTests+Serialization.m */,
@ -780,7 +777,6 @@
F4353D1D1AB8822D005A6198 /* GPBDescriptorTests.m in Sources */,
8B4248BB1A8C256A00BC1EC6 /* GPBSwiftTests.swift in Sources */,
F4584D821ECCB52A00803AB6 /* GPBExtensionRegistryTest.m in Sources */,
8BFF9D1A23AD582300E63E32 /* GPBMessageTests+ClassNames.m in Sources */,
5102DABC1891A073002037B6 /* GPBConcurrencyTests.m in Sources */,
F4487C751AADF7F500531423 /* GPBMessageTests+Runtime.m in Sources */,
F40EE4AC206BF8B90071091A /* GPBCompileTest02.m in Sources */,

@ -34,7 +34,6 @@
8BBEA4BB147C729200C4ADB7 /* libProtocolBuffers.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */; };
8BD3981F14BE59D70081D629 /* GPBUnittestProtos.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */; };
8BF8193514A0DDA600A2C982 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
8BFF9D1C23AD593C00E63E32 /* GPBMessageTests+ClassNames.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BFF9D1B23AD593B00E63E32 /* GPBMessageTests+ClassNames.m */; };
F401DC351A8E5C6F00FCC765 /* GPBArrayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F401DC341A8E5C6F00FCC765 /* GPBArrayTests.m */; };
F40EE4F0206BF91E0071091A /* GPBCompileTest01.m in Sources */ = {isa = PBXBuildFile; fileRef = F40EE4CD206BF9170071091A /* GPBCompileTest01.m */; };
F40EE4F1206BF91E0071091A /* GPBCompileTest02.m in Sources */ = {isa = PBXBuildFile; fileRef = F40EE4C6206BF9170071091A /* GPBCompileTest02.m */; };
@ -170,7 +169,6 @@
8BCF338814ED799900BC5317 /* GPBProtocolBuffers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GPBProtocolBuffers.m; sourceTree = "<group>"; };
8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnittestProtos.m; sourceTree = "<group>"; };
8BEB5AE01498033E0078BF9D /* GPBRuntimeTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBRuntimeTypes.h; sourceTree = "<group>"; };
8BFF9D1B23AD593B00E63E32 /* GPBMessageTests+ClassNames.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+ClassNames.m"; sourceTree = "<group>"; };
F401DC341A8E5C6F00FCC765 /* GPBArrayTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBArrayTests.m; sourceTree = "<group>"; };
F40EE4C2206BF9160071091A /* GPBCompileTest08.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCompileTest08.m; sourceTree = "<group>"; };
F40EE4C3206BF9160071091A /* GPBCompileTest04.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCompileTest04.m; sourceTree = "<group>"; };
@ -503,7 +501,6 @@
F4353D401AC06F31005A6198 /* GPBDictionaryTests+UInt64.m */,
F4584D801ECCB39E00803AB6 /* GPBExtensionRegistryTest.m */,
7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */,
8BFF9D1B23AD593B00E63E32 /* GPBMessageTests+ClassNames.m */,
F4487C841AAF6AC500531423 /* GPBMessageTests+Merge.m */,
F4487C761AADF84900531423 /* GPBMessageTests+Runtime.m */,
F4487C801AAF62FC00531423 /* GPBMessageTests+Serialization.m */,
@ -785,7 +782,6 @@
F4B51B1C1BBC5C7100744318 /* GPBObjectiveCPlusPlusTest.mm in Sources */,
8B4248B41A8BD96E00BC1EC6 /* GPBSwiftTests.swift in Sources */,
F4584D831ECCB53600803AB6 /* GPBExtensionRegistryTest.m in Sources */,
8BFF9D1C23AD593C00E63E32 /* GPBMessageTests+ClassNames.m in Sources */,
5102DABC1891A073002037B6 /* GPBConcurrencyTests.m in Sources */,
F4487C771AADF84900531423 /* GPBMessageTests+Runtime.m in Sources */,
F40EE4F1206BF91E0071091A /* GPBCompileTest02.m in Sources */,

@ -34,7 +34,6 @@
8BBEA4BB147C729200C4ADB7 /* libProtocolBuffers.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */; };
8BD3981F14BE59D70081D629 /* GPBUnittestProtos.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */; };
8BF8193514A0DDA600A2C982 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
8BFF9D1E23AD599400E63E32 /* GPBMessageTests+ClassNames.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BFF9D1D23AD599400E63E32 /* GPBMessageTests+ClassNames.m */; };
F401DC351A8E5C6F00FCC765 /* GPBArrayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F401DC341A8E5C6F00FCC765 /* GPBArrayTests.m */; };
F40EE4F0206BF91E0071091A /* GPBCompileTest01.m in Sources */ = {isa = PBXBuildFile; fileRef = F40EE4CD206BF9170071091A /* GPBCompileTest01.m */; };
F40EE4F1206BF91E0071091A /* GPBCompileTest02.m in Sources */ = {isa = PBXBuildFile; fileRef = F40EE4C6206BF9170071091A /* GPBCompileTest02.m */; };
@ -171,7 +170,6 @@
8BCF338814ED799900BC5317 /* GPBProtocolBuffers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GPBProtocolBuffers.m; sourceTree = "<group>"; };
8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnittestProtos.m; sourceTree = "<group>"; };
8BEB5AE01498033E0078BF9D /* GPBRuntimeTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBRuntimeTypes.h; sourceTree = "<group>"; };
8BFF9D1D23AD599400E63E32 /* GPBMessageTests+ClassNames.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+ClassNames.m"; sourceTree = "<group>"; };
F401DC341A8E5C6F00FCC765 /* GPBArrayTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBArrayTests.m; sourceTree = "<group>"; };
F40EE4C2206BF9160071091A /* GPBCompileTest08.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCompileTest08.m; sourceTree = "<group>"; };
F40EE4C3206BF9160071091A /* GPBCompileTest04.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCompileTest04.m; sourceTree = "<group>"; };
@ -504,7 +502,6 @@
F4353D401AC06F31005A6198 /* GPBDictionaryTests+UInt64.m */,
F4584D801ECCB39E00803AB6 /* GPBExtensionRegistryTest.m */,
7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */,
8BFF9D1D23AD599400E63E32 /* GPBMessageTests+ClassNames.m */,
F4487C841AAF6AC500531423 /* GPBMessageTests+Merge.m */,
F4487C761AADF84900531423 /* GPBMessageTests+Runtime.m */,
F4487C801AAF62FC00531423 /* GPBMessageTests+Serialization.m */,
@ -787,7 +784,6 @@
F4B51B1C1BBC5C7100744318 /* GPBObjectiveCPlusPlusTest.mm in Sources */,
8B4248B41A8BD96E00BC1EC6 /* GPBSwiftTests.swift in Sources */,
F4584D831ECCB53600803AB6 /* GPBExtensionRegistryTest.m in Sources */,
8BFF9D1E23AD599400E63E32 /* GPBMessageTests+ClassNames.m in Sources */,
5102DABC1891A073002037B6 /* GPBConcurrencyTests.m in Sources */,
F4487C771AADF84900531423 /* GPBMessageTests+Runtime.m in Sources */,
F40EE4F1206BF91E0071091A /* GPBCompileTest02.m in Sources */,

@ -1,145 +0,0 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2015 Google Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#import <objc/runtime.h>
#import "GPBDescriptor_PackagePrivate.h"
#import "GPBExtensionRegistry.h"
#import "GPBMessage.h"
#import "GPBRootObject_PackagePrivate.h"
#import "GPBTestUtilities.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
@interface MessageLackingClazzRoot (DynamicMethods)
+ (GPBExtensionDescriptor *)ext1;
@end
GPB_FINAL @interface MessageLackingClazz : GPBMessage
@property(copy, nonatomic) NSString *foo;
@end
@implementation MessageLackingClazz
@dynamic foo;
typedef struct MessageLackingClazz_storage_ {
uint32_t _has_storage_[1];
NSString *foo;
} MessageLackingClazz_storage_;
+ (GPBDescriptor *)descriptor {
static GPBDescriptor *descriptor = nil;
if (!descriptor) {
static GPBMessageFieldDescription fields[] = {
{
.name = "foo",
.dataTypeSpecific.className = "NSString",
.number = 1,
.hasIndex = 0,
.offset = (uint32_t)offsetof(MessageLackingClazz_storage_, foo),
.flags = (GPBFieldFlags)(GPBFieldOptional),
.dataType = GPBDataTypeMessage,
},
};
GPBFileDescriptor *desc =
[[[GPBFileDescriptor alloc] initWithPackage:@"test"
objcPrefix:@"TEST"
syntax:GPBFileSyntaxProto3] autorelease];
// GPBDescriptorInitializationFlag_UsesClassRefs intentionally not set here
descriptor = [GPBDescriptor
allocDescriptorForClass:[MessageLackingClazz class]
rootClass:[MessageLackingClazzRoot class]
file:desc
fields:fields
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(MessageLackingClazz_storage_)
flags:GPBDescriptorInitializationFlag_None];
[descriptor setupContainingMessageClassName:"MessageLackingClazz"];
}
return descriptor;
}
@end
@implementation MessageLackingClazzRoot
+ (GPBExtensionRegistry *)extensionRegistry {
// This is called by +initialize so there is no need to worry
// about thread safety and initialization of registry.
static GPBExtensionRegistry *registry = nil;
if (!registry) {
registry = [[GPBExtensionRegistry alloc] init];
static GPBExtensionDescription descriptions[] = {
{
.defaultValue.valueMessage = NULL,
.singletonName = "MessageLackingClazzRoot_ext1",
.extendedClass.name = "MessageLackingClazz",
.messageOrGroupClass.name = "MessageLackingClazz",
.enumDescriptorFunc = NULL,
.fieldNumber = 1,
.dataType = GPBDataTypeMessage,
// GPBExtensionUsesClazz Intentionally not set
.options = 0,
},
};
for (size_t i = 0; i < sizeof(descriptions) / sizeof(descriptions[0]); ++i) {
// Intentionall using `-initWithExtensionDescription:` and not `
// -initWithExtensionDescription:usesClassRefs:` to test backwards
// compatibility
GPBExtensionDescriptor *extension =
[[GPBExtensionDescriptor alloc] initWithExtensionDescription:&descriptions[i]];
[registry addExtension:extension];
[self globallyRegisterExtension:extension];
[extension release];
}
// None of the imports (direct or indirect) defined extensions, so no need to add
// them to this registry.
}
return registry;
}
@end
#pragma clang diagnostic pop
@interface MessageClassNameTests : GPBTestCase
@end
@implementation MessageClassNameTests
- (void)testClassNameSupported {
// This tests backwards compatibility to make sure we support older sources
// that use class names instead of references.
GPBDescriptor *desc = [MessageLackingClazz descriptor];
GPBFieldDescriptor *fieldDesc = [desc fieldWithName:@"foo"];
XCTAssertEqualObjects(fieldDesc.msgClass, [NSString class]);
}
- (void)testSetupContainingMessageClassNameSupported {
// This tests backwards compatibility to make sure we support older sources
// that use class names instead of references.
GPBDescriptor *desc = [MessageLackingClazz descriptor];
GPBDescriptor *container = [desc containingType];
XCTAssertEqualObjects(container.messageClass, [MessageLackingClazz class]);
}
- (void)testExtensionsNameSupported {
// This tests backwards compatibility to make sure we support older sources
// that use class names instead of references.
GPBExtensionDescriptor *desc = [MessageLackingClazzRoot ext1];
Class containerClass = [desc containingMessageClass];
XCTAssertEqualObjects(containerClass, [MessageLackingClazz class]);
Class msgClass = [desc msgClass];
XCTAssertEqualObjects(msgClass, [MessageLackingClazz class]);
}
@end
Loading…
Cancel
Save