Skip to content

Commit

Permalink
Merge pull request #8434 from haberman/ruby-message-eq
Browse files Browse the repository at this point in the history
Fixed message equality in cases where the message type is different.
  • Loading branch information
haberman committed Apr 1, 2021
2 parents a38319b + 38e1b59 commit f3f8707
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
9 changes: 3 additions & 6 deletions ruby/ext/google/protobuf_c/message.c
Expand Up @@ -697,16 +697,13 @@ bool Message_Equal(const upb_msg *m1, const upb_msg *m2, const upb_msgdef *m) {
* field is of a primitive type).
*/
static VALUE Message_eq(VALUE _self, VALUE _other) {
if (TYPE(_self) != TYPE(_other)) {
return Qfalse;
}
if (CLASS_OF(_self) != CLASS_OF(_other)) return Qfalse;

Message* self = ruby_to_Message(_self);
Message* other = ruby_to_Message(_other);
assert(self->msgdef == other->msgdef);

return Message_Equal(self->msg, other->msg, self->msgdef)
? Qtrue
: Qfalse;
return Message_Equal(self->msg, other->msg, self->msgdef) ? Qtrue : Qfalse;
}

uint64_t Message_Hash(const upb_msg* msg, const upb_msgdef* m, uint64_t seed) {
Expand Down
3 changes: 2 additions & 1 deletion ruby/tests/common_tests.rb
Expand Up @@ -699,12 +699,13 @@ def test_deep_copy
assert m.repeated_msg[0].object_id != m2.repeated_msg[0].object_id
end

def test_eq
def test_message_eq
m = proto_module::TestMessage.new(:optional_int32 => 42,
:repeated_int32 => [1, 2, 3])
m2 = proto_module::TestMessage.new(:optional_int32 => 43,
:repeated_int32 => [1, 2, 3])
assert m != m2
assert_not_equal proto_module::TestMessage.new, proto_module::TestMessage2.new
end

def test_enum_lookup
Expand Down

0 comments on commit f3f8707

Please sign in to comment.