Use TypedData for GRPC::Core::ServerCredentials
diff --git a/src/ruby/ext/grpc/rb_server_credentials.c b/src/ruby/ext/grpc/rb_server_credentials.c
index 8b813ea..ab16c05 100644
--- a/src/ruby/ext/grpc/rb_server_credentials.c
+++ b/src/ruby/ext/grpc/rb_server_credentials.c
@@ -82,6 +82,14 @@
}
}
+static const rb_data_type_t grpc_rb_server_credentials_data_type = {
+ "grpc_server_credentials",
+ {grpc_rb_server_credentials_mark, grpc_rb_server_credentials_free,
+ GRPC_RB_MEMSIZE_UNAVAILABLE},
+ NULL, NULL,
+ RUBY_TYPED_FREE_IMMEDIATELY
+};
+
/* Allocates ServerCredential instances.
Provides safe initial defaults for the instance fields. */
@@ -89,8 +97,8 @@
grpc_rb_server_credentials *wrapper = ALLOC(grpc_rb_server_credentials);
wrapper->wrapped = NULL;
wrapper->mark = Qnil;
- return Data_Wrap_Struct(cls, grpc_rb_server_credentials_mark,
- grpc_rb_server_credentials_free, wrapper);
+ return TypedData_Wrap_Struct(cls, &grpc_rb_server_credentials_data_type,
+ wrapper);
}
/* Clones ServerCredentials instances.
@@ -112,8 +120,10 @@
rb_obj_classname(grpc_rb_cServerCredentials));
}
- Data_Get_Struct(orig, grpc_rb_server_credentials, orig_ch);
- Data_Get_Struct(copy, grpc_rb_server_credentials, copy_ch);
+ TypedData_Get_Struct(orig, grpc_rb_server_credentials,
+ &grpc_rb_server_credentials_data_type, orig_ch);
+ TypedData_Get_Struct(copy, grpc_rb_server_credentials,
+ &grpc_rb_server_credentials_data_type, copy_ch);
/* use ruby's MEMCPY to make a byte-for-byte copy of the server_credentials
wrapper object. */
@@ -149,7 +159,8 @@
grpc_rb_server_credentials *wrapper = NULL;
grpc_server_credentials *creds = NULL;
grpc_ssl_pem_key_cert_pair key_cert_pair = {NULL, NULL};
- Data_Get_Struct(self, grpc_rb_server_credentials, wrapper);
+ TypedData_Get_Struct(self, grpc_rb_server_credentials,
+ &grpc_rb_server_credentials_data_type, wrapper);
if (pem_cert_chain == Qnil) {
rb_raise(rb_eRuntimeError,
"could not create a server credential: nil pem_cert_chain");
@@ -206,6 +217,7 @@
/* Gets the wrapped grpc_server_credentials from the ruby wrapper */
grpc_server_credentials *grpc_rb_get_wrapped_server_credentials(VALUE v) {
grpc_rb_server_credentials *wrapper = NULL;
- Data_Get_Struct(v, grpc_rb_server_credentials, wrapper);
+ TypedData_Get_Struct(v, grpc_rb_server_credentials,
+ &grpc_rb_server_credentials_data_type, wrapper);
return wrapper->wrapped;
}