From addd0615bfbc956ca0b9b7328955d0198218e2e7 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 10 Mar 2021 13:54:04 -0800 Subject: [PATCH] Register mark objects so Protobuf is compaction friendly This commit removes an unused reference and registers globals with the GC so that they will never die. Ruby is getting a compacting GC, and it means that these references can move. Registering them with `rb_gc_register_mark_object` will ensure the constants don't move and will not be collected. --- ruby/ext/google/protobuf_c/protobuf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ruby/ext/google/protobuf_c/protobuf.c b/ruby/ext/google/protobuf_c/protobuf.c index c27f30aa2d55..c9eecee11e5b 100644 --- a/ruby/ext/google/protobuf_c/protobuf.c +++ b/ruby/ext/google/protobuf_c/protobuf.c @@ -37,7 +37,7 @@ #include "message.h" #include "repeated_field.h" -VALUE cError; +VALUE cParseError; VALUE cTypeError; const upb_fielddef* map_field_key(const upb_fielddef* field) { @@ -368,8 +368,10 @@ void Init_protobuf_c() { Map_register(protobuf); Message_register(protobuf); - cError = rb_const_get(protobuf, rb_intern("Error")); + cParseError = rb_const_get(protobuf, rb_intern("ParseError")); + rb_gc_register_mark_object(cParseError); cTypeError = rb_const_get(protobuf, rb_intern("TypeError")); + rb_gc_register_mark_object(cTypeError); rb_define_singleton_method(protobuf, "discard_unknown", Google_Protobuf_discard_unknown, 1);