diff --git a/src/ruby/ext/grpc/rb_call.c b/src/ruby/ext/grpc/rb_call.c index 0f3b33da80166..6d8d76c630104 100644 --- a/src/ruby/ext/grpc/rb_call.c +++ b/src/ruby/ext/grpc/rb_call.c @@ -111,14 +111,12 @@ const rb_data_type_t grpc_rb_md_ary_data_type = { {NULL, NULL}}, NULL, NULL, -#ifdef RUBY_TYPED_FREE_IMMEDIATELY /* it is unsafe to specify RUBY_TYPED_FREE_IMMEDIATELY because * grpc_rb_call_destroy * touches a hash object. * TODO(yugui) Directly use st_table and call the free function earlier? */ 0, -#endif }; /* Describes grpc_call struct for RTypedData */ @@ -129,9 +127,7 @@ static const rb_data_type_t grpc_call_data_type = {"grpc_call", {NULL, NULL}}, NULL, NULL, -#ifdef RUBY_TYPED_FREE_IMMEDIATELY RUBY_TYPED_FREE_IMMEDIATELY -#endif }; /* Error code details is a hash containing text strings describing errors */ diff --git a/src/ruby/ext/grpc/rb_call_credentials.c b/src/ruby/ext/grpc/rb_call_credentials.c index 9957f3937e76c..d42d454bf956a 100644 --- a/src/ruby/ext/grpc/rb_call_credentials.c +++ b/src/ruby/ext/grpc/rb_call_credentials.c @@ -40,7 +40,8 @@ static VALUE grpc_rb_cCallCredentials = Qnil; * object that is used to hold references to any objects used to create the * credentials. */ typedef struct grpc_rb_call_credentials { - /* Holder of ruby objects involved in contructing the credentials */ + /* Holder of ruby objects involved in contructing the credentials. + Must be written using RB_OBJ_WRITE for proper write barriers */ VALUE mark; /* The actual credentials */ @@ -171,6 +172,8 @@ static int grpc_rb_call_credentials_plugin_get_metadata( size_t* num_creds_md, grpc_status_code* status, const char** error_details) { callback_params* params = gpr_zalloc(sizeof(callback_params)); + // FIXME: do we need to call a gc function for this VALUE? This + // callback_params doesn't have a corresponding rb_data_type_t. params->get_metadata = (VALUE)state; grpc_auth_metadata_context_copy(&context, ¶ms->context); params->user_data = user_data; @@ -222,9 +225,7 @@ static rb_data_type_t grpc_rb_call_credentials_data_type = { {NULL, NULL}}, NULL, NULL, -#ifdef RUBY_TYPED_FREE_IMMEDIATELY - RUBY_TYPED_FREE_IMMEDIATELY -#endif + RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED }; /* Allocates CallCredentials instances. @@ -251,7 +252,7 @@ VALUE grpc_rb_wrap_call_credentials(grpc_call_credentials* c, VALUE mark) { TypedData_Get_Struct(rb_wrapper, grpc_rb_call_credentials, &grpc_rb_call_credentials_data_type, wrapper); wrapper->wrapped = c; - wrapper->mark = mark; + RB_OBJ_WRITE(rb_wrapper, &wrapper->mark, mark); return rb_wrapper; } @@ -289,7 +290,7 @@ static VALUE grpc_rb_call_credentials_init(VALUE self, VALUE proc) { return Qnil; } - wrapper->mark = proc; + RB_OBJ_WRITE(self, &wrapper->mark, proc); wrapper->wrapped = creds; rb_ivar_set(self, id_callback, proc); diff --git a/src/ruby/ext/grpc/rb_channel.c b/src/ruby/ext/grpc/rb_channel.c index 76d2f39f17d3a..c83811acf35a2 100644 --- a/src/ruby/ext/grpc/rb_channel.c +++ b/src/ruby/ext/grpc/rb_channel.c @@ -69,6 +69,7 @@ typedef struct bg_watched_channel { /* grpc_rb_channel wraps a grpc_channel. */ typedef struct grpc_rb_channel { + /* Ruby VALUE that must be written using RB_OBJ_WRITE for proper write barriers */ VALUE credentials; grpc_channel_args args; /* The actual channel (protected in a wrapper to tell when it's safe to @@ -188,9 +189,7 @@ static rb_data_type_t grpc_channel_data_type = {"grpc_channel", {NULL, NULL}}, NULL, NULL, -#ifdef RUBY_TYPED_FREE_IMMEDIATELY - RUBY_TYPED_FREE_IMMEDIATELY -#endif + RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED }; /* Allocates grpc_rb_channel instances. */ @@ -239,7 +238,7 @@ static VALUE grpc_rb_channel_init(int argc, VALUE* argv, VALUE self) { ch = grpc_channel_create(target_chars, insecure_creds, &wrapper->args); grpc_channel_credentials_release(insecure_creds); } else { - wrapper->credentials = credentials; + RB_OBJ_WRITE(self, &wrapper->credentials, credentials); if (grpc_rb_is_channel_credentials(credentials)) { creds = grpc_rb_get_wrapped_channel_credentials(credentials); } else if (grpc_rb_is_xds_channel_credentials(credentials)) { diff --git a/src/ruby/ext/grpc/rb_channel_args.c b/src/ruby/ext/grpc/rb_channel_args.c index d7f67297be601..7da02072006a3 100644 --- a/src/ruby/ext/grpc/rb_channel_args.c +++ b/src/ruby/ext/grpc/rb_channel_args.c @@ -36,9 +36,7 @@ static rb_data_type_t grpc_rb_channel_args_data_type = { {NULL, NULL}}, NULL, NULL, -#ifdef RUBY_TYPED_FREE_IMMEDIATELY RUBY_TYPED_FREE_IMMEDIATELY -#endif }; /* A callback the processes the hash key values in channel_args hash */ diff --git a/src/ruby/ext/grpc/rb_channel_credentials.c b/src/ruby/ext/grpc/rb_channel_credentials.c index 9b1931954becd..7d5f755ac7432 100644 --- a/src/ruby/ext/grpc/rb_channel_credentials.c +++ b/src/ruby/ext/grpc/rb_channel_credentials.c @@ -41,7 +41,8 @@ static char* pem_root_certs = NULL; * mark object that is used to hold references to any objects used to create * the credentials. */ typedef struct grpc_rb_channel_credentials { - /* Holder of ruby objects involved in constructing the credentials */ + /* Holder of ruby objects involved in constructing the credentials. + Must be written using RB_OBJ_WRITE for proper write barriers */ VALUE mark; /* The actual credentials */ @@ -86,9 +87,7 @@ static rb_data_type_t grpc_rb_channel_credentials_data_type = { {NULL, NULL}}, NULL, NULL, -#ifdef RUBY_TYPED_FREE_IMMEDIATELY - RUBY_TYPED_FREE_IMMEDIATELY -#endif + RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED }; /* Allocates ChannelCredential instances. @@ -116,7 +115,7 @@ VALUE grpc_rb_wrap_channel_credentials(grpc_channel_credentials* c, TypedData_Get_Struct(rb_wrapper, grpc_rb_channel_credentials, &grpc_rb_channel_credentials_data_type, wrapper); wrapper->wrapped = c; - wrapper->mark = mark; + RB_OBJ_WRITE(rb_wrapper, &wrapper->mark, mark); return rb_wrapper; } diff --git a/src/ruby/ext/grpc/rb_compression_options.c b/src/ruby/ext/grpc/rb_compression_options.c index 062d5362c3e70..704c7c2532a4b 100644 --- a/src/ruby/ext/grpc/rb_compression_options.c +++ b/src/ruby/ext/grpc/rb_compression_options.c @@ -80,9 +80,7 @@ static rb_data_type_t grpc_rb_compression_options_data_type = { {NULL, NULL}}, NULL, NULL, -#ifdef RUBY_TYPED_FREE_IMMEDIATELY RUBY_TYPED_FREE_IMMEDIATELY -#endif }; /* Allocates CompressionOptions instances. diff --git a/src/ruby/ext/grpc/rb_grpc.c b/src/ruby/ext/grpc/rb_grpc.c index ac66b5907821a..06c3940e36ff0 100644 --- a/src/ruby/ext/grpc/rb_grpc.c +++ b/src/ruby/ext/grpc/rb_grpc.c @@ -57,9 +57,7 @@ static rb_data_type_t grpc_rb_timespec_data_type = { {NULL, NULL}}, NULL, NULL, -#ifdef RUBY_TYPED_FREE_IMMEDIATELY RUBY_TYPED_FREE_IMMEDIATELY -#endif }; /* Alloc func that blocks allocation of a given object by raising an diff --git a/src/ruby/ext/grpc/rb_server.c b/src/ruby/ext/grpc/rb_server.c index f80b40ae70e5a..4446310a2001a 100644 --- a/src/ruby/ext/grpc/rb_server.c +++ b/src/ruby/ext/grpc/rb_server.c @@ -116,13 +116,11 @@ static const rb_data_type_t grpc_rb_server_data_type = { {NULL, NULL}}, NULL, NULL, -#ifdef RUBY_TYPED_FREE_IMMEDIATELY /* It is unsafe to specify RUBY_TYPED_FREE_IMMEDIATELY because the free * function would block and we might want to unlock GVL * TODO(yugui) Unlock GVL? */ 0, -#endif }; /* Allocates grpc_rb_server instances. */ diff --git a/src/ruby/ext/grpc/rb_server_credentials.c b/src/ruby/ext/grpc/rb_server_credentials.c index 121f888f897c5..7816a309c5854 100644 --- a/src/ruby/ext/grpc/rb_server_credentials.c +++ b/src/ruby/ext/grpc/rb_server_credentials.c @@ -87,9 +87,7 @@ static const rb_data_type_t grpc_rb_server_credentials_data_type = { {NULL, NULL}}, NULL, NULL, -#ifdef RUBY_TYPED_FREE_IMMEDIATELY RUBY_TYPED_FREE_IMMEDIATELY -#endif }; /* Allocates ServerCredential instances. diff --git a/src/ruby/ext/grpc/rb_xds_channel_credentials.c b/src/ruby/ext/grpc/rb_xds_channel_credentials.c index 124bc8b3378bb..7f8b8d0f1938b 100644 --- a/src/ruby/ext/grpc/rb_xds_channel_credentials.c +++ b/src/ruby/ext/grpc/rb_xds_channel_credentials.c @@ -40,7 +40,8 @@ static VALUE grpc_rb_cXdsChannelCredentials = Qnil; * provides a mark object that is used to hold references to any objects used to * create the credentials. */ typedef struct grpc_rb_xds_channel_credentials { - /* Holder of ruby objects involved in constructing the credentials */ + /* Holder of ruby objects involved in constructing the credentials. + Must be written using RB_OBJ_WRITE for proper write barriers */ VALUE mark; /* The actual credentials */ @@ -83,9 +84,7 @@ static rb_data_type_t grpc_rb_xds_channel_credentials_data_type = { GRPC_RB_MEMSIZE_UNAVAILABLE, NULL}, NULL, NULL, -#ifdef RUBY_TYPED_FREE_IMMEDIATELY - RUBY_TYPED_FREE_IMMEDIATELY -#endif + RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED }; /* Allocates ChannelCredential instances. @@ -114,7 +113,7 @@ VALUE grpc_rb_xds_wrap_channel_credentials(grpc_channel_credentials* c, TypedData_Get_Struct(rb_wrapper, grpc_rb_xds_channel_credentials, &grpc_rb_xds_channel_credentials_data_type, wrapper); wrapper->wrapped = c; - wrapper->mark = mark; + RB_OBJ_WRITE(rb_wrapper, &wrapper->mark, mark); return rb_wrapper; } diff --git a/src/ruby/ext/grpc/rb_xds_server_credentials.c b/src/ruby/ext/grpc/rb_xds_server_credentials.c index 703e3e99b4b36..1b6b4fd79f116 100644 --- a/src/ruby/ext/grpc/rb_xds_server_credentials.c +++ b/src/ruby/ext/grpc/rb_xds_server_credentials.c @@ -85,9 +85,7 @@ static const rb_data_type_t grpc_rb_xds_server_credentials_data_type = { GRPC_RB_MEMSIZE_UNAVAILABLE, NULL}, NULL, NULL, -#ifdef RUBY_TYPED_FREE_IMMEDIATELY RUBY_TYPED_FREE_IMMEDIATELY -#endif }; /* Allocates ServerCredential instances.