aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Yuki Yugui Sonoda <yugui@yugui.jp>2015-04-11 14:50:09 +0900
committerGravatar Yuki Yugui Sonoda <yugui@yugui.jp>2015-04-16 18:45:14 +0900
commitc9b7d1cb04485111a61e462fc93c52c64cc1007f (patch)
tree2a1c7b797c27059284cb342e9616d164854829ff /src
parent961f0bcc15e3b505ff58d8ea343dc99e8613326f (diff)
Use TypedData for GRPC::Core::Channel
Diffstat (limited to 'src')
-rw-r--r--src/ruby/ext/grpc/rb_channel.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/ruby/ext/grpc/rb_channel.c b/src/ruby/ext/grpc/rb_channel.c
index 3480280a03..47b85c83ed 100644
--- a/src/ruby/ext/grpc/rb_channel.c
+++ b/src/ruby/ext/grpc/rb_channel.c
@@ -103,13 +103,19 @@ static void grpc_rb_channel_mark(void *p) {
}
}
+static rb_data_type_t grpc_channel_data_type = {
+ "grpc_channel",
+ {grpc_rb_channel_mark, grpc_rb_channel_free, GRPC_RB_MEMSIZE_UNAVAILABLE},
+ NULL, NULL,
+ RUBY_TYPED_FREE_IMMEDIATELY
+};
+
/* Allocates grpc_rb_channel instances. */
static VALUE grpc_rb_channel_alloc(VALUE cls) {
grpc_rb_channel *wrapper = ALLOC(grpc_rb_channel);
wrapper->wrapped = NULL;
wrapper->mark = Qnil;
- return Data_Wrap_Struct(cls, grpc_rb_channel_mark, grpc_rb_channel_free,
- wrapper);
+ return TypedData_Wrap_Struct(cls, &grpc_channel_data_type, wrapper);
}
/*
@@ -133,7 +139,7 @@ static VALUE grpc_rb_channel_init(int argc, VALUE *argv, VALUE self) {
/* "21" == 2 mandatory args, 1 (credentials) is optional */
rb_scan_args(argc, argv, "21", &target, &channel_args, &credentials);
- Data_Get_Struct(self, grpc_rb_channel, wrapper);
+ TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
target_chars = StringValueCStr(target);
grpc_rb_hash_convert_to_channel_args(channel_args, &args);
if (credentials == Qnil) {
@@ -174,8 +180,8 @@ static VALUE grpc_rb_channel_init_copy(VALUE copy, VALUE orig) {
return Qnil;
}
- Data_Get_Struct(orig, grpc_rb_channel, orig_ch);
- Data_Get_Struct(copy, grpc_rb_channel, copy_ch);
+ TypedData_Get_Struct(orig, grpc_rb_channel, &grpc_channel_data_type, orig_ch);
+ TypedData_Get_Struct(copy, grpc_rb_channel, &grpc_channel_data_type, copy_ch);
/* use ruby's MEMCPY to make a byte-for-byte copy of the channel wrapper
* object. */
@@ -196,7 +202,7 @@ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE cqueue, VALUE method,
char *host_chars = StringValueCStr(host);
cq = grpc_rb_get_wrapped_completion_queue(cqueue);
- Data_Get_Struct(self, grpc_rb_channel, wrapper);
+ TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
ch = wrapper->wrapped;
if (ch == NULL) {
rb_raise(rb_eRuntimeError, "closed!");
@@ -229,7 +235,7 @@ static VALUE grpc_rb_channel_destroy(VALUE self) {
grpc_rb_channel *wrapper = NULL;
grpc_channel *ch = NULL;
- Data_Get_Struct(self, grpc_rb_channel, wrapper);
+ TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
ch = wrapper->wrapped;
if (ch != NULL) {
grpc_channel_destroy(ch);
@@ -278,6 +284,6 @@ void Init_grpc_channel() {
/* Gets the wrapped channel from the ruby wrapper */
grpc_channel *grpc_rb_get_wrapped_channel(VALUE v) {
grpc_rb_channel *wrapper = NULL;
- Data_Get_Struct(v, grpc_rb_channel, wrapper);
+ TypedData_Get_Struct(v, grpc_rb_channel, &grpc_channel_data_type, wrapper);
return wrapper->wrapped;
}