Skip to content

Commit

Permalink
Updated Ruby to the latest upb. (#9589) (#9630)
Browse files Browse the repository at this point in the history
* Updated Ruby to the latest upb.

* Updated to newer upb.
  • Loading branch information
haberman authored Mar 14, 2022
1 parent 357e716 commit 16dccd6
Show file tree
Hide file tree
Showing 5 changed files with 1,131 additions and 734 deletions.
8 changes: 4 additions & 4 deletions ruby/ext/google/protobuf_c/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,19 +340,19 @@ uint64_t Msgval_GetHash(upb_MessageValue val, TypeInfo type_info,
uint64_t seed) {
switch (type_info.type) {
case kUpb_CType_Bool:
return Wyhash(&val, 1, seed, kWyhashSalt);
return _upb_Hash(&val, 1, seed);
case kUpb_CType_Float:
case kUpb_CType_Int32:
case kUpb_CType_UInt32:
case kUpb_CType_Enum:
return Wyhash(&val, 4, seed, kWyhashSalt);
return _upb_Hash(&val, 4, seed);
case kUpb_CType_Double:
case kUpb_CType_Int64:
case kUpb_CType_UInt64:
return Wyhash(&val, 8, seed, kWyhashSalt);
return _upb_Hash(&val, 8, seed);
case kUpb_CType_String:
case kUpb_CType_Bytes:
return Wyhash(val.str_val.data, val.str_val.size, seed, kWyhashSalt);
return _upb_Hash(val.str_val.data, val.str_val.size, seed);
case kUpb_CType_Message:
return Message_Hash(val.msg_val, type_info.def.msgdef, seed);
default:
Expand Down
38 changes: 14 additions & 24 deletions ruby/ext/google/protobuf_c/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,8 @@ void Message_PrintMessage(StringBuilder* b, const upb_Message* msg,

if (upb_FieldDef_IsMap(field)) {
const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(field);
const upb_FieldDef* key_f =
upb_MessageDef_FindFieldByNumberWithSize(entry_m, 1);
const upb_FieldDef* val_f =
upb_MessageDef_FindFieldByNumberWithSize(entry_m, 2);
const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry_m, 1);
const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(entry_m, 2);
TypeInfo val_info = TypeInfo_get(val_f);
Map_Inspect(b, msgval.map_val, upb_FieldDef_CType(key_f), val_info);
} else if (upb_FieldDef_IsRepeated(field)) {
Expand Down Expand Up @@ -365,7 +363,7 @@ static VALUE Message_field_accessor(VALUE _self, const upb_FieldDef* f,
upb_MessageValue wrapper = upb_Message_Get(self->msg, f);
const upb_MessageDef* wrapper_m = upb_FieldDef_MessageSubDef(f);
const upb_FieldDef* value_f =
upb_MessageDef_FindFieldByNumberWithSize(wrapper_m, 1);
upb_MessageDef_FindFieldByNumber(wrapper_m, 1);
upb_MessageValue value = upb_Message_Get(wrapper.msg_val, value_f);
return Convert_UpbToRuby(value, TypeInfo_get(value_f), self->arena);
} else {
Expand All @@ -377,8 +375,8 @@ static VALUE Message_field_accessor(VALUE _self, const upb_FieldDef* f,
if (argv[1] == Qnil) {
upb_Message_ClearField(msg, f);
} else {
const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumberWithSize(
upb_FieldDef_MessageSubDef(f), 1);
const upb_FieldDef* val_f =
upb_MessageDef_FindFieldByNumber(upb_FieldDef_MessageSubDef(f), 1);
upb_MessageValue msgval = Convert_RubyToUpb(
argv[1], upb_FieldDef_Name(f), TypeInfo_get(val_f), arena);
upb_Message* wrapper = upb_Message_Mutable(msg, f, arena).msg;
Expand Down Expand Up @@ -527,10 +525,8 @@ static int Map_initialize_kwarg(VALUE key, VALUE val, VALUE _self) {
static void Map_InitFromValue(upb_Map* map, const upb_FieldDef* f, VALUE val,
upb_Arena* arena) {
const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(f);
const upb_FieldDef* key_f =
upb_MessageDef_FindFieldByNumberWithSize(entry_m, 1);
const upb_FieldDef* val_f =
upb_MessageDef_FindFieldByNumberWithSize(entry_m, 2);
const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry_m, 1);
const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(entry_m, 2);
if (TYPE(val) != T_HASH) {
rb_raise(rb_eArgError,
"Expected Hash object as initializer value for map field '%s' "
Expand Down Expand Up @@ -748,7 +744,7 @@ uint64_t Message_Hash(const upb_Message* msg, const upb_MessageDef* m,
&size);

if (data) {
uint64_t ret = Wyhash(data, size, seed, kWyhashSalt);
uint64_t ret = _upb_Hash(data, size, seed);
upb_Arena_Free(arena);
return ret;
} else {
Expand Down Expand Up @@ -847,10 +843,8 @@ static VALUE Message_CreateHash(const upb_Message* msg,

if (upb_FieldDef_IsMap(field)) {
const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(field);
const upb_FieldDef* key_f =
upb_MessageDef_FindFieldByNumberWithSize(entry_m, 1);
const upb_FieldDef* val_f =
upb_MessageDef_FindFieldByNumberWithSize(entry_m, 2);
const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry_m, 1);
const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(entry_m, 2);
upb_CType key_type = upb_FieldDef_CType(key_f);
msg_value = Map_CreateHash(msgval.map_val, key_type, TypeInfo_get(val_f));
} else if (upb_FieldDef_IsRepeated(field)) {
Expand Down Expand Up @@ -1357,10 +1351,8 @@ const upb_Message* Message_GetUpbMessage(VALUE value, const upb_MessageDef* m,
upb_Message* msg = upb_Message_New(m, arena);
upb_MessageValue sec, nsec;
struct timespec time;
const upb_FieldDef* sec_f =
upb_MessageDef_FindFieldByNumberWithSize(m, 1);
const upb_FieldDef* nsec_f =
upb_MessageDef_FindFieldByNumberWithSize(m, 2);
const upb_FieldDef* sec_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_FieldDef* nsec_f = upb_MessageDef_FindFieldByNumber(m, 2);

if (!rb_obj_is_kind_of(value, rb_cTime)) goto badtype;

Expand All @@ -1375,10 +1367,8 @@ const upb_Message* Message_GetUpbMessage(VALUE value, const upb_MessageDef* m,
// Numeric -> Google::Protobuf::Duration
upb_Message* msg = upb_Message_New(m, arena);
upb_MessageValue sec, nsec;
const upb_FieldDef* sec_f =
upb_MessageDef_FindFieldByNumberWithSize(m, 1);
const upb_FieldDef* nsec_f =
upb_MessageDef_FindFieldByNumberWithSize(m, 2);
const upb_FieldDef* sec_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_FieldDef* nsec_f = upb_MessageDef_FindFieldByNumber(m, 2);

if (!rb_obj_is_kind_of(value, rb_cNumeric)) goto badtype;

Expand Down
4 changes: 2 additions & 2 deletions ruby/ext/google/protobuf_c/protobuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ VALUE cTypeError;

const upb_FieldDef *map_field_key(const upb_FieldDef *field) {
const upb_MessageDef *entry = upb_FieldDef_MessageSubDef(field);
return upb_MessageDef_FindFieldByNumberWithSize(entry, 1);
return upb_MessageDef_FindFieldByNumber(entry, 1);
}

const upb_FieldDef *map_field_value(const upb_FieldDef *field) {
const upb_MessageDef *entry = upb_FieldDef_MessageSubDef(field);
return upb_MessageDef_FindFieldByNumberWithSize(entry, 2);
return upb_MessageDef_FindFieldByNumber(entry, 2);
}

// -----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 16dccd6

Please sign in to comment.