THRIFT-2182 rb: segfault in regression tests (GC bug in rb_thrift_memory_buffer_write)
Patch: Paul Brannan
diff --git a/lib/rb/ext/compact_protocol.c b/lib/rb/ext/compact_protocol.c
index 1637e99..725d338 100644
--- a/lib/rb/ext/compact_protocol.c
+++ b/lib/rb/ext/compact_protocol.c
@@ -315,7 +315,7 @@
   buf = force_binary_encoding(buf);
   VALUE transport = GET_TRANSPORT(self);
   write_varint32(transport, RSTRING_LEN(buf));
-  WRITE(transport, RSTRING_PTR(buf), RSTRING_LEN(buf));
+  WRITE(transport, StringValuePtr(buf), RSTRING_LEN(buf));
   return Qnil;
 }
 
diff --git a/lib/rb/ext/memory_buffer.c b/lib/rb/ext/memory_buffer.c
index e7253dc..8b52c4a 100644
--- a/lib/rb/ext/memory_buffer.c
+++ b/lib/rb/ext/memory_buffer.c
@@ -39,7 +39,7 @@
 VALUE rb_thrift_memory_buffer_write(VALUE self, VALUE str) {
   VALUE buf = GET_BUF(self);
   str = force_binary_encoding(str);
-  rb_str_buf_cat(buf, RSTRING_PTR(str), RSTRING_LEN(str));
+  rb_str_buf_cat(buf, StringValuePtr(str), RSTRING_LEN(str));
   return Qnil;
 }
 
diff --git a/lib/rb/ext/struct.c b/lib/rb/ext/struct.c
index 8fbadbe..313da4c 100644
--- a/lib/rb/ext/struct.c
+++ b/lib/rb/ext/struct.c
@@ -607,7 +607,7 @@
     if (field_type == specified_type) {
       // read the value
       VALUE name = rb_hash_aref(field_info, name_sym);
-      rb_iv_set(self, "@setfield", ID2SYM(rb_intern(RSTRING_PTR(name))));
+      rb_iv_set(self, "@setfield", rb_str_intern(name));
       rb_iv_set(self, "@value", read_anything(protocol, field_type, field_info));
     } else {
       rb_funcall(protocol, skip_method_id, 1, field_type_value);