aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ruby
diff options
context:
space:
mode:
authorGravatar Yuki Yugui Sonoda <yugui@yugui.jp>2015-04-11 14:20:27 +0900
committerGravatar Yuki Yugui Sonoda <yugui@yugui.jp>2015-04-16 18:45:13 +0900
commit76801d21903b6cbe08ed456045a087c7ceff1b82 (patch)
treebe7c512a1088df1082a5309c325f5891ae418a86 /src/ruby
parent0afc3addf4b438d32ab9a7424c0ae588a1c8e212 (diff)
Use TypedData_XXX instead of Data_XXX for GRPC::Core::Call
Data_XXX family is being deprecated in Ruby 2.x.
Diffstat (limited to 'src/ruby')
-rw-r--r--src/ruby/ext/grpc/rb_call.c28
-rw-r--r--src/ruby/ext/grpc/rb_channel_args.c5
-rw-r--r--src/ruby/ext/grpc/rb_completion_queue.c4
-rw-r--r--src/ruby/ext/grpc/rb_grpc.c10
-rw-r--r--src/ruby/ext/grpc/rb_grpc.h8
5 files changed, 34 insertions, 21 deletions
diff --git a/src/ruby/ext/grpc/rb_call.c b/src/ruby/ext/grpc/rb_call.c
index 1b1958fd26..c8cfc45c69 100644
--- a/src/ruby/ext/grpc/rb_call.c
+++ b/src/ruby/ext/grpc/rb_call.c
@@ -86,7 +86,7 @@ static VALUE sym_cancelled;
static VALUE hash_all_calls;
/* Destroys a Call. */
-void grpc_rb_call_destroy(void *p) {
+static void grpc_rb_call_destroy(void *p) {
grpc_call *call = NULL;
VALUE ref_count = Qnil;
if (p == NULL) {
@@ -106,6 +106,18 @@ void grpc_rb_call_destroy(void *p) {
}
}
+/* Describes grpc_call struct for RTypedData */
+static const rb_data_type_t grpc_call_data_type = {
+ "grpc_call",
+ {GRPC_RB_GC_NOT_MARKED, grpc_rb_call_destroy, GRPC_RB_MEMSIZE_UNAVAILABLE},
+ NULL, NULL,
+ /* 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
+};
+
/* Error code details is a hash containing text strings describing errors */
VALUE rb_error_code_details;
@@ -124,7 +136,7 @@ const char *grpc_call_error_detail_of(grpc_call_error err) {
static VALUE grpc_rb_call_cancel(VALUE self) {
grpc_call *call = NULL;
grpc_call_error err;
- Data_Get_Struct(self, grpc_call, call);
+ TypedData_Get_Struct(self, grpc_call, &grpc_call_data_type, call);
err = grpc_call_cancel(call);
if (err != GRPC_CALL_OK) {
rb_raise(grpc_rb_eCallError, "cancel failed: %s (code=%d)",
@@ -258,8 +270,9 @@ void grpc_rb_md_ary_convert(VALUE md_ary_hash, grpc_metadata_array *md_ary) {
/* Initialize the array, compute it's capacity, then fill it. */
grpc_metadata_array_init(md_ary);
- md_ary_obj =
- Data_Wrap_Struct(grpc_rb_cMdAry, GC_NOT_MARKED, GC_DONT_FREE, md_ary);
+ md_ary_obj = Data_Wrap_Struct(grpc_rb_cMdAry,
+ GRPC_RB_GC_NOT_MARKED, GRPC_RB_GC_DONT_FREE,
+ md_ary);
rb_hash_foreach(md_ary_hash, grpc_rb_md_ary_capacity_hash_cb, md_ary_obj);
md_ary->metadata = gpr_malloc(md_ary->capacity * sizeof(grpc_metadata));
rb_hash_foreach(md_ary_hash, grpc_rb_md_ary_fill_hash_cb, md_ary_obj);
@@ -543,7 +556,7 @@ static VALUE grpc_rb_call_run_batch(VALUE self, VALUE cqueue, VALUE tag,
grpc_event *ev = NULL;
grpc_call_error err;
VALUE result = Qnil;
- Data_Get_Struct(self, grpc_call, call);
+ TypedData_Get_Struct(self, grpc_call, &grpc_call_data_type, call);
/* Validate the ops args, adding them to a ruby array */
if (TYPE(ops_hash) != T_HASH) {
@@ -734,7 +747,7 @@ void Init_grpc_call() {
/* Gets the call from the ruby object */
grpc_call *grpc_rb_get_wrapped_call(VALUE v) {
grpc_call *c = NULL;
- Data_Get_Struct(v, grpc_call, c);
+ TypedData_Get_Struct(v, grpc_call, &grpc_call_data_type, c);
return c;
}
@@ -751,6 +764,5 @@ VALUE grpc_rb_wrap_call(grpc_call *c) {
rb_hash_aset(hash_all_calls, OFFT2NUM((VALUE)c),
UINT2NUM(NUM2UINT(obj) + 1));
}
- return Data_Wrap_Struct(grpc_rb_cCall, GC_NOT_MARKED,
- grpc_rb_call_destroy, c);
+ return TypedData_Wrap_Struct(grpc_rb_cCall, &grpc_call_data_type, c);
}
diff --git a/src/ruby/ext/grpc/rb_channel_args.c b/src/ruby/ext/grpc/rb_channel_args.c
index 9b92ec1514..0e2cdac1a1 100644
--- a/src/ruby/ext/grpc/rb_channel_args.c
+++ b/src/ruby/ext/grpc/rb_channel_args.c
@@ -126,8 +126,9 @@ static VALUE grpc_rb_hash_convert_to_channel_args0(VALUE as_value) {
MEMZERO(params->dst->args, grpc_arg, num_args);
rb_hash_foreach(params->src_hash,
grpc_rb_channel_create_in_process_add_args_hash_cb,
- Data_Wrap_Struct(grpc_rb_cChannelArgs, GC_NOT_MARKED,
- GC_DONT_FREE, params->dst));
+ Data_Wrap_Struct(grpc_rb_cChannelArgs,
+ GRPC_RB_GC_NOT_MARKED,
+ GRPC_RB_GC_DONT_FREE, params->dst));
/* reset num_args as grpc_rb_channel_create_in_process_add_args_hash_cb
* decrements it during has processing */
params->dst->num_args = num_args;
diff --git a/src/ruby/ext/grpc/rb_completion_queue.c b/src/ruby/ext/grpc/rb_completion_queue.c
index 20ce1b909c..bfa2a28a4b 100644
--- a/src/ruby/ext/grpc/rb_completion_queue.c
+++ b/src/ruby/ext/grpc/rb_completion_queue.c
@@ -118,8 +118,8 @@ static VALUE grpc_rb_completion_queue_alloc(VALUE cls) {
if (cq == NULL) {
rb_raise(rb_eArgError, "could not create a completion queue: not sure why");
}
- return Data_Wrap_Struct(cls, GC_NOT_MARKED, grpc_rb_completion_queue_destroy,
- cq);
+ return Data_Wrap_Struct(cls, GRPC_RB_GC_NOT_MARKED,
+ grpc_rb_completion_queue_destroy, cq);
}
/* Blocks until the next event is available, and returns the event. */
diff --git a/src/ruby/ext/grpc/rb_grpc.c b/src/ruby/ext/grpc/rb_grpc.c
index 4f30a6216a..e721a9b3e7 100644
--- a/src/ruby/ext/grpc/rb_grpc.c
+++ b/src/ruby/ext/grpc/rb_grpc.c
@@ -46,10 +46,6 @@
#include "rb_credentials.h"
#include "rb_server_credentials.h"
-/* Define common vars and funcs declared in rb.h */
-const RUBY_DATA_FUNC GC_NOT_MARKED = NULL;
-const RUBY_DATA_FUNC GC_DONT_FREE = NULL;
-
VALUE grpc_rb_cTimeVal = Qnil;
/* Alloc func that blocks allocation of a given object by raising an
@@ -224,15 +220,15 @@ void Init_grpc_time_consts() {
rb_define_class_under(grpc_rb_mGrpcCore, "TimeSpec", rb_cObject);
rb_define_const(grpc_rb_mTimeConsts, "ZERO",
Data_Wrap_Struct(grpc_rb_cTimeVal,
- GC_NOT_MARKED, GC_DONT_FREE,
+ GRPC_RB_GC_NOT_MARKED, GRPC_RB_GC_DONT_FREE,
(void *)&gpr_time_0));
rb_define_const(grpc_rb_mTimeConsts, "INFINITE_FUTURE",
Data_Wrap_Struct(grpc_rb_cTimeVal,
- GC_NOT_MARKED, GC_DONT_FREE,
+ GRPC_RB_GC_NOT_MARKED, GRPC_RB_GC_DONT_FREE,
(void *)&gpr_inf_future));
rb_define_const(grpc_rb_mTimeConsts, "INFINITE_PAST",
Data_Wrap_Struct(grpc_rb_cTimeVal,
- GC_NOT_MARKED, GC_DONT_FREE,
+ GRPC_RB_GC_NOT_MARKED, GRPC_RB_GC_DONT_FREE,
(void *)&gpr_inf_past));
rb_define_method(grpc_rb_cTimeVal, "to_time", grpc_rb_time_val_to_time, 0);
rb_define_method(grpc_rb_cTimeVal, "inspect", grpc_rb_time_val_inspect, 0);
diff --git a/src/ruby/ext/grpc/rb_grpc.h b/src/ruby/ext/grpc/rb_grpc.h
index 3a93029556..57db350f5e 100644
--- a/src/ruby/ext/grpc/rb_grpc.h
+++ b/src/ruby/ext/grpc/rb_grpc.h
@@ -61,12 +61,16 @@ VALUE sym_metadata;
/* GC_NOT_MARKED is used in calls to Data_Wrap_Struct to indicate that the
wrapped struct does not need to participate in ruby gc. */
-extern const RUBY_DATA_FUNC GC_NOT_MARKED;
+#define GRPC_RB_GC_NOT_MARKED (RUBY_DATA_FUNC)(NULL)
/* GC_DONT_FREED is used in calls to Data_Wrap_Struct to indicate that the
wrapped struct should not be freed the wrapped ruby object is released by
the garbage collector. */
-extern const RUBY_DATA_FUNC GC_DONT_FREE;
+#define GRPC_RB_GC_DONT_FREE (RUBY_DATA_FUNC)(NULL)
+
+/* GRPC_RB_MEMSIZE_UNAVAILABLE is used in rb_data_type_t to indicate that the
+ * number of bytes used by the wrapped struct is not available. */
+#define GRPC_RB_MEMSIZE_UNAVAILABLE (size_t (*)(const void*))(NULL)
/* A ruby object alloc func that fails by raising an exception. */
VALUE grpc_rb_cannot_alloc(VALUE cls);