Skip to content

Commit 2360bac

Browse files
committed
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 protocolbuffers#7555
1 parent 0ff6399 commit 2360bac

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

objectivec/GPBDescriptor_PackagePrivate.h

+18-3
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,29 @@ typedef NS_OPTIONS(uint8_t, GPBExtensionOptions) {
131131
typedef struct GPBExtensionDescription {
132132
GPBGenericValue defaultValue;
133133
const char *singletonName;
134+
// Before 3.12, `extendedClass` was just a `const char *`. Thanks to nested
135+
// initialization (https://en.cppreference.com/w/c/language/struct_initialization#Nested_initialization)
136+
// old generated code with `.extendedClass = GPBStringifySymbol(Something)`
137+
// still works; and the current generator can use `extendedClass.clazz`, to
138+
// pass a Class reference.
134139
union {
135140
const char *name;
136141
Class clazz;
137142
} extendedClass;
143+
// Before 3.12, this was `const char *messageOrGroupClassName`. In the
144+
// initial 3.12 release, we moved the `union messageOrGroupClass`, and failed
145+
// to realize that would break existing source code for extensions. So to
146+
// keep existing source code working, we added an unnamed union (C11) to
147+
// provide both the old field name and the new union. This keeps both older
148+
// and newer code working.
149+
// Background: https://github.com/protocolbuffers/protobuf/issues/7555
138150
union {
139-
const char *name;
140-
Class clazz;
141-
} messageOrGroupClass;
151+
const char *messageOrGroupClassName;
152+
union {
153+
const char *name;
154+
Class clazz;
155+
} messageOrGroupClass;
156+
};
142157
GPBEnumDescriptorFunc enumDescriptorFunc;
143158
int32_t fieldNumber;
144159
GPBDataType dataType;

0 commit comments

Comments
 (0)