Skip to content
Snippets Groups Projects
Commit 34bb6df1 authored by Alexander Polcyn's avatar Alexander Polcyn
Browse files

allocated run batch stack on the heap

parent 27338de4
No related branches found
No related tags found
No related merge requests found
...@@ -784,7 +784,7 @@ static VALUE grpc_run_batch_stack_build_result(run_batch_stack *st) { ...@@ -784,7 +784,7 @@ static VALUE grpc_run_batch_stack_build_result(run_batch_stack *st) {
Only one operation of each type can be active at once in any given Only one operation of each type can be active at once in any given
batch */ batch */
static VALUE grpc_rb_call_run_batch(VALUE self, VALUE ops_hash) { static VALUE grpc_rb_call_run_batch(VALUE self, VALUE ops_hash) {
run_batch_stack st; run_batch_stack *st;
grpc_rb_call *call = NULL; grpc_rb_call *call = NULL;
grpc_event ev; grpc_event ev;
grpc_call_error err; grpc_call_error err;
...@@ -792,6 +792,8 @@ static VALUE grpc_rb_call_run_batch(VALUE self, VALUE ops_hash) { ...@@ -792,6 +792,8 @@ static VALUE grpc_rb_call_run_batch(VALUE self, VALUE ops_hash) {
VALUE rb_write_flag = rb_ivar_get(self, id_write_flag); VALUE rb_write_flag = rb_ivar_get(self, id_write_flag);
unsigned write_flag = 0; unsigned write_flag = 0;
void *tag = (void*)&st; void *tag = (void*)&st;
st = gpr_malloc(sizeof(run_batch_stack));
if (RTYPEDDATA_DATA(self) == NULL) { if (RTYPEDDATA_DATA(self) == NULL) {
rb_raise(grpc_rb_eCallError, "Cannot run batch on closed call"); rb_raise(grpc_rb_eCallError, "Cannot run batch on closed call");
return Qnil; return Qnil;
...@@ -806,14 +808,15 @@ static VALUE grpc_rb_call_run_batch(VALUE self, VALUE ops_hash) { ...@@ -806,14 +808,15 @@ static VALUE grpc_rb_call_run_batch(VALUE self, VALUE ops_hash) {
if (rb_write_flag != Qnil) { if (rb_write_flag != Qnil) {
write_flag = NUM2UINT(rb_write_flag); write_flag = NUM2UINT(rb_write_flag);
} }
grpc_run_batch_stack_init(&st, write_flag); grpc_run_batch_stack_init(st, write_flag);
grpc_run_batch_stack_fill_ops(&st, ops_hash); grpc_run_batch_stack_fill_ops(st, ops_hash);
/* call grpc_call_start_batch, then wait for it to complete using /* call grpc_call_start_batch, then wait for it to complete using
* pluck_event */ * pluck_event */
err = grpc_call_start_batch(call->wrapped, st.ops, st.op_num, tag, NULL); err = grpc_call_start_batch(call->wrapped, st->ops, st->op_num, tag, NULL);
if (err != GRPC_CALL_OK) { if (err != GRPC_CALL_OK) {
grpc_run_batch_stack_cleanup(&st); grpc_run_batch_stack_cleanup(st);
gpr_free(st);
rb_raise(grpc_rb_eCallError, rb_raise(grpc_rb_eCallError,
"grpc_call_start_batch failed with %s (code=%d)", "grpc_call_start_batch failed with %s (code=%d)",
grpc_call_error_detail_of(err), err); grpc_call_error_detail_of(err), err);
...@@ -826,8 +829,9 @@ static VALUE grpc_rb_call_run_batch(VALUE self, VALUE ops_hash) { ...@@ -826,8 +829,9 @@ static VALUE grpc_rb_call_run_batch(VALUE self, VALUE ops_hash) {
} }
/* Build and return the BatchResult struct result, /* Build and return the BatchResult struct result,
if there is an error, it's reflected in the status */ if there is an error, it's reflected in the status */
result = grpc_run_batch_stack_build_result(&st); result = grpc_run_batch_stack_build_result(st);
grpc_run_batch_stack_cleanup(&st); grpc_run_batch_stack_cleanup(st);
gpr_free(st);
return result; return result;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment