Skip to content

Commit a639cf8

Browse files
thomasvlcopybara-github
authored andcommitted
[ObjC] Raise the library version and enable new generated code.
There are no functionality changes here, this revision of the generated code format remove some legacy things and thus reduce verboseness of the code. The existing format will be supported per protobuf policies and won't be removed before then. PiperOrigin-RevId: 729120445
1 parent b1a28a4 commit a639cf8

File tree

8 files changed

+22
-45
lines changed

8 files changed

+22
-45
lines changed

objectivec/GPBBootstrap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
// Current library runtime version.
115115
// - Gets bumped when the runtime makes changes to the interfaces between the
116116
// generated code and runtime (things added/removed, etc).
117-
#define GOOGLE_PROTOBUF_OBJC_VERSION 30007
117+
#define GOOGLE_PROTOBUF_OBJC_VERSION 40310
118118

119119
// Minimum runtime version supported for compiling/running against.
120120
// - Gets changed when support for the older generated code is dropped.

objectivec/GPBMessage.m

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// https://developers.google.com/open-source/licenses/bsd
77

88
#import "GPBMessage.h"
9+
#import "GPBBootstrap.h"
910
#import "GPBMessage_PackagePrivate.h"
1011

1112
#import <Foundation/Foundation.h>
@@ -1113,19 +1114,17 @@ + (instancetype)alloc {
11131114
+ (GPBDescriptor *)descriptor {
11141115
// This is thread safe because it is called from +initialize.
11151116
static GPBDescriptor *descriptor = NULL;
1116-
static GPBFileDescription fileDescription = {
1117-
.package = "internal", .prefix = "", .syntax = GPBFileSyntaxProto2};
1117+
static GPBFilePackageAndPrefix fileDescription = {.package = "internal", .prefix = ""};
11181118
if (!descriptor) {
1119-
descriptor = [GPBDescriptor
1120-
allocDescriptorForClass:[GPBMessage class]
1121-
messageName:@"GPBMessage"
1122-
fileDescription:&fileDescription
1123-
fields:NULL
1124-
fieldCount:0
1125-
storageSize:0
1126-
flags:(GPBDescriptorInitializationFlag_UsesClassRefs |
1127-
GPBDescriptorInitializationFlag_Proto3OptionalKnown |
1128-
GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
1119+
descriptor =
1120+
[GPBDescriptor allocDescriptorForClass:[GPBMessage class]
1121+
messageName:@"GPBMessage"
1122+
runtimeSupport:&GOOGLE_PROTOBUF_OBJC_EXPECTED_GENCODE_VERSION_40310
1123+
fileDescription:&fileDescription
1124+
fields:NULL
1125+
fieldCount:0
1126+
storageSize:0
1127+
flags:GPBDescriptorInitializationFlag_None];
11291128
}
11301129
return descriptor;
11311130
}

src/google/protobuf/compiler/objectivec/enum.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ void EnumGenerator::GenerateSource(io::Printer* printer) const {
233233
GPBEnumDescriptor *$name$_EnumDescriptor(void) {
234234
static _Atomic(GPBEnumDescriptor*) descriptor = nil;
235235
if (!descriptor) {
236-
GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
237236
static const char *valueNames =
238237
$values_name_blob$
239238
static const int32_t values[] = {
@@ -242,6 +241,7 @@ void EnumGenerator::GenerateSource(io::Printer* printer) const {
242241
$maybe_extra_text_format_decl$
243242
GPBEnumDescriptor *worker =
244243
[GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol($name$)
244+
runtimeSupport:&$google_protobuf_runtime_support$
245245
valueNames:valueNames
246246
values:values
247247
count:(uint32_t)(sizeof(values) / sizeof(int32_t))

src/google/protobuf/compiler/objectivec/extension.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ void ExtensionGenerator::GenerateStaticVariablesInitialization(
7373
std::vector<std::string> options;
7474
if (descriptor_->is_repeated()) options.push_back("GPBExtensionRepeated");
7575
if (descriptor_->is_packed()) options.push_back("GPBExtensionPacked");
76-
if (descriptor_->containing_type()->options().message_set_wire_format()) {
77-
options.push_back("GPBExtensionSetWireFormat");
78-
}
7976

8077
printer->Emit(
8178
{{"default",

src/google/protobuf/compiler/objectivec/field.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,6 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor,
8686
if (descriptor->has_default_value())
8787
field_flags.push_back("GPBFieldHasDefaultValue");
8888
if (needs_custom_name) field_flags.push_back("GPBFieldTextFormatNameCustom");
89-
if (descriptor->type() == FieldDescriptor::TYPE_ENUM) {
90-
field_flags.push_back("GPBFieldHasEnumDescriptor");
91-
if (descriptor->enum_type()->is_closed()) {
92-
field_flags.push_back("GPBFieldClosedEnum");
93-
}
94-
}
9589
// It will clear on a zero value if...
9690
// - not repeated/map
9791
// - doesn't have presence

src/google/protobuf/compiler/objectivec/file.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace objectivec {
4343
namespace {
4444

4545
// This is also found in GPBBootstrap.h, and needs to be kept in sync.
46-
const int32_t GOOGLE_PROTOBUF_OBJC_VERSION = 30007;
46+
const int32_t GOOGLE_PROTOBUF_OBJC_VERSION = 40310;
4747

4848
const char* kHeaderExtension = ".pbobjc.h";
4949

@@ -607,6 +607,9 @@ void FileGenerator::GenerateFile(io::Printer* p, GeneratedFileType file_type,
607607
// then honor the directives within the generators sources.
608608
"clangfmt", "clang-format"},
609609
{"root_class_name", root_class_name_},
610+
{"google_protobuf_runtime_support",
611+
absl::StrCat("GOOGLE_PROTOBUF_OBJC_EXPECTED_GENCODE_VERSION_",
612+
GOOGLE_PROTOBUF_OBJC_VERSION)},
610613
});
611614

612615
p->Emit(
@@ -740,7 +743,7 @@ void FileGenerator::EmitRootExtensionRegistryImplementation(
740743
for (size_t i = 0; i < sizeof(descriptions) / sizeof(descriptions[0]); ++i) {
741744
GPBExtensionDescriptor *extension =
742745
[[GPBExtensionDescriptor alloc] initWithExtensionDescription:&descriptions[i]
743-
usesClassRefs:YES];
746+
runtimeSupport:&$google_protobuf_runtime_support$];
744747
[registry addExtension:extension];
745748
[self globallyRegisterExtension:extension];
746749
[extension release];
@@ -773,7 +776,6 @@ void FileGenerator::EmitRootExtensionRegistryImplementation(
773776
// about thread safety and initialization of registry.
774777
static GPBExtensionRegistry* registry = nil;
775778
if (!registry) {
776-
GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
777779
registry = [[GPBExtensionRegistry alloc] init];
778780
$register_local_extensions$;
779781
$register_imports$
@@ -819,13 +821,11 @@ void FileGenerator::EmitFileDescription(io::Printer* p) const {
819821
{"prefix_value",
820822
objc_prefix.empty() && !file_->options().has_objc_class_prefix()
821823
? "NULL"
822-
: absl::StrCat("\"", objc_prefix, "\"")},
823-
{"syntax", syntax}},
824+
: absl::StrCat("\"", objc_prefix, "\"")}},
824825
R"objc(
825-
static GPBFileDescription $file_description_name$ = {
826+
static GPBFilePackageAndPrefix $file_description_name$ = {
826827
.package = $package_value$,
827-
.prefix = $prefix_value$,
828-
.syntax = $syntax$
828+
.prefix = $prefix_value$
829829
};
830830
)objc");
831831
p->Emit("\n");

src/google/protobuf/compiler/objectivec/map_field.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ MapFieldGenerator::MapFieldGenerator(
6060
if (absl::StrContains(value_field_flags, "GPBFieldHasDefaultValue")) {
6161
field_flags.push_back("GPBFieldHasDefaultValue");
6262
}
63-
if (absl::StrContains(value_field_flags, "GPBFieldHasEnumDescriptor")) {
64-
field_flags.push_back("GPBFieldHasEnumDescriptor");
65-
if (absl::StrContains(value_field_flags, "GPBFieldClosedEnum")) {
66-
field_flags.push_back("GPBFieldClosedEnum");
67-
}
68-
}
6963

7064
variables_.Set("fieldflags", BuildFlagsString(FLAGTYPE_FIELD, field_flags));
7165

src/google/protobuf/compiler/objectivec/message.cc

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,6 @@ void MessageGenerator::GenerateSource(io::Printer* printer) const {
429429
: "GPBMessageFieldDescription");
430430

431431
std::vector<std::string> init_flags;
432-
init_flags.push_back("GPBDescriptorInitializationFlag_UsesClassRefs");
433-
init_flags.push_back("GPBDescriptorInitializationFlag_Proto3OptionalKnown");
434-
init_flags.push_back(
435-
"GPBDescriptorInitializationFlag_ClosedEnumSupportKnown");
436432
if (need_defaults) {
437433
init_flags.push_back("GPBDescriptorInitializationFlag_FieldsWithDefault");
438434
}
@@ -488,10 +484,6 @@ void MessageGenerator::GenerateSource(io::Printer* printer) const {
488484
// Start up the root class to support the scoped extensions.
489485
__unused Class rootStartup = [$root_class_name$ class];
490486
)objc");
491-
} else {
492-
// The Root class has a debug runtime check, so if not
493-
// starting that up, add the check.
494-
printer->Emit("GPB_DEBUG_CHECK_RUNTIME_VERSIONS();\n");
495487
}
496488
}},
497489
{"field_description_type", field_description_type},
@@ -627,6 +619,7 @@ void MessageGenerator::GenerateSource(io::Printer* printer) const {
627619
GPBDescriptor *localDescriptor =
628620
[GPBDescriptor allocDescriptorForClass:$class_reference$
629621
messageName:@"$message_name$"
622+
runtimeSupport:&$google_protobuf_runtime_support$
630623
fileDescription:&$file_description_name$
631624
fields:$fields$
632625
fieldCount:$fields_count$

0 commit comments

Comments
 (0)