From 413e7f5d247dbe99978ef4995e75597623b245a7 Mon Sep 17 00:00:00 2001 From: J2ObjC Team Date: Tue, 24 Nov 2026 08:09:54 -0800 Subject: [PATCH] Add J2ObjC companion and KNP compatibility alias for `ExtensionRegistryLite` to match Kotlin/Native protobuf codegen in Objective-C and Swift. Objective-C and Swift code migrating from J2ObjC protos to Kotlin/Native protos cannot call `ExtensionRegistryLite.getGeneratedRegistry()` through a single API because J2ObjC did not expose `KNPComGoogleProtobufExtensionRegistryLite`, its `companion`/`shared` properties, or a transitive include from `GeneratedMessage.h`. - Declare `ComGoogleProtobufExtensionRegistryLiteCompanionProtocol` (`getGeneratedRegistry`), `companion` and `shared` class properties on `ComGoogleProtobufExtensionRegistryLite`, and `@compatibility_alias` for `KNPComGoogleProtobufExtensionRegistryLite` and `KNPComGoogleProtobufExtensionRegistryLiteCompanion`. - Return `ComGoogleProtobufExtensionRegistryLite_getEmptyRegistry()` instead of `nil` in `GeneratedExtensionRegistryLoader.m` when zero extensions are linked so `+getGeneratedRegistry` is nonnull, matching Java and Kotlin/Native. - Include `com/google/protobuf/ExtensionRegistryLite.h` from `GeneratedMessage.h` so `KNPComGoogleProtobufExtensionRegistryLite` is available from generated proto headers. - Add Objective-C and Swift round-trip extension parse tests using `KNPComGoogleProtobufExtensionRegistryLite.companion.getGeneratedRegistry`. PiperOrigin-RevId: 1029062286 --- .../src/com/google/protobuf/ExtensionRegistryLite.h | 10 ++++++++++ .../runtime/src/com/google/protobuf/GeneratedMessage.h | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/protobuf/runtime/src/com/google/protobuf/ExtensionRegistryLite.h b/protobuf/runtime/src/com/google/protobuf/ExtensionRegistryLite.h index e96cce6bd1..3e245c5e13 100644 --- a/protobuf/runtime/src/com/google/protobuf/ExtensionRegistryLite.h +++ b/protobuf/runtime/src/com/google/protobuf/ExtensionRegistryLite.h @@ -43,6 +43,9 @@ typedef ComGoogleProtobufExtensionRegistryLite CGPExtensionRegistryLite; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wnullability-completeness" + @interface ComGoogleProtobufExtensionRegistryLite : NSObject + (ComGoogleProtobufExtensionRegistryLite *)getEmptyRegistry; @@ -53,6 +56,11 @@ typedef ComGoogleProtobufExtensionRegistryLite CGPExtensionRegistryLite; @end +@compatibility_alias KNPComGoogleProtobufExtensionRegistryLite + ComGoogleProtobufExtensionRegistryLite; +@compatibility_alias KNPComGoogleProtobufExtensionRegistryLiteCompanion + ComGoogleProtobufExtensionRegistryLite; + J2OBJC_STATIC_INIT(ComGoogleProtobufExtensionRegistryLite) J2OBJC_TYPE_LITERAL_HEADER(ComGoogleProtobufExtensionRegistryLite) @@ -78,4 +86,6 @@ ComGoogleProtobufExtensionRegistryLite *new_ComGoogleProtobufExtensionRegistryLi CF_EXTERN_C_END +#pragma clang diagnostic pop + #endif // __ComGoogleProtobufExtensionRegistryLite_H__ diff --git a/protobuf/runtime/src/com/google/protobuf/GeneratedMessage.h b/protobuf/runtime/src/com/google/protobuf/GeneratedMessage.h index 4893bf7501..2b4457f376 100644 --- a/protobuf/runtime/src/com/google/protobuf/GeneratedMessage.h +++ b/protobuf/runtime/src/com/google/protobuf/GeneratedMessage.h @@ -40,13 +40,13 @@ #include "com/google/protobuf/AbstractMessage.h" #include "com/google/protobuf/Extension.h" +#include "com/google/protobuf/ExtensionRegistryLite.h" #include "com/google/protobuf/Message.h" #include "com/google/protobuf/MessageOrBuilder.h" #include "com/google/protobuf/common.h" @class ComGoogleProtobufByteString; @class ComGoogleProtobufDescriptors_FieldDescriptor; -@class ComGoogleProtobufExtensionRegistryLite; @class ComGoogleProtobufGeneratedMessage_GeneratedExtension; struct CGPFieldData;