From 9cdf347d1977d328754c1e03f43f06dfa7887d51 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Mon, 21 Nov 2022 11:12:40 -0800 Subject: [PATCH] fix the ruby and php builds which were broken by a recent upb change PiperOrigin-RevId: 490026333 --- php/ext/google/protobuf/convert.c | 3 ++- php/ext/google/protobuf/message.c | 8 +++++--- ruby/ext/google/protobuf_c/message.c | 18 +++++++++++------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/php/ext/google/protobuf/convert.c b/php/ext/google/protobuf/convert.c index bedbcca367fc..6a8cca9cf1db 100644 --- a/php/ext/google/protobuf/convert.c +++ b/php/ext/google/protobuf/convert.c @@ -505,7 +505,8 @@ bool Convert_PhpToUpbAutoWrap(zval *val, upb_MessageValue *upb_val, TypeInfo typ // Assigning a scalar to a wrapper-typed value. We will automatically wrap // the value, so the user doesn't need to create a FooWrapper(['value': X]) // message manually. - upb_Message *wrapper = upb_Message_New(subm, arena); + upb_MiniTable *t = upb_MessageDef_MiniTable(subm); + upb_Message *wrapper = upb_Message_New(t, arena); const upb_FieldDef *val_f = upb_MessageDef_FindFieldByNumber(subm, 1); upb_MessageValue msgval; if (!Convert_PhpToUpb(val, &msgval, TypeInfo_Get(val_f), arena)) return false; diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index 0c90705eaf51..08296534e705 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -426,11 +426,12 @@ static zval *Message_get_property_ptr_ptr(PROTO_VAL *object, PROTO_STR *member, */ static zend_object *Message_clone_obj(PROTO_VAL *object) { Message* intern = PROTO_VAL_P(object); - upb_Message *clone = upb_Message_New(intern->desc->msgdef, Arena_Get(&intern->arena)); + upb_MiniTable *t = upb_MessageDef_MiniTable(intern->desc->msgdef); + upb_Message *clone = upb_Message_New(t, Arena_Get(&intern->arena)); // TODO: copy unknown fields? // TODO: use official upb msg copy function - memcpy(clone, intern->msg, upb_MessageDef_MiniTable(intern->desc->msgdef)->size); + memcpy(clone, intern->msg, t->size); zval ret; Message_GetPhpWrapper(&ret, intern->desc, clone, &intern->arena); return Z_OBJ_P(&ret); @@ -579,7 +580,8 @@ bool Message_InitFromPhp(upb_Message *msg, const upb_MessageDef *m, zval *init, static void Message_Initialize(Message *intern, const Descriptor *desc) { intern->desc = desc; - intern->msg = upb_Message_New(desc->msgdef, Arena_Get(&intern->arena)); + upb_MiniTable *t = upb_MessageDef_MiniTable(desc->msgdef); + intern->msg = upb_Message_New(t, Arena_Get(&intern->arena)); ObjCache_Add(intern->msg, &intern->std); } diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index 46c5f5f81ee6..3fca50641195 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -511,8 +511,8 @@ static int Map_initialize_kwarg(VALUE key, VALUE val, VALUE _self) { k = Convert_RubyToUpb(key, "", map_init->key_type, NULL); if (map_init->val_type.type == kUpb_CType_Message && TYPE(val) == T_HASH) { - upb_Message* msg = - upb_Message_New(map_init->val_type.def.msgdef, map_init->arena); + upb_MiniTable* t = upb_MessageDef_MiniTable(map_init->val_type.def.msgdef); + upb_Message* msg = upb_Message_New(t, map_init->arena); Message_InitFromValue(msg, map_init->val_type.def.msgdef, val, map_init->arena); v.msg_val = msg; @@ -542,7 +542,8 @@ static upb_MessageValue MessageValue_FromValue(VALUE val, TypeInfo info, upb_Arena* arena) { if (info.type == kUpb_CType_Message) { upb_MessageValue msgval; - upb_Message* msg = upb_Message_New(info.def.msgdef, arena); + upb_MiniTable* t = upb_MessageDef_MiniTable(info.def.msgdef); + upb_Message* msg = upb_Message_New(t, arena); Message_InitFromValue(msg, info.def.msgdef, val, arena); msgval.msg_val = msg; return msgval; @@ -657,7 +658,8 @@ static VALUE Message_initialize(int argc, VALUE* argv, VALUE _self) { Message* self = ruby_to_Message(_self); VALUE arena_rb = Arena_new(); upb_Arena* arena = Arena_get(arena_rb); - upb_Message* msg = upb_Message_New(self->msgdef, arena); + upb_MiniTable* t = upb_MessageDef_MiniTable(self->msgdef); + upb_Message* msg = upb_Message_New(t, arena); Message_InitPtr(_self, msg, arena_rb); @@ -1308,7 +1310,7 @@ upb_Message* Message_deep_copy(const upb_Message* msg, const upb_MessageDef* m, const upb_MiniTable* layout = upb_MessageDef_MiniTable(m); size_t size; - upb_Message* new_msg = upb_Message_New(m, arena); + upb_Message* new_msg = upb_Message_New(layout, arena); char* data; if (upb_Encode(msg, layout, 0, tmp_arena, &data, &size) != @@ -1341,7 +1343,8 @@ const upb_Message* Message_GetUpbMessage(VALUE value, const upb_MessageDef* m, switch (upb_MessageDef_WellKnownType(m)) { case kUpb_WellKnown_Timestamp: { // Time -> Google::Protobuf::Timestamp - upb_Message* msg = upb_Message_New(m, arena); + const upb_MiniTable* t = upb_MessageDef_MiniTable(m); + upb_Message* msg = upb_Message_New(t, arena); upb_MessageValue sec, nsec; struct timespec time; const upb_FieldDef* sec_f = upb_MessageDef_FindFieldByNumber(m, 1); @@ -1358,7 +1361,8 @@ const upb_Message* Message_GetUpbMessage(VALUE value, const upb_MessageDef* m, } case kUpb_WellKnown_Duration: { // Numeric -> Google::Protobuf::Duration - upb_Message* msg = upb_Message_New(m, arena); + const upb_MiniTable* t = upb_MessageDef_MiniTable(m); + upb_Message* msg = upb_Message_New(t, arena); upb_MessageValue sec, nsec; const upb_FieldDef* sec_f = upb_MessageDef_FindFieldByNumber(m, 1); const upb_FieldDef* nsec_f = upb_MessageDef_FindFieldByNumber(m, 2);