diff options
author | Yuki Yugui Sonoda <yugui@yugui.jp> | 2015-04-11 15:25:16 +0900 |
---|---|---|
committer | Yuki Yugui Sonoda <yugui@yugui.jp> | 2015-04-16 18:45:14 +0900 |
commit | a87924e646673276d5a0f8302800e486be7b0105 (patch) | |
tree | 71ed8240cefa772d9e0ebfd49c60a8c394f0b953 /src/ruby | |
parent | bf256ae07a492ddca6ee59164cf27f8a13d6a3db (diff) |
Use TypedData for GRPC::Core::Credentials
Diffstat (limited to 'src/ruby')
-rw-r--r-- | src/ruby/ext/grpc/rb_credentials.c | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/src/ruby/ext/grpc/rb_credentials.c b/src/ruby/ext/grpc/rb_credentials.c index 1504a4884e..8170f0d26c 100644 --- a/src/ruby/ext/grpc/rb_credentials.c +++ b/src/ruby/ext/grpc/rb_credentials.c @@ -83,14 +83,21 @@ static void grpc_rb_credentials_mark(void *p) { } } +static rb_data_type_t grpc_rb_credentials_data_type = { + "grpc_credentials", + {grpc_rb_credentials_mark, grpc_rb_credentials_free, + GRPC_RB_MEMSIZE_UNAVAILABLE}, + NULL, + NULL, + RUBY_TYPED_FREE_IMMEDIATELY}; + /* Allocates Credential instances. Provides safe initial defaults for the instance fields. */ static VALUE grpc_rb_credentials_alloc(VALUE cls) { grpc_rb_credentials *wrapper = ALLOC(grpc_rb_credentials); wrapper->wrapped = NULL; wrapper->mark = Qnil; - return Data_Wrap_Struct(cls, grpc_rb_credentials_mark, - grpc_rb_credentials_free, wrapper); + return TypedData_Wrap_Struct(cls, &grpc_rb_credentials_data_type, wrapper); } /* Clones Credentials instances. @@ -110,8 +117,10 @@ static VALUE grpc_rb_credentials_init_copy(VALUE copy, VALUE orig) { rb_raise(rb_eTypeError, "not a %s", rb_obj_classname(grpc_rb_cCredentials)); } - Data_Get_Struct(orig, grpc_rb_credentials, orig_cred); - Data_Get_Struct(copy, grpc_rb_credentials, copy_cred); + TypedData_Get_Struct(orig, grpc_rb_credentials, + &grpc_rb_credentials_data_type, orig_cred); + TypedData_Get_Struct(copy, grpc_rb_credentials, + &grpc_rb_credentials_data_type, copy_cred); /* use ruby's MEMCPY to make a byte-for-byte copy of the credentials * wrapper object. */ @@ -133,8 +142,7 @@ static VALUE grpc_rb_default_credentials_create(VALUE cls) { } wrapper->mark = Qnil; - return Data_Wrap_Struct(cls, grpc_rb_credentials_mark, - grpc_rb_credentials_free, wrapper); + return TypedData_Wrap_Struct(cls, &grpc_rb_credentials_data_type, wrapper); } /* @@ -151,8 +159,7 @@ static VALUE grpc_rb_compute_engine_credentials_create(VALUE cls) { } wrapper->mark = Qnil; - return Data_Wrap_Struct(cls, grpc_rb_credentials_mark, - grpc_rb_credentials_free, wrapper); + return TypedData_Wrap_Struct(cls, &grpc_rb_credentials_data_type, wrapper); } /* @@ -166,8 +173,10 @@ static VALUE grpc_rb_composite_credentials_create(VALUE self, VALUE other) { grpc_rb_credentials *other_wrapper = NULL; grpc_rb_credentials *wrapper = NULL; - Data_Get_Struct(self, grpc_rb_credentials, self_wrapper); - Data_Get_Struct(other, grpc_rb_credentials, other_wrapper); + TypedData_Get_Struct(self, grpc_rb_credentials, + &grpc_rb_credentials_data_type, self_wrapper); + TypedData_Get_Struct(other, grpc_rb_credentials, + &grpc_rb_credentials_data_type, other_wrapper); wrapper = ALLOC(grpc_rb_credentials); wrapper->wrapped = grpc_composite_credentials_create(self_wrapper->wrapped, other_wrapper->wrapped); @@ -178,8 +187,8 @@ static VALUE grpc_rb_composite_credentials_create(VALUE self, VALUE other) { } wrapper->mark = Qnil; - return Data_Wrap_Struct(grpc_rb_cCredentials, grpc_rb_credentials_mark, - grpc_rb_credentials_free, wrapper); + return TypedData_Wrap_Struct(grpc_rb_cCredentials, + &grpc_rb_credentials_data_type, wrapper); } /* The attribute used on the mark object to hold the pem_root_certs. */ @@ -214,7 +223,8 @@ static VALUE grpc_rb_credentials_init(int argc, VALUE *argv, VALUE self) { rb_scan_args(argc, argv, "12", &pem_root_certs, &pem_private_key, &pem_cert_chain); - Data_Get_Struct(self, grpc_rb_credentials, wrapper); + TypedData_Get_Struct(self, grpc_rb_credentials, + &grpc_rb_credentials_data_type, wrapper); if (pem_root_certs == Qnil) { rb_raise(rb_eRuntimeError, "could not create a credential: nil pem_root_certs"); @@ -225,8 +235,8 @@ static VALUE grpc_rb_credentials_init(int argc, VALUE *argv, VALUE self) { } else { key_cert_pair.private_key = RSTRING_PTR(pem_private_key); key_cert_pair.cert_chain = RSTRING_PTR(pem_cert_chain); - creds = grpc_ssl_credentials_create( - RSTRING_PTR(pem_root_certs), &key_cert_pair); + creds = grpc_ssl_credentials_create(RSTRING_PTR(pem_root_certs), + &key_cert_pair); } if (creds == NULL) { rb_raise(rb_eRuntimeError, "could not create a credentials, not sure why"); @@ -253,8 +263,8 @@ void Init_grpc_credentials() { rb_define_alloc_func(grpc_rb_cCredentials, grpc_rb_credentials_alloc); /* Provides a ruby constructor and support for dup/clone. */ - rb_define_method(grpc_rb_cCredentials, "initialize", - grpc_rb_credentials_init, -1); + rb_define_method(grpc_rb_cCredentials, "initialize", grpc_rb_credentials_init, + -1); rb_define_method(grpc_rb_cCredentials, "initialize_copy", grpc_rb_credentials_init_copy, 1); @@ -277,6 +287,7 @@ void Init_grpc_credentials() { /* Gets the wrapped grpc_credentials from the ruby wrapper */ grpc_credentials *grpc_rb_get_wrapped_credentials(VALUE v) { grpc_rb_credentials *wrapper = NULL; - Data_Get_Struct(v, grpc_rb_credentials, wrapper); + TypedData_Get_Struct(v, grpc_rb_credentials, &grpc_rb_credentials_data_type, + wrapper); return wrapper->wrapped; } |