aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar murgatroid99 <mlumish@google.com>2016-03-14 13:01:00 -0700
committerGravatar murgatroid99 <mlumish@google.com>2016-03-23 11:20:42 -0700
commit05afaa838aad09ca65c8da5108492e63f15ae3f9 (patch)
treeacd0d88f5dbce5d03401b2aae6990ba3de849610
parent3eaaf39efffc95327b4ff440fc4a412486f94311 (diff)
Add GC marking for composite credentials
-rw-r--r--src/ruby/ext/grpc/rb_call_credentials.c32
-rw-r--r--src/ruby/ext/grpc/rb_channel_credentials.c23
2 files changed, 23 insertions, 32 deletions
diff --git a/src/ruby/ext/grpc/rb_call_credentials.c b/src/ruby/ext/grpc/rb_call_credentials.c
index 402becf6aa..7c4b69f7f0 100644
--- a/src/ruby/ext/grpc/rb_call_credentials.c
+++ b/src/ruby/ext/grpc/rb_call_credentials.c
@@ -50,17 +50,13 @@
* grpc_call_credentials */
static VALUE grpc_rb_cCallCredentials = Qnil;
-/* grpc_rb_call_credentials wraps a grpc_call_credentials. It provides a peer
- * ruby object, 'mark' to minimize copying when a credential is created from
- * ruby. */
+/* grpc_rb_call_credentials wraps a grpc_call_credentials. It provides a mark
+ * object that is used to hold references to any objects used to create the
+ * credentials. */
typedef struct grpc_rb_call_credentials {
/* Holder of ruby objects involved in contructing the credentials */
VALUE mark;
- /* The proc called when getting the credentials. Same pointer as
- wrapped->state */
- VALUE proc;
-
/* The actual credentials */
grpc_call_credentials *wrapped;
} grpc_rb_call_credentials;
@@ -150,13 +146,8 @@ static void grpc_rb_call_credentials_free(void *p) {
return;
}
wrapper = (grpc_rb_call_credentials *)p;
-
- /* Delete the wrapped object if the mark object is Qnil, which indicates that
- * no other object is the actual owner. */
- if (wrapper->wrapped != NULL && wrapper->mark == Qnil) {
- grpc_call_credentials_release(wrapper->wrapped);
- wrapper->wrapped = NULL;
- }
+ grpc_call_credentials_release(wrapper->wrapped);
+ wrapper->wrapped = NULL;
xfree(p);
}
@@ -168,11 +159,9 @@ static void grpc_rb_call_credentials_mark(void *p) {
return;
}
wrapper = (grpc_rb_call_credentials *)p;
- /* If it's not already cleaned up, mark the mark object */
if (wrapper->mark != Qnil) {
rb_gc_mark(wrapper->mark);
}
- rb_gc_mark(wrapper->proc);
}
static rb_data_type_t grpc_rb_call_credentials_data_type = {
@@ -191,7 +180,6 @@ static rb_data_type_t grpc_rb_call_credentials_data_type = {
static VALUE grpc_rb_call_credentials_alloc(VALUE cls) {
grpc_rb_call_credentials *wrapper = ALLOC(grpc_rb_call_credentials);
wrapper->wrapped = NULL;
- wrapper->proc = Qnil;
wrapper->mark = Qnil;
return TypedData_Wrap_Struct(cls, &grpc_rb_call_credentials_data_type, wrapper);
}
@@ -199,7 +187,7 @@ static VALUE grpc_rb_call_credentials_alloc(VALUE cls) {
/* Creates a wrapping object for a given call credentials. This should only be
* called with grpc_call_credentials objects that are not already associated
* with any Ruby object */
-VALUE grpc_rb_wrap_call_credentials(grpc_call_credentials *c) {
+VALUE grpc_rb_wrap_call_credentials(grpc_call_credentials *c, VALUE mark) {
VALUE rb_wrapper;
grpc_rb_call_credentials *wrapper;
if (c == NULL) {
@@ -209,6 +197,7 @@ VALUE grpc_rb_wrap_call_credentials(grpc_call_credentials *c) {
TypedData_Get_Struct(rb_wrapper, grpc_rb_call_credentials,
&grpc_rb_call_credentials_data_type, wrapper);
wrapper->wrapped = c;
+ wrapper->mark = mark;
return rb_wrapper;
}
@@ -272,7 +261,7 @@ static VALUE grpc_rb_call_credentials_init(VALUE self, VALUE proc) {
return Qnil;
}
- wrapper->proc = proc;
+ wrapper->mark = proc;
wrapper->wrapped = creds;
rb_ivar_set(self, id_callback, proc);
@@ -283,15 +272,18 @@ static VALUE grpc_rb_call_credentials_compose(int argc, VALUE *argv,
VALUE self) {
grpc_call_credentials *creds;
grpc_call_credentials *other;
+ VALUE mark;
if (argc == 0) {
return self;
}
+ mark = rb_ary_new();
creds = grpc_rb_get_wrapped_call_credentials(self);
for (int i = 0; i < argc; i++) {
+ rb_ary_push(mark, argv[i]);
other = grpc_rb_get_wrapped_call_credentials(argv[i]);
creds = grpc_composite_call_credentials_create(creds, other, NULL);
}
- return grpc_rb_wrap_call_credentials(creds);
+ return grpc_rb_wrap_call_credentials(creds, mark);
}
void Init_grpc_call_credentials() {
diff --git a/src/ruby/ext/grpc/rb_channel_credentials.c b/src/ruby/ext/grpc/rb_channel_credentials.c
index 8c6fc3b7eb..f649084311 100644
--- a/src/ruby/ext/grpc/rb_channel_credentials.c
+++ b/src/ruby/ext/grpc/rb_channel_credentials.c
@@ -49,8 +49,8 @@
static VALUE grpc_rb_cChannelCredentials = Qnil;
/* grpc_rb_channel_credentials wraps a grpc_channel_credentials. It provides a
- * peer ruby object, 'mark' to minimize copying when a credential is
- * created from ruby. */
+ * mark object that is used to hold references to any objects used to create
+ * the credentials. */
typedef struct grpc_rb_channel_credentials {
/* Holder of ruby objects involved in constructing the credentials */
VALUE mark;
@@ -66,13 +66,8 @@ static void grpc_rb_channel_credentials_free(void *p) {
return;
};
wrapper = (grpc_rb_channel_credentials *)p;
-
- /* Delete the wrapped object if the mark object is Qnil, which indicates that
- * no other object is the actual owner. */
- if (wrapper->wrapped != NULL && wrapper->mark == Qnil) {
- grpc_channel_credentials_release(wrapper->wrapped);
- wrapper->wrapped = NULL;
- }
+ grpc_channel_credentials_release(wrapper->wrapped);
+ wrapper->wrapped = NULL;
xfree(p);
}
@@ -85,7 +80,6 @@ static void grpc_rb_channel_credentials_mark(void *p) {
}
wrapper = (grpc_rb_channel_credentials *)p;
- /* If it's not already cleaned up, mark the mark object */
if (wrapper->mark != Qnil) {
rb_gc_mark(wrapper->mark);
}
@@ -114,7 +108,7 @@ static VALUE grpc_rb_channel_credentials_alloc(VALUE cls) {
/* Creates a wrapping object for a given channel credentials. This should only
* be called with grpc_channel_credentials objects that are not already
* associated with any Ruby object. */
-VALUE grpc_rb_wrap_channel_credentials(grpc_channel_credentials *c) {
+VALUE grpc_rb_wrap_channel_credentials(grpc_channel_credentials *c, VALUE mark) {
VALUE rb_wrapper;
grpc_rb_channel_credentials *wrapper;
if (c == NULL) {
@@ -124,6 +118,7 @@ VALUE grpc_rb_wrap_channel_credentials(grpc_channel_credentials *c) {
TypedData_Get_Struct(rb_wrapper, grpc_rb_channel_credentials,
&grpc_rb_channel_credentials_data_type, wrapper);
wrapper->wrapped = c;
+ wrapper->mark = mark;
return rb_wrapper;
}
@@ -222,11 +217,15 @@ static VALUE grpc_rb_channel_credentials_compose(int argc, VALUE *argv,
VALUE self) {
grpc_channel_credentials *creds;
grpc_call_credentials *other;
+ VALUE mark;
if (argc == 0) {
return self;
}
+ mark = rb_ary_new();
+ rb_ary_push(mark, self);
creds = grpc_rb_get_wrapped_channel_credentials(self);
for (int i = 0; i < argc; i++) {
+ rb_ary_push(mark, argv[i]);
other = grpc_rb_get_wrapped_call_credentials(argv[i]);
creds = grpc_composite_channel_credentials_create(creds, other, NULL);
if (creds == NULL) {
@@ -234,7 +233,7 @@ static VALUE grpc_rb_channel_credentials_compose(int argc, VALUE *argv,
"Failed to compose channel and call credentials");
}
}
- return grpc_rb_wrap_channel_credentials(creds);
+ return grpc_rb_wrap_channel_credentials(creds, mark);
}
void Init_grpc_channel_credentials() {