aboutsummaryrefslogtreecommitdiff
path: root/ruby/ext/google/protobuf_c/encode_decode.c
diff options
context:
space:
mode:
authorChris Fallin <cfallin@c1f.net>2015-01-12 16:09:35 -0800
committerChris Fallin <cfallin@c1f.net>2015-01-12 16:09:35 -0800
commitaddd26cbb3e7af05917bfc9bc965b0ada4bc80b0 (patch)
tree7c572501a4b5e27720b1bdd21f4e6965c66b0f75 /ruby/ext/google/protobuf_c/encode_decode.c
parent97b663a8be6764a3489d7150f77503ecaf40df5f (diff)
downloadprotobuf-addd26cbb3e7af05917bfc9bc965b0ada4bc80b0.tar.gz
protobuf-addd26cbb3e7af05917bfc9bc965b0ada4bc80b0.tar.bz2
protobuf-addd26cbb3e7af05917bfc9bc965b0ada4bc80b0.zip
Addressed code-review comments.
Diffstat (limited to 'ruby/ext/google/protobuf_c/encode_decode.c')
-rw-r--r--ruby/ext/google/protobuf_c/encode_decode.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/ruby/ext/google/protobuf_c/encode_decode.c b/ruby/ext/google/protobuf_c/encode_decode.c
index 1cff9049..e5e1514b 100644
--- a/ruby/ext/google/protobuf_c/encode_decode.c
+++ b/ruby/ext/google/protobuf_c/encode_decode.c
@@ -253,7 +253,12 @@ static map_handlerdata_t* new_map_handlerdata(
hd->value_field_type = upb_fielddef_type(value_field);
hd->value_field_typeclass = field_type_class(value_field);
- // Ensure that value_field_typeclass is properly GC-rooted.
+ // Ensure that value_field_typeclass is properly GC-rooted. We must do this
+ // because we hold a reference to the Ruby class in the handlerdata, which is
+ // owned by the handlers. The handlers are owned by *this* message's Ruby
+ // object, but each Ruby object is rooted independently at the def -> Ruby
+ // object map. So we have to ensure that the Ruby objects we depend on will
+ // stick around as long as we're around.
if (hd->value_field_typeclass != Qnil) {
rb_ary_push(desc->typeclass_references, hd->value_field_typeclass);
}