From 101e636de7381afcaea2e7dd192dee0364ce9545 Mon Sep 17 00:00:00 2001 From: usa Date: Wed, 3 Sep 2014 03:52:57 +0000 Subject: merge revision(s) 45676,45677: [Backport #9769] stringio.c: move GC guard * ext/stringio/stringio.c (strio_write): move GC guard after the last using position. * ext/stringio/stringio.c (strio_write): use rb_str_append to reuse coderange bits other than ASCII-8BIT, and keep taintedness. [ruby-dev:48118] [Bug #9769] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47366 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/stringio/stringio.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'ext') diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 15ef44aa35..2e7c367276 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -1172,7 +1172,6 @@ strio_write(VALUE self, VALUE str) long len, olen; rb_encoding *enc, *enc2; - RB_GC_GUARD(str); if (!RB_TYPE_P(str, T_STRING)) str = rb_obj_as_string(str); enc = rb_enc_get(ptr->string); @@ -1188,7 +1187,13 @@ strio_write(VALUE self, VALUE str) ptr->pos = olen; } if (ptr->pos == olen) { - rb_str_cat(ptr->string, RSTRING_PTR(str), len); + if (enc2 == rb_ascii8bit_encoding()) { + rb_enc_str_buf_cat(ptr->string, RSTRING_PTR(str), len, enc); + OBJ_INFECT(ptr->string, str); + } + else { + rb_str_buf_append(ptr->string, str); + } } else { strio_extend(ptr, ptr->pos, len); @@ -1196,6 +1201,7 @@ strio_write(VALUE self, VALUE str) OBJ_INFECT(ptr->string, str); } OBJ_INFECT(ptr->string, self); + RB_GC_GUARD(str); ptr->pos += len; return LONG2NUM(len); } -- cgit v1.2.3