From 2360bacd12f5cc3f234b4155a2b7474f26ca3c7d Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Thu, 28 May 2020 14:13:39 -0400 Subject: [PATCH] Tweak the union used for Extensions to support old generated code. Support the old field name as well as the union to keep the old generated code building. Fixes #7555 --- objectivec/GPBDescriptor_PackagePrivate.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/objectivec/GPBDescriptor_PackagePrivate.h b/objectivec/GPBDescriptor_PackagePrivate.h index b3d673043c..408f8d4e10 100644 --- a/objectivec/GPBDescriptor_PackagePrivate.h +++ b/objectivec/GPBDescriptor_PackagePrivate.h @@ -131,14 +131,29 @@ typedef NS_OPTIONS(uint8_t, GPBExtensionOptions) { typedef struct GPBExtensionDescription { GPBGenericValue defaultValue; const char *singletonName; + // Before 3.12, `extendedClass` was just a `const char *`. Thanks to nested + // initialization (https://en.cppreference.com/w/c/language/struct_initialization#Nested_initialization) + // old generated code with `.extendedClass = GPBStringifySymbol(Something)` + // still works; and the current generator can use `extendedClass.clazz`, to + // pass a Class reference. union { const char *name; Class clazz; } extendedClass; + // Before 3.12, this was `const char *messageOrGroupClassName`. In the + // initial 3.12 release, we moved the `union messageOrGroupClass`, and failed + // to realize that would break existing source code for extensions. So to + // keep existing source code working, we added an unnamed union (C11) to + // provide both the old field name and the new union. This keeps both older + // and newer code working. + // Background: https://github.com/protocolbuffers/protobuf/issues/7555 union { - const char *name; - Class clazz; - } messageOrGroupClass; + const char *messageOrGroupClassName; + union { + const char *name; + Class clazz; + } messageOrGroupClass; + }; GPBEnumDescriptorFunc enumDescriptorFunc; int32_t fieldNumber; GPBDataType dataType;