Skip to content

Commit

Permalink
fix the ruby and php builds which were broken by a recent upb change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 490026333
  • Loading branch information
ericsalo authored and copybara-github committed Nov 21, 2022
1 parent 1489e8d commit 9cdf347
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
3 changes: 2 additions & 1 deletion php/ext/google/protobuf/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions php/ext/google/protobuf/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
18 changes: 11 additions & 7 deletions ruby/ext/google/protobuf_c/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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) !=
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 9cdf347

Please sign in to comment.