Skip to content

Commit

Permalink
[ObjC] Raise the library version and enable new generated code.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
thomasvl authored and copybara-github committed Feb 20, 2025
1 parent b1a28a4 commit a639cf8
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 45 deletions.
2 changes: 1 addition & 1 deletion objectivec/GPBBootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,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 30007
#define GOOGLE_PROTOBUF_OBJC_VERSION 40310

// Minimum runtime version supported for compiling/running against.
// - Gets changed when support for the older generated code is dropped.
Expand Down
23 changes: 11 additions & 12 deletions objectivec/GPBMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// https://developers.google.com/open-source/licenses/bsd

#import "GPBMessage.h"
#import "GPBBootstrap.h"
#import "GPBMessage_PackagePrivate.h"

#import <Foundation/Foundation.h>
Expand Down Expand Up @@ -1113,19 +1114,17 @@ + (instancetype)alloc {
+ (GPBDescriptor *)descriptor {
// This is thread safe because it is called from +initialize.
static GPBDescriptor *descriptor = NULL;
static GPBFileDescription fileDescription = {
.package = "internal", .prefix = "", .syntax = GPBFileSyntaxProto2};
static GPBFilePackageAndPrefix fileDescription = {.package = "internal", .prefix = ""};
if (!descriptor) {
descriptor = [GPBDescriptor
allocDescriptorForClass:[GPBMessage class]
messageName:@"GPBMessage"
fileDescription:&fileDescription
fields:NULL
fieldCount:0
storageSize:0
flags:(GPBDescriptorInitializationFlag_UsesClassRefs |
GPBDescriptorInitializationFlag_Proto3OptionalKnown |
GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
descriptor =
[GPBDescriptor allocDescriptorForClass:[GPBMessage class]
messageName:@"GPBMessage"
runtimeSupport:&GOOGLE_PROTOBUF_OBJC_EXPECTED_GENCODE_VERSION_40310
fileDescription:&fileDescription
fields:NULL
fieldCount:0
storageSize:0
flags:GPBDescriptorInitializationFlag_None];
}
return descriptor;
}
Expand Down
2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/objectivec/enum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ void EnumGenerator::GenerateSource(io::Printer* printer) const {
GPBEnumDescriptor *$name$_EnumDescriptor(void) {
static _Atomic(GPBEnumDescriptor*) descriptor = nil;
if (!descriptor) {
GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
static const char *valueNames =
$values_name_blob$
static const int32_t values[] = {
Expand All @@ -242,6 +241,7 @@ void EnumGenerator::GenerateSource(io::Printer* printer) const {
$maybe_extra_text_format_decl$
GPBEnumDescriptor *worker =
[GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol($name$)
runtimeSupport:&$google_protobuf_runtime_support$
valueNames:valueNames
values:values
count:(uint32_t)(sizeof(values) / sizeof(int32_t))
Expand Down
3 changes: 0 additions & 3 deletions src/google/protobuf/compiler/objectivec/extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ void ExtensionGenerator::GenerateStaticVariablesInitialization(
std::vector<std::string> options;
if (descriptor_->is_repeated()) options.push_back("GPBExtensionRepeated");
if (descriptor_->is_packed()) options.push_back("GPBExtensionPacked");
if (descriptor_->containing_type()->options().message_set_wire_format()) {
options.push_back("GPBExtensionSetWireFormat");
}

printer->Emit(
{{"default",
Expand Down
6 changes: 0 additions & 6 deletions src/google/protobuf/compiler/objectivec/field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor,
if (descriptor->has_default_value())
field_flags.push_back("GPBFieldHasDefaultValue");
if (needs_custom_name) field_flags.push_back("GPBFieldTextFormatNameCustom");
if (descriptor->type() == FieldDescriptor::TYPE_ENUM) {
field_flags.push_back("GPBFieldHasEnumDescriptor");
if (descriptor->enum_type()->is_closed()) {
field_flags.push_back("GPBFieldClosedEnum");
}
}
// It will clear on a zero value if...
// - not repeated/map
// - doesn't have presence
Expand Down
16 changes: 8 additions & 8 deletions src/google/protobuf/compiler/objectivec/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace objectivec {
namespace {

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

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

Expand Down Expand Up @@ -607,6 +607,9 @@ void FileGenerator::GenerateFile(io::Printer* p, GeneratedFileType file_type,
// then honor the directives within the generators sources.
"clangfmt", "clang-format"},
{"root_class_name", root_class_name_},
{"google_protobuf_runtime_support",
absl::StrCat("GOOGLE_PROTOBUF_OBJC_EXPECTED_GENCODE_VERSION_",
GOOGLE_PROTOBUF_OBJC_VERSION)},
});

p->Emit(
Expand Down Expand Up @@ -740,7 +743,7 @@ void FileGenerator::EmitRootExtensionRegistryImplementation(
for (size_t i = 0; i < sizeof(descriptions) / sizeof(descriptions[0]); ++i) {
GPBExtensionDescriptor *extension =
[[GPBExtensionDescriptor alloc] initWithExtensionDescription:&descriptions[i]
usesClassRefs:YES];
runtimeSupport:&$google_protobuf_runtime_support$];
[registry addExtension:extension];
[self globallyRegisterExtension:extension];
[extension release];
Expand Down Expand Up @@ -773,7 +776,6 @@ void FileGenerator::EmitRootExtensionRegistryImplementation(
// about thread safety and initialization of registry.
static GPBExtensionRegistry* registry = nil;
if (!registry) {
GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
registry = [[GPBExtensionRegistry alloc] init];
$register_local_extensions$;
$register_imports$
Expand Down Expand Up @@ -819,13 +821,11 @@ void FileGenerator::EmitFileDescription(io::Printer* p) const {
{"prefix_value",
objc_prefix.empty() && !file_->options().has_objc_class_prefix()
? "NULL"
: absl::StrCat("\"", objc_prefix, "\"")},
{"syntax", syntax}},
: absl::StrCat("\"", objc_prefix, "\"")}},
R"objc(
static GPBFileDescription $file_description_name$ = {
static GPBFilePackageAndPrefix $file_description_name$ = {
.package = $package_value$,
.prefix = $prefix_value$,
.syntax = $syntax$
.prefix = $prefix_value$
};
)objc");
p->Emit("\n");
Expand Down
6 changes: 0 additions & 6 deletions src/google/protobuf/compiler/objectivec/map_field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ MapFieldGenerator::MapFieldGenerator(
if (absl::StrContains(value_field_flags, "GPBFieldHasDefaultValue")) {
field_flags.push_back("GPBFieldHasDefaultValue");
}
if (absl::StrContains(value_field_flags, "GPBFieldHasEnumDescriptor")) {
field_flags.push_back("GPBFieldHasEnumDescriptor");
if (absl::StrContains(value_field_flags, "GPBFieldClosedEnum")) {
field_flags.push_back("GPBFieldClosedEnum");
}
}

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

Expand Down
9 changes: 1 addition & 8 deletions src/google/protobuf/compiler/objectivec/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,6 @@ void MessageGenerator::GenerateSource(io::Printer* printer) const {
: "GPBMessageFieldDescription");

std::vector<std::string> init_flags;
init_flags.push_back("GPBDescriptorInitializationFlag_UsesClassRefs");
init_flags.push_back("GPBDescriptorInitializationFlag_Proto3OptionalKnown");
init_flags.push_back(
"GPBDescriptorInitializationFlag_ClosedEnumSupportKnown");
if (need_defaults) {
init_flags.push_back("GPBDescriptorInitializationFlag_FieldsWithDefault");
}
Expand Down Expand Up @@ -488,10 +484,6 @@ void MessageGenerator::GenerateSource(io::Printer* printer) const {
// Start up the root class to support the scoped extensions.
__unused Class rootStartup = [$root_class_name$ class];
)objc");
} else {
// The Root class has a debug runtime check, so if not
// starting that up, add the check.
printer->Emit("GPB_DEBUG_CHECK_RUNTIME_VERSIONS();\n");
}
}},
{"field_description_type", field_description_type},
Expand Down Expand Up @@ -627,6 +619,7 @@ void MessageGenerator::GenerateSource(io::Printer* printer) const {
GPBDescriptor *localDescriptor =
[GPBDescriptor allocDescriptorForClass:$class_reference$
messageName:@"$message_name$"
runtimeSupport:&$google_protobuf_runtime_support$
fileDescription:&$file_description_name$
fields:$fields$
fieldCount:$fields_count$
Expand Down

0 comments on commit a639cf8

Please sign in to comment.