aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ruby/ext/grpc/rb_compression_options.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ruby/ext/grpc/rb_compression_options.c')
-rw-r--r--src/ruby/ext/grpc/rb_compression_options.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/ruby/ext/grpc/rb_compression_options.c b/src/ruby/ext/grpc/rb_compression_options.c
index 6200dbafeb..6b2467ee46 100644
--- a/src/ruby/ext/grpc/rb_compression_options.c
+++ b/src/ruby/ext/grpc/rb_compression_options.c
@@ -34,6 +34,7 @@
#include <ruby/ruby.h>
#include "rb_compression_options.h"
+#include "rb_byte_buffer.h"
#include "rb_grpc_imports.generated.h"
#include <grpc/compression.h>
@@ -168,9 +169,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) {
- char *name_str = NULL;
- long name_len = 0;
+ grpc_slice name_slice;
VALUE algorithm_name_as_string = Qnil;
+ char *tmp_str = NULL;
Check_Type(algorithm_name, T_SYMBOL);
@@ -178,16 +179,18 @@ 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_str = RSTRING_PTR(algorithm_name_as_string);
- name_len = RSTRING_LEN(algorithm_name_as_string);
+ name_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(algorithm_name_as_string), 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_str, name_len, algorithm_value)) {
+ if(!grpc_compression_algorithm_parse(name_slice, algorithm_value)) {
+ tmp_str = grpc_slice_to_c_string(name_slice);
rb_raise(rb_eNameError, "Invalid compression algorithm name: %s",
- StringValueCStr(algorithm_name_as_string));
+ tmp_str);
}
+
+ grpc_slice_unref(name_slice);
}
/* Indicates whether a given algorithm is enabled on this instance, given the