Pārlūkot izejas kodu

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.
Aaron Patterson 4 gadi atpakaļ
vecāks
revīzija
addd0615bf
1 mainītis faili ar 4 papildinājumiem un 2 dzēšanām
  1. 4 2
      ruby/ext/google/protobuf_c/protobuf.c

+ 4 - 2
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);