From 408b497d4e650d3b45f1c4facb70b305299bfebd Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 10 Jan 2024 01:34:19 +0000 Subject: [PATCH] Auto-generate files after cl/597088960 --- php/ext/google/protobuf/php-upb.h | 26 ++++++++++++++++++++++++++ ruby/ext/google/protobuf_c/ruby-upb.h | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 6e43b83c50..80b4e33de8 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -2608,6 +2608,32 @@ UPB_INLINE void _upb_Message_GetExtensionField( } } +// Gets a extension message or creates a default message and sets the extension +// if it doesn't already exist. +UPB_INLINE bool _upb_Message_GetOrCreateExtensionSubmessage( + struct upb_Message* msg, const upb_MiniTableExtension* mt_ext, + struct upb_Message** val, upb_Arena* a) { + const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field); + UPB_ASSUME(upb_MiniTableField_IsExtension(f)); + const struct upb_Extension* const_ext = _upb_Message_Getext(msg, mt_ext); + if (const_ext) { + // Extension exists, get a mutable version of it. + struct upb_Extension* ext = + _upb_Message_GetOrCreateExtension(msg, mt_ext, a); + *val = (struct upb_Message*)ext->data.ptr; + return true; + } + // Extension doesn't exist, create a new message and set it. + struct upb_Message* ext_msg = + _upb_Message_New(upb_MiniTableExtension_GetSubMessage(mt_ext), a); + if (!ext_msg) return false; + struct upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); + if (!ext) return false; + ext->data.ptr = ext_msg; + *val = ext_msg; + return true; +} + UPB_INLINE void _upb_Message_SetNonExtensionField( struct upb_Message* msg, const upb_MiniTableField* field, const void* val) { UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 8873252159..f171f462cb 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -2610,6 +2610,32 @@ UPB_INLINE void _upb_Message_GetExtensionField( } } +// Gets a extension message or creates a default message and sets the extension +// if it doesn't already exist. +UPB_INLINE bool _upb_Message_GetOrCreateExtensionSubmessage( + struct upb_Message* msg, const upb_MiniTableExtension* mt_ext, + struct upb_Message** val, upb_Arena* a) { + const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field); + UPB_ASSUME(upb_MiniTableField_IsExtension(f)); + const struct upb_Extension* const_ext = _upb_Message_Getext(msg, mt_ext); + if (const_ext) { + // Extension exists, get a mutable version of it. + struct upb_Extension* ext = + _upb_Message_GetOrCreateExtension(msg, mt_ext, a); + *val = (struct upb_Message*)ext->data.ptr; + return true; + } + // Extension doesn't exist, create a new message and set it. + struct upb_Message* ext_msg = + _upb_Message_New(upb_MiniTableExtension_GetSubMessage(mt_ext), a); + if (!ext_msg) return false; + struct upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); + if (!ext) return false; + ext->data.ptr = ext_msg; + *val = ext_msg; + return true; +} + UPB_INLINE void _upb_Message_SetNonExtensionField( struct upb_Message* msg, const upb_MiniTableField* field, const void* val) { UPB_ASSUME(!upb_MiniTableField_IsExtension(field));