diff options
author | Craig Tiller <ctiller@google.com> | 2017-01-20 18:11:52 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-20 18:11:52 -0800 |
commit | 5e01e2ac977655aa074faf7fde0a74298f5e4c55 (patch) | |
tree | 9acab9c5952f292683a6d474861e2997e2a9d664 /src/ruby/ext | |
parent | c84725fd02dc58a819c8c4e8acdc321e81f44764 (diff) |
Revert "Metadata handling rewrite"
Diffstat (limited to 'src/ruby/ext')
-rw-r--r-- | src/ruby/ext/grpc/rb_byte_buffer.c | 7 | ||||
-rw-r--r-- | src/ruby/ext/grpc/rb_byte_buffer.h | 3 | ||||
-rw-r--r-- | src/ruby/ext/grpc/rb_call.c | 93 | ||||
-rw-r--r-- | src/ruby/ext/grpc/rb_channel.c | 27 | ||||
-rw-r--r-- | src/ruby/ext/grpc/rb_compression_options.c | 15 | ||||
-rw-r--r-- | src/ruby/ext/grpc/rb_grpc_imports.generated.c | 30 | ||||
-rw-r--r-- | src/ruby/ext/grpc/rb_grpc_imports.generated.h | 55 | ||||
-rw-r--r-- | src/ruby/ext/grpc/rb_server.c | 10 |
8 files changed, 72 insertions, 168 deletions
diff --git a/src/ruby/ext/grpc/rb_byte_buffer.c b/src/ruby/ext/grpc/rb_byte_buffer.c index 65fa2f2cf6..47fd6d9120 100644 --- a/src/ruby/ext/grpc/rb_byte_buffer.c +++ b/src/ruby/ext/grpc/rb_byte_buffer.c @@ -68,10 +68,3 @@ VALUE grpc_rb_byte_buffer_to_s(grpc_byte_buffer *buffer) { grpc_byte_buffer_reader_destroy(&reader); return rb_string; } - -VALUE grpc_rb_slice_to_ruby_string(grpc_slice slice) { - if (GRPC_SLICE_START_PTR(slice) == NULL) { - rb_raise(rb_eRuntimeError, "attempt to convert uninitialized grpc_slice to ruby string"); - } - return rb_str_new((char*)GRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice)); -} diff --git a/src/ruby/ext/grpc/rb_byte_buffer.h b/src/ruby/ext/grpc/rb_byte_buffer.h index fac68fe6a0..c7ddd76489 100644 --- a/src/ruby/ext/grpc/rb_byte_buffer.h +++ b/src/ruby/ext/grpc/rb_byte_buffer.h @@ -44,7 +44,4 @@ grpc_byte_buffer *grpc_rb_s_to_byte_buffer(char *string, size_t length); /* Converts a grpc_byte_buffer to a ruby string */ VALUE grpc_rb_byte_buffer_to_s(grpc_byte_buffer *buffer); -/* Converts a grpc_slice to a ruby string */ -VALUE grpc_rb_slice_to_ruby_string(grpc_slice slice); - #endif /* GRPC_RB_BYTE_BUFFER_H_ */ diff --git a/src/ruby/ext/grpc/rb_call.c b/src/ruby/ext/grpc/rb_call.c index 0179bd9e9b..67a42af619 100644 --- a/src/ruby/ext/grpc/rb_call.c +++ b/src/ruby/ext/grpc/rb_call.c @@ -121,8 +121,8 @@ static size_t md_ary_datasize(const void *p) { size_t i, datasize = sizeof(grpc_metadata_array); for (i = 0; i < ary->count; ++i) { const grpc_metadata *const md = &ary->metadata[i]; - datasize += GRPC_SLICE_LENGTH(md->key); - datasize += GRPC_SLICE_LENGTH(md->value); + datasize += strlen(md->key); + datasize += md->value_length; } datasize += ary->capacity * sizeof(grpc_metadata); return datasize; @@ -386,23 +386,23 @@ static int grpc_rb_md_ary_fill_hash_cb(VALUE key, VALUE val, VALUE md_ary_obj) { grpc_metadata_array *md_ary = NULL; long array_length; long i; - grpc_slice key_slice; - grpc_slice value_slice; - char* tmp_str; + char *key_str; + size_t key_len; + char *value_str; + size_t value_len; if (TYPE(key) == T_SYMBOL) { - key_slice = grpc_slice_from_static_string(rb_id2name(SYM2ID(key))); - } else if (TYPE(key) == T_STRING) { - key_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(key), RSTRING_LEN(key)); - } else { - rb_raise(rb_eTypeError, "grpc_rb_md_ary_fill_hash_cb: bad type for key parameter"); + key_str = (char *)rb_id2name(SYM2ID(key)); + key_len = strlen(key_str); + } else { /* StringValueCStr does all other type exclusions for us */ + key_str = StringValueCStr(key); + key_len = RSTRING_LEN(key); } - if (!grpc_header_key_is_legal(key_slice)) { - tmp_str = grpc_slice_to_c_string(key_slice); + if (!grpc_header_key_is_legal(key_str, key_len)) { rb_raise(rb_eArgError, "'%s' is an invalid header key, must match [a-z0-9-_.]+", - tmp_str); + key_str); return ST_STOP; } @@ -414,31 +414,33 @@ static int grpc_rb_md_ary_fill_hash_cb(VALUE key, VALUE val, VALUE md_ary_obj) { array_length = RARRAY_LEN(val); /* If the value is an array, add capacity for each value in the array */ for (i = 0; i < array_length; i++) { - value_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(rb_ary_entry(val, i)), RSTRING_LEN(rb_ary_entry(val, i))); - if (!grpc_is_binary_header(key_slice) && - !grpc_header_nonbin_value_is_legal(value_slice)) { + value_str = RSTRING_PTR(rb_ary_entry(val, i)); + value_len = RSTRING_LEN(rb_ary_entry(val, i)); + if (!grpc_is_binary_header(key_str, key_len) && + !grpc_header_nonbin_value_is_legal(value_str, value_len)) { // The value has invalid characters - tmp_str = grpc_slice_to_c_string(value_slice); rb_raise(rb_eArgError, - "Header value '%s' has invalid characters", tmp_str); + "Header value '%s' has invalid characters", value_str); return ST_STOP; } - md_ary->metadata[md_ary->count].key = key_slice; - md_ary->metadata[md_ary->count].value = value_slice; + md_ary->metadata[md_ary->count].key = key_str; + md_ary->metadata[md_ary->count].value = value_str; + md_ary->metadata[md_ary->count].value_length = value_len; md_ary->count += 1; } } else if (TYPE(val) == T_STRING) { - value_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(val), RSTRING_LEN(val)); - if (!grpc_is_binary_header(key_slice) && - !grpc_header_nonbin_value_is_legal(value_slice)) { + value_str = RSTRING_PTR(val); + value_len = RSTRING_LEN(val); + if (!grpc_is_binary_header(key_str, key_len) && + !grpc_header_nonbin_value_is_legal(value_str, value_len)) { // The value has invalid characters - tmp_str = grpc_slice_to_c_string(value_slice); rb_raise(rb_eArgError, - "Header value '%s' has invalid characters", tmp_str); + "Header value '%s' has invalid characters", value_str); return ST_STOP; } - md_ary->metadata[md_ary->count].key = key_slice; - md_ary->metadata[md_ary->count].value = value_slice; + md_ary->metadata[md_ary->count].key = key_str; + md_ary->metadata[md_ary->count].value = value_str; + md_ary->metadata[md_ary->count].value_length = value_len; md_ary->count += 1; } else { rb_raise(rb_eArgError, @@ -504,19 +506,22 @@ VALUE grpc_rb_md_ary_to_h(grpc_metadata_array *md_ary) { size_t i; for (i = 0; i < md_ary->count; i++) { - key = grpc_rb_slice_to_ruby_string(md_ary->metadata[i].key); + key = rb_str_new2(md_ary->metadata[i].key); value = rb_hash_aref(result, key); if (value == Qnil) { - value = grpc_rb_slice_to_ruby_string(md_ary->metadata[i].value); + value = rb_str_new(md_ary->metadata[i].value, + md_ary->metadata[i].value_length); rb_hash_aset(result, key, value); } else if (TYPE(value) == T_ARRAY) { /* Add the string to the returned array */ - rb_ary_push(value, grpc_rb_slice_to_ruby_string(md_ary->metadata[i].value)); + rb_ary_push(value, rb_str_new(md_ary->metadata[i].value, + md_ary->metadata[i].value_length)); } else { /* Add the current value with this key and the new one to an array */ new_ary = rb_ary_new(); rb_ary_push(new_ary, value); - rb_ary_push(new_ary, grpc_rb_slice_to_ruby_string(md_ary->metadata[i].value)); + rb_ary_push(new_ary, rb_str_new(md_ary->metadata[i].value, + md_ary->metadata[i].value_length)); rb_hash_aset(result, key, new_ary); } } @@ -558,7 +563,6 @@ static int grpc_rb_call_check_op_keys_hash_cb(VALUE key, VALUE val, */ static void grpc_rb_op_update_status_from_server(grpc_op *op, grpc_metadata_array *md_ary, - grpc_slice *send_status_details, VALUE status) { VALUE code = rb_struct_aref(status, sym_code); VALUE details = rb_struct_aref(status, sym_details); @@ -575,11 +579,8 @@ static void grpc_rb_op_update_status_from_server(grpc_op *op, rb_obj_classname(code)); return; } - - *send_status_details = grpc_slice_from_copied_buffer(RSTRING_PTR(details), RSTRING_LEN(details)); - op->data.send_status_from_server.status = NUM2INT(code); - op->data.send_status_from_server.status_details = send_status_details; + op->data.send_status_from_server.status_details = StringValueCStr(details); grpc_rb_md_ary_convert(metadata_hash, md_ary); op->data.send_status_from_server.trailing_metadata_count = md_ary->count; op->data.send_status_from_server.trailing_metadata = md_ary->metadata; @@ -602,9 +603,9 @@ typedef struct run_batch_stack { grpc_metadata_array recv_trailing_metadata; int recv_cancelled; grpc_status_code recv_status; - grpc_slice recv_status_details; + char *recv_status_details; + size_t recv_status_details_capacity; unsigned write_flag; - grpc_slice send_status_details; } run_batch_stack; /* grpc_run_batch_stack_init ensures the run_batch_stack is properly @@ -630,12 +631,8 @@ static void grpc_run_batch_stack_cleanup(run_batch_stack *st) { grpc_metadata_array_destroy(&st->recv_metadata); grpc_metadata_array_destroy(&st->recv_trailing_metadata); - if (GRPC_SLICE_START_PTR(st->send_status_details) != NULL) { - grpc_slice_unref(st->send_status_details); - } - - if (GRPC_SLICE_START_PTR(st->recv_status_details) != NULL) { - grpc_slice_unref(st->recv_status_details); + if (st->recv_status_details != NULL) { + gpr_free(st->recv_status_details); } if (st->recv_message != NULL) { @@ -686,7 +683,7 @@ static void grpc_run_batch_stack_fill_ops(run_batch_stack *st, VALUE ops_hash) { /* N.B. later there is no need to explicitly delete the metadata keys * and values, they are references to data in ruby objects. */ grpc_rb_op_update_status_from_server( - &st->ops[st->op_num], &st->send_trailing_metadata, &st->send_status_details, this_value); + &st->ops[st->op_num], &st->send_trailing_metadata, this_value); break; case GRPC_OP_RECV_INITIAL_METADATA: st->ops[st->op_num].data.recv_initial_metadata = &st->recv_metadata; @@ -701,6 +698,8 @@ static void grpc_run_batch_stack_fill_ops(run_batch_stack *st, VALUE ops_hash) { &st->recv_status; st->ops[st->op_num].data.recv_status_on_client.status_details = &st->recv_status_details; + st->ops[st->op_num].data.recv_status_on_client.status_details_capacity = + &st->recv_status_details_capacity; break; case GRPC_OP_RECV_CLOSE_ON_SERVER: st->ops[st->op_num].data.recv_close_on_server.cancelled = @@ -748,9 +747,9 @@ static VALUE grpc_run_batch_stack_build_result(run_batch_stack *st) { rb_struct_aset( result, sym_status, rb_struct_new(grpc_rb_sStatus, UINT2NUM(st->recv_status), - (GRPC_SLICE_START_PTR(st->recv_status_details) == NULL + (st->recv_status_details == NULL ? Qnil - : grpc_rb_slice_to_ruby_string(st->recv_status_details)), + : rb_str_new2(st->recv_status_details)), grpc_rb_md_ary_to_h(&st->recv_trailing_metadata), NULL)); break; diff --git a/src/ruby/ext/grpc/rb_channel.c b/src/ruby/ext/grpc/rb_channel.c index 84e43d3f7b..3b2b88eb77 100644 --- a/src/ruby/ext/grpc/rb_channel.c +++ b/src/ruby/ext/grpc/rb_channel.c @@ -35,7 +35,6 @@ #include "rb_grpc_imports.generated.h" #include "rb_channel.h" -#include "rb_byte_buffer.h" #include <grpc/grpc.h> #include <grpc/grpc_security.h> @@ -253,14 +252,10 @@ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent, grpc_channel *ch = NULL; grpc_completion_queue *cq = NULL; int flags = GRPC_PROPAGATE_DEFAULTS; - grpc_slice method_slice; - grpc_slice host_slice; - grpc_slice *host_slice_ptr = NULL; - char* tmp_str = NULL; - + char *method_chars = StringValueCStr(method); + char *host_chars = NULL; if (host != Qnil) { - host_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(host), RSTRING_LEN(host)); - host_slice_ptr = &host_slice; + host_chars = StringValueCStr(host); } if (mask != Qnil) { flags = NUM2UINT(mask); @@ -277,25 +272,15 @@ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent, return Qnil; } - method_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(method), RSTRING_LEN(method)); - - call = grpc_channel_create_call(ch, parent_call, flags, cq, method_slice, - host_slice_ptr, grpc_rb_time_timeval( + call = grpc_channel_create_call(ch, parent_call, flags, cq, method_chars, + host_chars, grpc_rb_time_timeval( deadline, /* absolute time */ 0), NULL); - if (call == NULL) { - tmp_str = grpc_slice_to_c_string(method_slice); rb_raise(rb_eRuntimeError, "cannot create call with method %s", - tmp_str); + method_chars); return Qnil; } - - grpc_slice_unref(method_slice); - if (host_slice_ptr != NULL) { - grpc_slice_unref(host_slice); - } - res = grpc_rb_wrap_call(call, cq); /* Make this channel an instance attribute of the call so that it is not GCed diff --git a/src/ruby/ext/grpc/rb_compression_options.c b/src/ruby/ext/grpc/rb_compression_options.c index 6b2467ee46..6200dbafeb 100644 --- a/src/ruby/ext/grpc/rb_compression_options.c +++ b/src/ruby/ext/grpc/rb_compression_options.c @@ -34,7 +34,6 @@ #include <ruby/ruby.h> #include "rb_compression_options.h" -#include "rb_byte_buffer.h" #include "rb_grpc_imports.generated.h" #include <grpc/compression.h> @@ -169,9 +168,9 @@ void grpc_rb_compression_options_set_default_level( * Raises an error if the name of the algorithm passed in is invalid. */ void grpc_rb_compression_options_algorithm_name_to_value_internal( grpc_compression_algorithm *algorithm_value, VALUE algorithm_name) { - grpc_slice name_slice; + char *name_str = NULL; + long name_len = 0; VALUE algorithm_name_as_string = Qnil; - char *tmp_str = NULL; Check_Type(algorithm_name, T_SYMBOL); @@ -179,18 +178,16 @@ void grpc_rb_compression_options_algorithm_name_to_value_internal( * correct C string out of it. */ algorithm_name_as_string = rb_funcall(algorithm_name, rb_intern("to_s"), 0); - name_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(algorithm_name_as_string), RSTRING_LEN(algorithm_name_as_string)); + name_str = RSTRING_PTR(algorithm_name_as_string); + name_len = RSTRING_LEN(algorithm_name_as_string); /* Raise an error if the name isn't recognized as a compression algorithm by * the algorithm parse function * in GRPC core. */ - if(!grpc_compression_algorithm_parse(name_slice, algorithm_value)) { - tmp_str = grpc_slice_to_c_string(name_slice); + if (!grpc_compression_algorithm_parse(name_str, name_len, algorithm_value)) { rb_raise(rb_eNameError, "Invalid compression algorithm name: %s", - tmp_str); + StringValueCStr(algorithm_name_as_string)); } - - grpc_slice_unref(name_slice); } /* Indicates whether a given algorithm is enabled on this instance, given the diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.c b/src/ruby/ext/grpc/rb_grpc_imports.generated.c index 230682e72d..6c36df9113 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.c +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.c @@ -179,30 +179,17 @@ grpc_slice_new_type grpc_slice_new_import; grpc_slice_new_with_user_data_type grpc_slice_new_with_user_data_import; grpc_slice_new_with_len_type grpc_slice_new_with_len_import; grpc_slice_malloc_type grpc_slice_malloc_import; -grpc_slice_intern_type grpc_slice_intern_import; grpc_slice_from_copied_string_type grpc_slice_from_copied_string_import; grpc_slice_from_copied_buffer_type grpc_slice_from_copied_buffer_import; grpc_slice_from_static_string_type grpc_slice_from_static_string_import; -grpc_slice_from_static_buffer_type grpc_slice_from_static_buffer_import; grpc_slice_sub_type grpc_slice_sub_import; grpc_slice_sub_no_ref_type grpc_slice_sub_no_ref_import; grpc_slice_split_tail_type grpc_slice_split_tail_import; grpc_slice_split_head_type grpc_slice_split_head_import; -grpc_empty_slice_type grpc_empty_slice_import; -grpc_slice_default_hash_impl_type grpc_slice_default_hash_impl_import; -grpc_slice_default_eq_impl_type grpc_slice_default_eq_impl_import; -grpc_slice_eq_type grpc_slice_eq_import; +gpr_empty_slice_type gpr_empty_slice_import; grpc_slice_cmp_type grpc_slice_cmp_import; grpc_slice_str_cmp_type grpc_slice_str_cmp_import; -grpc_slice_buf_cmp_type grpc_slice_buf_cmp_import; -grpc_slice_buf_start_eq_type grpc_slice_buf_start_eq_import; -grpc_slice_rchr_type grpc_slice_rchr_import; -grpc_slice_chr_type grpc_slice_chr_import; -grpc_slice_slice_type grpc_slice_slice_import; -grpc_slice_hash_type grpc_slice_hash_import; grpc_slice_is_equivalent_type grpc_slice_is_equivalent_import; -grpc_slice_dup_type grpc_slice_dup_import; -grpc_slice_to_c_string_type grpc_slice_to_c_string_import; grpc_slice_buffer_init_type grpc_slice_buffer_init_import; grpc_slice_buffer_destroy_type grpc_slice_buffer_destroy_import; grpc_slice_buffer_add_type grpc_slice_buffer_add_import; @@ -468,30 +455,17 @@ void grpc_rb_load_imports(HMODULE library) { grpc_slice_new_with_user_data_import = (grpc_slice_new_with_user_data_type) GetProcAddress(library, "grpc_slice_new_with_user_data"); grpc_slice_new_with_len_import = (grpc_slice_new_with_len_type) GetProcAddress(library, "grpc_slice_new_with_len"); grpc_slice_malloc_import = (grpc_slice_malloc_type) GetProcAddress(library, "grpc_slice_malloc"); - grpc_slice_intern_import = (grpc_slice_intern_type) GetProcAddress(library, "grpc_slice_intern"); grpc_slice_from_copied_string_import = (grpc_slice_from_copied_string_type) GetProcAddress(library, "grpc_slice_from_copied_string"); grpc_slice_from_copied_buffer_import = (grpc_slice_from_copied_buffer_type) GetProcAddress(library, "grpc_slice_from_copied_buffer"); grpc_slice_from_static_string_import = (grpc_slice_from_static_string_type) GetProcAddress(library, "grpc_slice_from_static_string"); - grpc_slice_from_static_buffer_import = (grpc_slice_from_static_buffer_type) GetProcAddress(library, "grpc_slice_from_static_buffer"); grpc_slice_sub_import = (grpc_slice_sub_type) GetProcAddress(library, "grpc_slice_sub"); grpc_slice_sub_no_ref_import = (grpc_slice_sub_no_ref_type) GetProcAddress(library, "grpc_slice_sub_no_ref"); grpc_slice_split_tail_import = (grpc_slice_split_tail_type) GetProcAddress(library, "grpc_slice_split_tail"); grpc_slice_split_head_import = (grpc_slice_split_head_type) GetProcAddress(library, "grpc_slice_split_head"); - grpc_empty_slice_import = (grpc_empty_slice_type) GetProcAddress(library, "grpc_empty_slice"); - grpc_slice_default_hash_impl_import = (grpc_slice_default_hash_impl_type) GetProcAddress(library, "grpc_slice_default_hash_impl"); - grpc_slice_default_eq_impl_import = (grpc_slice_default_eq_impl_type) GetProcAddress(library, "grpc_slice_default_eq_impl"); - grpc_slice_eq_import = (grpc_slice_eq_type) GetProcAddress(library, "grpc_slice_eq"); + gpr_empty_slice_import = (gpr_empty_slice_type) GetProcAddress(library, "gpr_empty_slice"); grpc_slice_cmp_import = (grpc_slice_cmp_type) GetProcAddress(library, "grpc_slice_cmp"); grpc_slice_str_cmp_import = (grpc_slice_str_cmp_type) GetProcAddress(library, "grpc_slice_str_cmp"); - grpc_slice_buf_cmp_import = (grpc_slice_buf_cmp_type) GetProcAddress(library, "grpc_slice_buf_cmp"); - grpc_slice_buf_start_eq_import = (grpc_slice_buf_start_eq_type) GetProcAddress(library, "grpc_slice_buf_start_eq"); - grpc_slice_rchr_import = (grpc_slice_rchr_type) GetProcAddress(library, "grpc_slice_rchr"); - grpc_slice_chr_import = (grpc_slice_chr_type) GetProcAddress(library, "grpc_slice_chr"); - grpc_slice_slice_import = (grpc_slice_slice_type) GetProcAddress(library, "grpc_slice_slice"); - grpc_slice_hash_import = (grpc_slice_hash_type) GetProcAddress(library, "grpc_slice_hash"); grpc_slice_is_equivalent_import = (grpc_slice_is_equivalent_type) GetProcAddress(library, "grpc_slice_is_equivalent"); - grpc_slice_dup_import = (grpc_slice_dup_type) GetProcAddress(library, "grpc_slice_dup"); - grpc_slice_to_c_string_import = (grpc_slice_to_c_string_type) GetProcAddress(library, "grpc_slice_to_c_string"); grpc_slice_buffer_init_import = (grpc_slice_buffer_init_type) GetProcAddress(library, "grpc_slice_buffer_init"); grpc_slice_buffer_destroy_import = (grpc_slice_buffer_destroy_type) GetProcAddress(library, "grpc_slice_buffer_destroy"); grpc_slice_buffer_add_import = (grpc_slice_buffer_add_type) GetProcAddress(library, "grpc_slice_buffer_add"); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index 4c4f655b86..5745686adf 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -176,7 +176,7 @@ extern census_resource_id_type census_resource_id_import; typedef void(*census_record_values_type)(census_context *context, census_value *values, size_t nvalues); extern census_record_values_type census_record_values_import; #define census_record_values census_record_values_import -typedef int(*grpc_compression_algorithm_parse_type)(grpc_slice value, grpc_compression_algorithm *algorithm); +typedef int(*grpc_compression_algorithm_parse_type)(const char *name, size_t name_length, grpc_compression_algorithm *algorithm); extern grpc_compression_algorithm_parse_type grpc_compression_algorithm_parse_import; #define grpc_compression_algorithm_parse grpc_compression_algorithm_parse_import typedef int(*grpc_compression_algorithm_name_type)(grpc_compression_algorithm algorithm, char **name); @@ -254,7 +254,7 @@ extern grpc_channel_check_connectivity_state_type grpc_channel_check_connectivit typedef void(*grpc_channel_watch_connectivity_state_type)(grpc_channel *channel, grpc_connectivity_state last_observed_state, gpr_timespec deadline, grpc_completion_queue *cq, void *tag); extern grpc_channel_watch_connectivity_state_type grpc_channel_watch_connectivity_state_import; #define grpc_channel_watch_connectivity_state grpc_channel_watch_connectivity_state_import -typedef grpc_call *(*grpc_channel_create_call_type)(grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, grpc_completion_queue *completion_queue, grpc_slice method, const grpc_slice *host, gpr_timespec deadline, void *reserved); +typedef grpc_call *(*grpc_channel_create_call_type)(grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, grpc_completion_queue *completion_queue, const char *method, const char *host, gpr_timespec deadline, void *reserved); extern grpc_channel_create_call_type grpc_channel_create_call_import; #define grpc_channel_create_call grpc_channel_create_call_import typedef void(*grpc_channel_ping_type)(grpc_channel *channel, grpc_completion_queue *cq, void *tag, void *reserved); @@ -338,13 +338,13 @@ extern grpc_server_destroy_type grpc_server_destroy_import; typedef int(*grpc_tracer_set_enabled_type)(const char *name, int enabled); extern grpc_tracer_set_enabled_type grpc_tracer_set_enabled_import; #define grpc_tracer_set_enabled grpc_tracer_set_enabled_import -typedef int(*grpc_header_key_is_legal_type)(grpc_slice slice); +typedef int(*grpc_header_key_is_legal_type)(const char *key, size_t length); extern grpc_header_key_is_legal_type grpc_header_key_is_legal_import; #define grpc_header_key_is_legal grpc_header_key_is_legal_import -typedef int(*grpc_header_nonbin_value_is_legal_type)(grpc_slice slice); +typedef int(*grpc_header_nonbin_value_is_legal_type)(const char *value, size_t length); extern grpc_header_nonbin_value_is_legal_type grpc_header_nonbin_value_is_legal_import; #define grpc_header_nonbin_value_is_legal grpc_header_nonbin_value_is_legal_import -typedef int(*grpc_is_binary_header_type)(grpc_slice slice); +typedef int(*grpc_is_binary_header_type)(const char *key, size_t length); extern grpc_is_binary_header_type grpc_is_binary_header_import; #define grpc_is_binary_header grpc_is_binary_header_import typedef const char *(*grpc_call_error_to_string_type)(grpc_call_error error); @@ -488,9 +488,6 @@ extern grpc_slice_new_with_len_type grpc_slice_new_with_len_import; typedef grpc_slice(*grpc_slice_malloc_type)(size_t length); extern grpc_slice_malloc_type grpc_slice_malloc_import; #define grpc_slice_malloc grpc_slice_malloc_import -typedef grpc_slice(*grpc_slice_intern_type)(grpc_slice slice); -extern grpc_slice_intern_type grpc_slice_intern_import; -#define grpc_slice_intern grpc_slice_intern_import typedef grpc_slice(*grpc_slice_from_copied_string_type)(const char *source); extern grpc_slice_from_copied_string_type grpc_slice_from_copied_string_import; #define grpc_slice_from_copied_string grpc_slice_from_copied_string_import @@ -500,9 +497,6 @@ extern grpc_slice_from_copied_buffer_type grpc_slice_from_copied_buffer_import; typedef grpc_slice(*grpc_slice_from_static_string_type)(const char *source); extern grpc_slice_from_static_string_type grpc_slice_from_static_string_import; #define grpc_slice_from_static_string grpc_slice_from_static_string_import -typedef grpc_slice(*grpc_slice_from_static_buffer_type)(const void *source, size_t len); -extern grpc_slice_from_static_buffer_type grpc_slice_from_static_buffer_import; -#define grpc_slice_from_static_buffer grpc_slice_from_static_buffer_import typedef grpc_slice(*grpc_slice_sub_type)(grpc_slice s, size_t begin, size_t end); extern grpc_slice_sub_type grpc_slice_sub_import; #define grpc_slice_sub grpc_slice_sub_import @@ -515,51 +509,18 @@ extern grpc_slice_split_tail_type grpc_slice_split_tail_import; typedef grpc_slice(*grpc_slice_split_head_type)(grpc_slice *s, size_t split); extern grpc_slice_split_head_type grpc_slice_split_head_import; #define grpc_slice_split_head grpc_slice_split_head_import -typedef grpc_slice(*grpc_empty_slice_type)(void); -extern grpc_empty_slice_type grpc_empty_slice_import; -#define grpc_empty_slice grpc_empty_slice_import -typedef uint32_t(*grpc_slice_default_hash_impl_type)(grpc_slice s); -extern grpc_slice_default_hash_impl_type grpc_slice_default_hash_impl_import; -#define grpc_slice_default_hash_impl grpc_slice_default_hash_impl_import -typedef int(*grpc_slice_default_eq_impl_type)(grpc_slice a, grpc_slice b); -extern grpc_slice_default_eq_impl_type grpc_slice_default_eq_impl_import; -#define grpc_slice_default_eq_impl grpc_slice_default_eq_impl_import -typedef int(*grpc_slice_eq_type)(grpc_slice a, grpc_slice b); -extern grpc_slice_eq_type grpc_slice_eq_import; -#define grpc_slice_eq grpc_slice_eq_import +typedef grpc_slice(*gpr_empty_slice_type)(void); +extern gpr_empty_slice_type gpr_empty_slice_import; +#define gpr_empty_slice gpr_empty_slice_import typedef int(*grpc_slice_cmp_type)(grpc_slice a, grpc_slice b); extern grpc_slice_cmp_type grpc_slice_cmp_import; #define grpc_slice_cmp grpc_slice_cmp_import typedef int(*grpc_slice_str_cmp_type)(grpc_slice a, const char *b); extern grpc_slice_str_cmp_type grpc_slice_str_cmp_import; #define grpc_slice_str_cmp grpc_slice_str_cmp_import -typedef int(*grpc_slice_buf_cmp_type)(grpc_slice a, const void *b, size_t blen); -extern grpc_slice_buf_cmp_type grpc_slice_buf_cmp_import; -#define grpc_slice_buf_cmp grpc_slice_buf_cmp_import -typedef int(*grpc_slice_buf_start_eq_type)(grpc_slice a, const void *b, size_t blen); -extern grpc_slice_buf_start_eq_type grpc_slice_buf_start_eq_import; -#define grpc_slice_buf_start_eq grpc_slice_buf_start_eq_import -typedef int(*grpc_slice_rchr_type)(grpc_slice s, char c); -extern grpc_slice_rchr_type grpc_slice_rchr_import; -#define grpc_slice_rchr grpc_slice_rchr_import -typedef int(*grpc_slice_chr_type)(grpc_slice s, char c); -extern grpc_slice_chr_type grpc_slice_chr_import; -#define grpc_slice_chr grpc_slice_chr_import -typedef int(*grpc_slice_slice_type)(grpc_slice haystack, grpc_slice needle); -extern grpc_slice_slice_type grpc_slice_slice_import; -#define grpc_slice_slice grpc_slice_slice_import -typedef uint32_t(*grpc_slice_hash_type)(grpc_slice s); -extern grpc_slice_hash_type grpc_slice_hash_import; -#define grpc_slice_hash grpc_slice_hash_import typedef int(*grpc_slice_is_equivalent_type)(grpc_slice a, grpc_slice b); extern grpc_slice_is_equivalent_type grpc_slice_is_equivalent_import; #define grpc_slice_is_equivalent grpc_slice_is_equivalent_import -typedef grpc_slice(*grpc_slice_dup_type)(grpc_slice a); -extern grpc_slice_dup_type grpc_slice_dup_import; -#define grpc_slice_dup grpc_slice_dup_import -typedef char *(*grpc_slice_to_c_string_type)(grpc_slice s); -extern grpc_slice_to_c_string_type grpc_slice_to_c_string_import; -#define grpc_slice_to_c_string grpc_slice_to_c_string_import typedef void(*grpc_slice_buffer_init_type)(grpc_slice_buffer *sb); extern grpc_slice_buffer_init_type grpc_slice_buffer_init_import; #define grpc_slice_buffer_init grpc_slice_buffer_init_import diff --git a/src/ruby/ext/grpc/rb_server.c b/src/ruby/ext/grpc/rb_server.c index 7b2f5774aa..c7b112c94b 100644 --- a/src/ruby/ext/grpc/rb_server.c +++ b/src/ruby/ext/grpc/rb_server.c @@ -44,7 +44,6 @@ #include "rb_channel_args.h" #include "rb_completion_queue.h" #include "rb_server_credentials.h" -#include "rb_byte_buffer.h" #include "rb_grpc.h" /* grpc_rb_cServer is the ruby class that proxies grpc_server. */ @@ -167,6 +166,8 @@ static void grpc_request_call_stack_init(request_call_stack* st) { MEMZERO(st, request_call_stack, 1); grpc_metadata_array_init(&st->md_ary); grpc_call_details_init(&st->details); + st->details.method = NULL; + st->details.host = NULL; } /* grpc_request_call_stack_cleanup ensures the request_call_stack is properly @@ -190,7 +191,6 @@ static VALUE grpc_rb_server_request_call(VALUE self) { void *tag = (void*)&st; grpc_completion_queue *call_queue = grpc_completion_queue_create(NULL); gpr_timespec deadline; - TypedData_Get_Struct(self, grpc_rb_server, &grpc_rb_server_data_type, s); if (s->wrapped == NULL) { rb_raise(rb_eRuntimeError, "destroyed!"); @@ -218,13 +218,11 @@ static VALUE grpc_rb_server_request_call(VALUE self) { return Qnil; } - - /* build the NewServerRpc struct result */ deadline = gpr_convert_clock_type(st.details.deadline, GPR_CLOCK_REALTIME); result = rb_struct_new( - grpc_rb_sNewServerRpc, grpc_rb_slice_to_ruby_string(st.details.method), - grpc_rb_slice_to_ruby_string(st.details.host), + grpc_rb_sNewServerRpc, rb_str_new2(st.details.method), + rb_str_new2(st.details.host), rb_funcall(rb_cTime, id_at, 2, INT2NUM(deadline.tv_sec), INT2NUM(deadline.tv_nsec / 1000)), grpc_rb_md_ary_to_h(&st.md_ary), grpc_rb_wrap_call(call, call_queue), |