diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-03 03:52:57 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-03 03:52:57 +0000 |
commit | 101e636de7381afcaea2e7dd192dee0364ce9545 (patch) | |
tree | 21c898b5160d916fbf46d85e9aee5a318e7c2d02 /ext | |
parent | 6ed3a3524a05dbd22cab4440dd81f7c76ea67afd (diff) |
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
Diffstat (limited to 'ext')
-rw-r--r-- | ext/stringio/stringio.c | 10 |
1 files changed, 8 insertions, 2 deletions
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); } |