Use TypedData_XXX instead of Data_XXX for GRPC::Core::Call

Data_XXX family is being deprecated in Ruby 2.x.
pull/1295/head
Yuki Yugui Sonoda 10 years ago
parent 0afc3addf4
commit 76801d2190
  1. 28
      src/ruby/ext/grpc/rb_call.c
  2. 5
      src/ruby/ext/grpc/rb_channel_args.c
  3. 4
      src/ruby/ext/grpc/rb_completion_queue.c
  4. 10
      src/ruby/ext/grpc/rb_grpc.c
  5. 8
      src/ruby/ext/grpc/rb_grpc.h

@ -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);
}

@ -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;

@ -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. */

@ -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);

@ -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);

Loading…
Cancel
Save