Skip to content

Commit

Permalink
Override Map.clone to use Map's dup method
Browse files Browse the repository at this point in the history
Message and Repeated field override clone so that it uses the internal implementation of dup but Map is missing this and only implements dup.  This can lead to unexpected behavior since two out of three complex types behave correctly.
  • Loading branch information
alusco-scratch committed Oct 2, 2020
1 parent 344f28d commit 00a7ea4
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ruby/ext/google/protobuf_c/map.c
Expand Up @@ -827,6 +827,8 @@ void Map_register(VALUE module) {
rb_define_method(klass, "clear", Map_clear, 0);
rb_define_method(klass, "length", Map_length, 0);
rb_define_method(klass, "dup", Map_dup, 0);
// Also define #clone so that we don't inherit Object#clone.
rb_define_method(klass, "clone", Map_dup, 0);
rb_define_method(klass, "==", Map_eq, 1);
rb_define_method(klass, "hash", Map_hash, 0);
rb_define_method(klass, "to_h", Map_to_h, 0);
Expand Down

0 comments on commit 00a7ea4

Please sign in to comment.