Unverified Commit cf7c15e3 authored by Paul Yang's avatar Paul Yang Committed by GitHub

Fix ruby gc_test in ruby 2.4 (#4011)

* Fix ruby gc_test in ruby 2.4

* Initialize global variables to Qnil.
parent 0e7b5895
...@@ -76,7 +76,7 @@ static upb_enumdef* check_enum_notfrozen(const upb_enumdef* def) { ...@@ -76,7 +76,7 @@ static upb_enumdef* check_enum_notfrozen(const upb_enumdef* def) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#define DEFINE_CLASS(name, string_name) \ #define DEFINE_CLASS(name, string_name) \
VALUE c ## name; \ VALUE c ## name = Qnil; \
const rb_data_type_t _ ## name ## _type = { \ const rb_data_type_t _ ## name ## _type = { \
string_name, \ string_name, \
{ name ## _mark, name ## _free, NULL }, \ { name ## _mark, name ## _free, NULL }, \
...@@ -126,11 +126,11 @@ void DescriptorPool_register(VALUE module) { ...@@ -126,11 +126,11 @@ void DescriptorPool_register(VALUE module) {
rb_define_method(klass, "lookup", DescriptorPool_lookup, 1); rb_define_method(klass, "lookup", DescriptorPool_lookup, 1);
rb_define_singleton_method(klass, "generated_pool", rb_define_singleton_method(klass, "generated_pool",
DescriptorPool_generated_pool, 0); DescriptorPool_generated_pool, 0);
cDescriptorPool = klass;
rb_gc_register_address(&cDescriptorPool); rb_gc_register_address(&cDescriptorPool);
cDescriptorPool = klass;
generated_pool = rb_class_new_instance(0, NULL, klass);
rb_gc_register_address(&generated_pool); rb_gc_register_address(&generated_pool);
generated_pool = rb_class_new_instance(0, NULL, klass);
} }
static void add_descriptor_to_pool(DescriptorPool* self, static void add_descriptor_to_pool(DescriptorPool* self,
...@@ -299,8 +299,8 @@ void Descriptor_register(VALUE module) { ...@@ -299,8 +299,8 @@ void Descriptor_register(VALUE module) {
rb_define_method(klass, "name", Descriptor_name, 0); rb_define_method(klass, "name", Descriptor_name, 0);
rb_define_method(klass, "name=", Descriptor_name_set, 1); rb_define_method(klass, "name=", Descriptor_name_set, 1);
rb_include_module(klass, rb_mEnumerable); rb_include_module(klass, rb_mEnumerable);
cDescriptor = klass;
rb_gc_register_address(&cDescriptor); rb_gc_register_address(&cDescriptor);
cDescriptor = klass;
} }
/* /*
...@@ -518,8 +518,8 @@ void FieldDescriptor_register(VALUE module) { ...@@ -518,8 +518,8 @@ void FieldDescriptor_register(VALUE module) {
rb_define_method(klass, "subtype", FieldDescriptor_subtype, 0); rb_define_method(klass, "subtype", FieldDescriptor_subtype, 0);
rb_define_method(klass, "get", FieldDescriptor_get, 1); rb_define_method(klass, "get", FieldDescriptor_get, 1);
rb_define_method(klass, "set", FieldDescriptor_set, 2); rb_define_method(klass, "set", FieldDescriptor_set, 2);
cFieldDescriptor = klass;
rb_gc_register_address(&cFieldDescriptor); rb_gc_register_address(&cFieldDescriptor);
cFieldDescriptor = klass;
} }
/* /*
...@@ -916,8 +916,8 @@ void OneofDescriptor_register(VALUE module) { ...@@ -916,8 +916,8 @@ void OneofDescriptor_register(VALUE module) {
rb_define_method(klass, "add_field", OneofDescriptor_add_field, 1); rb_define_method(klass, "add_field", OneofDescriptor_add_field, 1);
rb_define_method(klass, "each", OneofDescriptor_each, 0); rb_define_method(klass, "each", OneofDescriptor_each, 0);
rb_include_module(klass, rb_mEnumerable); rb_include_module(klass, rb_mEnumerable);
cOneofDescriptor = klass;
rb_gc_register_address(&cOneofDescriptor); rb_gc_register_address(&cOneofDescriptor);
cOneofDescriptor = klass;
} }
/* /*
...@@ -1037,8 +1037,8 @@ void EnumDescriptor_register(VALUE module) { ...@@ -1037,8 +1037,8 @@ void EnumDescriptor_register(VALUE module) {
rb_define_method(klass, "each", EnumDescriptor_each, 0); rb_define_method(klass, "each", EnumDescriptor_each, 0);
rb_define_method(klass, "enummodule", EnumDescriptor_enummodule, 0); rb_define_method(klass, "enummodule", EnumDescriptor_enummodule, 0);
rb_include_module(klass, rb_mEnumerable); rb_include_module(klass, rb_mEnumerable);
cEnumDescriptor = klass;
rb_gc_register_address(&cEnumDescriptor); rb_gc_register_address(&cEnumDescriptor);
cEnumDescriptor = klass;
} }
/* /*
...@@ -1202,8 +1202,8 @@ void MessageBuilderContext_register(VALUE module) { ...@@ -1202,8 +1202,8 @@ void MessageBuilderContext_register(VALUE module) {
rb_define_method(klass, "repeated", MessageBuilderContext_repeated, -1); rb_define_method(klass, "repeated", MessageBuilderContext_repeated, -1);
rb_define_method(klass, "map", MessageBuilderContext_map, -1); rb_define_method(klass, "map", MessageBuilderContext_map, -1);
rb_define_method(klass, "oneof", MessageBuilderContext_oneof, 1); rb_define_method(klass, "oneof", MessageBuilderContext_oneof, 1);
cMessageBuilderContext = klass;
rb_gc_register_address(&cMessageBuilderContext); rb_gc_register_address(&cMessageBuilderContext);
cMessageBuilderContext = klass;
} }
/* /*
...@@ -1491,8 +1491,8 @@ void OneofBuilderContext_register(VALUE module) { ...@@ -1491,8 +1491,8 @@ void OneofBuilderContext_register(VALUE module) {
rb_define_method(klass, "initialize", rb_define_method(klass, "initialize",
OneofBuilderContext_initialize, 2); OneofBuilderContext_initialize, 2);
rb_define_method(klass, "optional", OneofBuilderContext_optional, -1); rb_define_method(klass, "optional", OneofBuilderContext_optional, -1);
cOneofBuilderContext = klass;
rb_gc_register_address(&cOneofBuilderContext); rb_gc_register_address(&cOneofBuilderContext);
cOneofBuilderContext = klass;
} }
/* /*
...@@ -1569,8 +1569,8 @@ void EnumBuilderContext_register(VALUE module) { ...@@ -1569,8 +1569,8 @@ void EnumBuilderContext_register(VALUE module) {
rb_define_method(klass, "initialize", rb_define_method(klass, "initialize",
EnumBuilderContext_initialize, 1); EnumBuilderContext_initialize, 1);
rb_define_method(klass, "value", EnumBuilderContext_value, 2); rb_define_method(klass, "value", EnumBuilderContext_value, 2);
cEnumBuilderContext = klass;
rb_gc_register_address(&cEnumBuilderContext); rb_gc_register_address(&cEnumBuilderContext);
cEnumBuilderContext = klass;
} }
/* /*
...@@ -1645,8 +1645,8 @@ void Builder_register(VALUE module) { ...@@ -1645,8 +1645,8 @@ void Builder_register(VALUE module) {
rb_define_method(klass, "add_enum", Builder_add_enum, 1); rb_define_method(klass, "add_enum", Builder_add_enum, 1);
rb_define_method(klass, "initialize", Builder_initialize, 0); rb_define_method(klass, "initialize", Builder_initialize, 0);
rb_define_method(klass, "finalize_to_pool", Builder_finalize_to_pool, 1); rb_define_method(klass, "finalize_to_pool", Builder_finalize_to_pool, 1);
cBuilder = klass;
rb_gc_register_address(&cBuilder); rb_gc_register_address(&cBuilder);
cBuilder = klass;
} }
/* /*
......
...@@ -825,8 +825,8 @@ VALUE Map_iter_value(Map_iter* iter) { ...@@ -825,8 +825,8 @@ VALUE Map_iter_value(Map_iter* iter) {
void Map_register(VALUE module) { void Map_register(VALUE module) {
VALUE klass = rb_define_class_under(module, "Map", rb_cObject); VALUE klass = rb_define_class_under(module, "Map", rb_cObject);
rb_define_alloc_func(klass, Map_alloc); rb_define_alloc_func(klass, Map_alloc);
cMap = klass;
rb_gc_register_address(&cMap); rb_gc_register_address(&cMap);
cMap = klass;
rb_define_method(klass, "initialize", Map_init, -1); rb_define_method(klass, "initialize", Map_init, -1);
rb_define_method(klass, "each", Map_each, 0); rb_define_method(klass, "each", Map_each, 0);
......
...@@ -626,8 +626,8 @@ void RepeatedField_register(VALUE module) { ...@@ -626,8 +626,8 @@ void RepeatedField_register(VALUE module) {
VALUE klass = rb_define_class_under( VALUE klass = rb_define_class_under(
module, "RepeatedField", rb_cObject); module, "RepeatedField", rb_cObject);
rb_define_alloc_func(klass, RepeatedField_alloc); rb_define_alloc_func(klass, RepeatedField_alloc);
cRepeatedField = klass;
rb_gc_register_address(&cRepeatedField); rb_gc_register_address(&cRepeatedField);
cRepeatedField = klass;
rb_define_method(klass, "initialize", rb_define_method(klass, "initialize",
RepeatedField_init, -1); RepeatedField_init, -1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment