Remove Ruby copy initializers. They don't make sense with wrapped structs, and we don't use them anyway

pull/6886/head
murgatroid99 9 years ago
parent e5d37dd50e
commit cc0f4e1c80
  1. 31
      src/ruby/ext/grpc/rb_call_credentials.c
  2. 30
      src/ruby/ext/grpc/rb_channel.c
  3. 32
      src/ruby/ext/grpc/rb_channel_credentials.c
  4. 2
      src/ruby/ext/grpc/rb_grpc.c
  5. 31
      src/ruby/ext/grpc/rb_server.c
  6. 32
      src/ruby/ext/grpc/rb_server_credentials.c

@ -211,35 +211,6 @@ VALUE grpc_rb_wrap_call_credentials(grpc_call_credentials *c, VALUE mark) {
return rb_wrapper; return rb_wrapper;
} }
/* Clones CallCredentials instances.
Gives CallCredentials a consistent implementation of Ruby's object copy/dup
protocol. */
static VALUE grpc_rb_call_credentials_init_copy(VALUE copy, VALUE orig) {
grpc_rb_call_credentials *orig_cred = NULL;
grpc_rb_call_credentials *copy_cred = NULL;
if (copy == orig) {
return copy;
}
/* Raise an error if orig is not a credentials object or a subclass. */
if (TYPE(orig) != T_DATA ||
RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_call_credentials_free) {
rb_raise(rb_eTypeError, "not a %s",
rb_obj_classname(grpc_rb_cCallCredentials));
}
TypedData_Get_Struct(orig, grpc_rb_call_credentials,
&grpc_rb_call_credentials_data_type, orig_cred);
TypedData_Get_Struct(copy, grpc_rb_call_credentials,
&grpc_rb_call_credentials_data_type, copy_cred);
/* use ruby's MEMCPY to make a byte-for-byte copy of the credentials
* wrapper object. */
MEMCPY(copy_cred, orig_cred, grpc_rb_call_credentials, 1);
return copy;
}
/* The attribute used on the mark object to hold the callback */ /* The attribute used on the mark object to hold the callback */
static ID id_callback; static ID id_callback;
@ -308,7 +279,7 @@ void Init_grpc_call_credentials() {
rb_define_method(grpc_rb_cCallCredentials, "initialize", rb_define_method(grpc_rb_cCallCredentials, "initialize",
grpc_rb_call_credentials_init, 1); grpc_rb_call_credentials_init, 1);
rb_define_method(grpc_rb_cCallCredentials, "initialize_copy", rb_define_method(grpc_rb_cCallCredentials, "initialize_copy",
grpc_rb_call_credentials_init_copy, 1); grpc_rb_cannot_init_copy, 1);
rb_define_method(grpc_rb_cCallCredentials, "compose", rb_define_method(grpc_rb_cCallCredentials, "compose",
grpc_rb_call_credentials_compose, -1); grpc_rb_call_credentials_compose, -1);

@ -231,34 +231,6 @@ static VALUE grpc_rb_channel_watch_connectivity_state(VALUE self,
return Qnil; return Qnil;
} }
/* Clones Channel instances.
Gives Channel a consistent implementation of Ruby's object copy/dup
protocol. */
static VALUE grpc_rb_channel_init_copy(VALUE copy, VALUE orig) {
grpc_rb_channel *orig_ch = NULL;
grpc_rb_channel *copy_ch = NULL;
if (copy == orig) {
return copy;
}
/* Raise an error if orig is not a channel object or a subclass. */
if (TYPE(orig) != T_DATA ||
RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_channel_free) {
rb_raise(rb_eTypeError, "not a %s", rb_obj_classname(grpc_rb_cChannel));
return Qnil;
}
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. */
MEMCPY(copy_ch, orig_ch, grpc_rb_channel, 1);
return copy;
}
/* Create a call given a grpc_channel, in order to call method. The request /* Create a call given a grpc_channel, in order to call method. The request
is not sent until grpc_call_invoke is called. */ is not sent until grpc_call_invoke is called. */
static VALUE grpc_rb_channel_create_call(VALUE self, VALUE cqueue, static VALUE grpc_rb_channel_create_call(VALUE self, VALUE cqueue,
@ -387,7 +359,7 @@ void Init_grpc_channel() {
/* Provides a ruby constructor and support for dup/clone. */ /* Provides a ruby constructor and support for dup/clone. */
rb_define_method(grpc_rb_cChannel, "initialize", grpc_rb_channel_init, -1); rb_define_method(grpc_rb_cChannel, "initialize", grpc_rb_channel_init, -1);
rb_define_method(grpc_rb_cChannel, "initialize_copy", rb_define_method(grpc_rb_cChannel, "initialize_copy",
grpc_rb_channel_init_copy, 1); grpc_rb_cannot_init_copy, 1);
/* Add ruby analogues of the Channel methods. */ /* Add ruby analogues of the Channel methods. */
rb_define_method(grpc_rb_cChannel, "connectivity_state", rb_define_method(grpc_rb_cChannel, "connectivity_state",

@ -126,36 +126,6 @@ VALUE grpc_rb_wrap_channel_credentials(grpc_channel_credentials *c, VALUE mark)
return rb_wrapper; return rb_wrapper;
} }
/* Clones ChannelCredentials instances.
Gives ChannelCredentials a consistent implementation of Ruby's object copy/dup
protocol. */
static VALUE grpc_rb_channel_credentials_init_copy(VALUE copy, VALUE orig) {
grpc_rb_channel_credentials *orig_cred = NULL;
grpc_rb_channel_credentials *copy_cred = NULL;
if (copy == orig) {
return copy;
}
/* Raise an error if orig is not a credentials object or a subclass. */
if (TYPE(orig) != T_DATA ||
RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_channel_credentials_free) {
rb_raise(rb_eTypeError, "not a %s",
rb_obj_classname(grpc_rb_cChannelCredentials));
}
TypedData_Get_Struct(orig, grpc_rb_channel_credentials,
&grpc_rb_channel_credentials_data_type, orig_cred);
TypedData_Get_Struct(copy, grpc_rb_channel_credentials,
&grpc_rb_channel_credentials_data_type, copy_cred);
/* use ruby's MEMCPY to make a byte-for-byte copy of the credentials
* wrapper object. */
MEMCPY(copy_cred, orig_cred, grpc_rb_channel_credentials, 1);
return copy;
}
/* The attribute used on the mark object to hold the pem_root_certs. */ /* The attribute used on the mark object to hold the pem_root_certs. */
static ID id_pem_root_certs; static ID id_pem_root_certs;
@ -271,7 +241,7 @@ void Init_grpc_channel_credentials() {
rb_define_method(grpc_rb_cChannelCredentials, "initialize", rb_define_method(grpc_rb_cChannelCredentials, "initialize",
grpc_rb_channel_credentials_init, -1); grpc_rb_channel_credentials_init, -1);
rb_define_method(grpc_rb_cChannelCredentials, "initialize_copy", rb_define_method(grpc_rb_cChannelCredentials, "initialize_copy",
grpc_rb_channel_credentials_init_copy, 1); grpc_rb_cannot_init_copy, 1);
rb_define_method(grpc_rb_cChannelCredentials, "compose", rb_define_method(grpc_rb_cChannelCredentials, "compose",
grpc_rb_channel_credentials_compose, -1); grpc_rb_channel_credentials_compose, -1);
rb_define_module_function(grpc_rb_cChannelCredentials, rb_define_module_function(grpc_rb_cChannelCredentials,

@ -85,7 +85,7 @@ VALUE grpc_rb_cannot_init(VALUE self) {
VALUE grpc_rb_cannot_init_copy(VALUE copy, VALUE self) { VALUE grpc_rb_cannot_init_copy(VALUE copy, VALUE self) {
(void)self; (void)self;
rb_raise(rb_eTypeError, rb_raise(rb_eTypeError,
"initialization of %s only allowed from the gRPC native layer", "Copy initialization of %s is not supported",
rb_obj_classname(copy)); rb_obj_classname(copy));
return Qnil; return Qnil;
} }

@ -154,35 +154,6 @@ static VALUE grpc_rb_server_init(VALUE self, VALUE cqueue, VALUE channel_args) {
return self; return self;
} }
/* Clones Server instances.
Gives Server a consistent implementation of Ruby's object copy/dup
protocol. */
static VALUE grpc_rb_server_init_copy(VALUE copy, VALUE orig) {
grpc_rb_server *orig_srv = NULL;
grpc_rb_server *copy_srv = NULL;
if (copy == orig) {
return copy;
}
/* Raise an error if orig is not a server object or a subclass. */
if (TYPE(orig) != T_DATA ||
RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_server_free) {
rb_raise(rb_eTypeError, "not a %s", rb_obj_classname(grpc_rb_cServer));
}
TypedData_Get_Struct(orig, grpc_rb_server, &grpc_rb_server_data_type,
orig_srv);
TypedData_Get_Struct(copy, grpc_rb_server, &grpc_rb_server_data_type,
copy_srv);
/* use ruby's MEMCPY to make a byte-for-byte copy of the server wrapper
object. */
MEMCPY(copy_srv, orig_srv, grpc_rb_server, 1);
return copy;
}
/* request_call_stack holds various values used by the /* request_call_stack holds various values used by the
* grpc_rb_server_request_call function */ * grpc_rb_server_request_call function */
typedef struct request_call_stack { typedef struct request_call_stack {
@ -378,7 +349,7 @@ void Init_grpc_server() {
/* Provides a ruby constructor and support for dup/clone. */ /* Provides a ruby constructor and support for dup/clone. */
rb_define_method(grpc_rb_cServer, "initialize", grpc_rb_server_init, 2); rb_define_method(grpc_rb_cServer, "initialize", grpc_rb_server_init, 2);
rb_define_method(grpc_rb_cServer, "initialize_copy", rb_define_method(grpc_rb_cServer, "initialize_copy",
grpc_rb_server_init_copy, 1); grpc_rb_cannot_init_copy, 1);
/* Add the server methods. */ /* Add the server methods. */
rb_define_method(grpc_rb_cServer, "request_call", rb_define_method(grpc_rb_cServer, "request_call",

@ -111,36 +111,6 @@ static VALUE grpc_rb_server_credentials_alloc(VALUE cls) {
wrapper); wrapper);
} }
/* Clones ServerCredentials instances.
Gives ServerCredentials a consistent implementation of Ruby's object copy/dup
protocol. */
static VALUE grpc_rb_server_credentials_init_copy(VALUE copy, VALUE orig) {
grpc_rb_server_credentials *orig_ch = NULL;
grpc_rb_server_credentials *copy_ch = NULL;
if (copy == orig) {
return copy;
}
/* Raise an error if orig is not a server_credentials object or a subclass. */
if (TYPE(orig) != T_DATA ||
RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_server_credentials_free) {
rb_raise(rb_eTypeError, "not a %s",
rb_obj_classname(grpc_rb_cServerCredentials));
}
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. */
MEMCPY(copy_ch, orig_ch, grpc_rb_server_credentials, 1);
return copy;
}
/* The attribute used on the mark object to preserve the pem_root_certs. */ /* The attribute used on the mark object to preserve the pem_root_certs. */
static ID id_pem_root_certs; static ID id_pem_root_certs;
@ -270,7 +240,7 @@ void Init_grpc_server_credentials() {
rb_define_method(grpc_rb_cServerCredentials, "initialize", rb_define_method(grpc_rb_cServerCredentials, "initialize",
grpc_rb_server_credentials_init, 3); grpc_rb_server_credentials_init, 3);
rb_define_method(grpc_rb_cServerCredentials, "initialize_copy", rb_define_method(grpc_rb_cServerCredentials, "initialize_copy",
grpc_rb_server_credentials_init_copy, 1); grpc_rb_cannot_init_copy, 1);
id_pem_key_certs = rb_intern("__pem_key_certs"); id_pem_key_certs = rb_intern("__pem_key_certs");
id_pem_root_certs = rb_intern("__pem_root_certs"); id_pem_root_certs = rb_intern("__pem_root_certs");

Loading…
Cancel
Save