Use TypedData for GRPC::Core::Credentials
diff --git a/src/ruby/ext/grpc/rb_credentials.c b/src/ruby/ext/grpc/rb_credentials.c
index 1504a48..8170f0d 100644
--- a/src/ruby/ext/grpc/rb_credentials.c
+++ b/src/ruby/ext/grpc/rb_credentials.c
@@ -83,14 +83,21 @@
}
}
+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 @@
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 @@
}
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 @@
}
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 @@
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 @@
}
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 @@
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 @@
} 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 @@
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 @@
/* 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;
}