Skip to content

Commit

Permalink
[ObjC] Loosen the link between generate messages and roots.
Browse files Browse the repository at this point in the history
The root class only needs to be started up if the message scopes extensions.
This updates the startup flows so the root is only started when the message
scopes extensions and thus the runtime requires that startup.

Bump the generated source version to account for the new initializer that
doesn't take the rootClass argument.

Fix typo while at it.

PiperOrigin-RevId: 504899046
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Jan 26, 2023
1 parent 8e022f8 commit 48ff4f6
Show file tree
Hide file tree
Showing 25 changed files with 67 additions and 61 deletions.
4 changes: 2 additions & 2 deletions objectivec/GPBAny.pbobjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion objectivec/GPBAny.pbobjc.m

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions objectivec/GPBApi.pbobjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions objectivec/GPBApi.pbobjc.m

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion objectivec/GPBBootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
// Current library runtime version.
// - Gets bumped when the runtime makes changes to the interfaces between the
// generated code and runtime (things added/removed, etc).
#define GOOGLE_PROTOBUF_OBJC_VERSION 30005
#define GOOGLE_PROTOBUF_OBJC_VERSION 30006

// Minimum runtime version supported for compiling/running against.
// - Gets changed when support for the older generated code is dropped.
Expand Down
36 changes: 25 additions & 11 deletions objectivec/GPBDescriptor.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ @interface GPBFieldDescriptor ()
// description has to be long lived, it is held as a raw pointer.
- (instancetype)initWithFieldDescription:(void *)description
file:(GPBFileDescriptor *)file
decriptorFlags:(GPBDescriptorInitializationFlags)decriptorFlags;
descriptorFlags:(GPBDescriptorInitializationFlags)descriptorFlags;

@end

Expand Down Expand Up @@ -135,15 +135,11 @@ @implementation GPBDescriptor {
@synthesize wireFormat = wireFormat_;

+ (instancetype)allocDescriptorForClass:(Class)messageClass
rootClass:(Class)rootClass
file:(GPBFileDescriptor *)file
fields:(void *)fieldDescriptions
fieldCount:(uint32_t)fieldCount
storageSize:(uint32_t)storageSize
flags:(GPBDescriptorInitializationFlags)flags {
// The rootClass is no longer used, but it is passed in to ensure it
// was started up during initialization also.
(void)rootClass;
NSMutableArray *fields =
(fieldCount ? [[NSMutableArray alloc] initWithCapacity:fieldCount] : nil);
BOOL fieldsIncludeDefault = (flags & GPBDescriptorInitializationFlag_FieldsWithDefault) != 0;
Expand All @@ -157,7 +153,7 @@ + (instancetype)allocDescriptorForClass:(Class)messageClass
desc = &(((GPBMessageFieldDescription *)fieldDescriptions)[i]);
}
GPBFieldDescriptor *fieldDescriptor =
[[GPBFieldDescriptor alloc] initWithFieldDescription:desc file:file decriptorFlags:flags];
[[GPBFieldDescriptor alloc] initWithFieldDescription:desc file:file descriptorFlags:flags];
[fields addObject:fieldDescriptor];
[fieldDescriptor release];
}
Expand All @@ -172,6 +168,24 @@ + (instancetype)allocDescriptorForClass:(Class)messageClass
return descriptor;
}

+ (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 {
// 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
file:(GPBFileDescriptor *)file
fields:(NSArray *)fields
Expand Down Expand Up @@ -466,10 +480,10 @@ @implementation GPBFieldDescriptor {

- (instancetype)initWithFieldDescription:(void *)description
file:(GPBFileDescriptor *)file
decriptorFlags:(GPBDescriptorInitializationFlags)decriptorFlags {
descriptorFlags:(GPBDescriptorInitializationFlags)descriptorFlags {
if ((self = [super init])) {
BOOL includesDefault =
(decriptorFlags & GPBDescriptorInitializationFlag_FieldsWithDefault) != 0;
(descriptorFlags & GPBDescriptorInitializationFlag_FieldsWithDefault) != 0;
GPBMessageFieldDescription *coreDesc;
if (includesDefault) {
coreDesc = &(((GPBMessageFieldDescriptionWithDefault *)description)->core);
Expand All @@ -486,7 +500,7 @@ - (instancetype)initWithFieldDescription:(void *)description

// If proto3 optionals weren't known (i.e. generated code from an
// older version), compute the flag for the rest of the runtime.
if ((decriptorFlags & GPBDescriptorInitializationFlag_Proto3OptionalKnown) == 0) {
if ((descriptorFlags & GPBDescriptorInitializationFlag_Proto3OptionalKnown) == 0) {
// If it was...
// - proto3 syntax
// - not repeated/map
Expand All @@ -504,7 +518,7 @@ - (instancetype)initWithFieldDescription:(void *)description

// If the ClosedEnum flag wasn't known (i.e. generated code from an older
// version), compute the flag for the rest of the runtime.
if ((decriptorFlags & GPBDescriptorInitializationFlag_ClosedEnumSupportKnown) == 0) {
if ((descriptorFlags & GPBDescriptorInitializationFlag_ClosedEnumSupportKnown) == 0) {
// 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
Expand Down Expand Up @@ -540,7 +554,7 @@ - (instancetype)initWithFieldDescription:(void *)description
// 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).
if ((decriptorFlags & GPBDescriptorInitializationFlag_UsesClassRefs) != 0) {
if ((descriptorFlags & GPBDescriptorInitializationFlag_UsesClassRefs) != 0) {
msgClass_ = coreDesc->dataTypeSpecific.clazz;
} else {
// Backwards compatibility for sources generated with older protoc.
Expand Down
8 changes: 8 additions & 0 deletions objectivec/GPBDescriptor_PackagePrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ typedef NS_OPTIONS(uint32_t, GPBDescriptorInitializationFlags) {
}

// fieldDescriptions have to be long lived, they are held as raw pointers.
+ (instancetype)allocDescriptorForClass:(Class)messageClass
file:(GPBFileDescriptor *)file
fields:(void *)fieldDescriptions
fieldCount:(uint32_t)fieldCount
storageSize:(uint32_t)storageSize
flags:(GPBDescriptorInitializationFlags)flags;

// Old interface that took the rootClass.
+ (instancetype)allocDescriptorForClass:(Class)messageClass
rootClass:(Class)rootClass
file:(GPBFileDescriptor *)file
Expand Down
4 changes: 2 additions & 2 deletions objectivec/GPBDuration.pbobjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion objectivec/GPBDuration.pbobjc.m

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions objectivec/GPBEmpty.pbobjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion objectivec/GPBEmpty.pbobjc.m

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions objectivec/GPBFieldMask.pbobjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion objectivec/GPBFieldMask.pbobjc.m

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions objectivec/GPBSourceContext.pbobjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion objectivec/GPBSourceContext.pbobjc.m

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions objectivec/GPBStruct.pbobjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions objectivec/GPBStruct.pbobjc.m

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions objectivec/GPBTimestamp.pbobjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion objectivec/GPBTimestamp.pbobjc.m

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions objectivec/GPBType.pbobjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions objectivec/GPBType.pbobjc.m

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions objectivec/GPBWrappers.pbobjc.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 48ff4f6

Please sign in to comment.