diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-05-28 14:38:54 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-05-28 14:38:54 +0000 |
commit | fc9677332a1f2ce41912b57886d4733d61d192f1 (patch) | |
tree | c884ede1e13ecf09b132e42d27e4361fa3168998 /ext | |
parent | 7ebed66e59efe774ebbd890f2a56c8a54498e22f (diff) |
merge revision(s) r45646: [Backport #9765]
* ext/stringio/stringio.c (strio_putc): fix for non-ascii
encoding, like as IO#putc. [ruby-dev:48114] [Bug #9765]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@46213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/stringio/stringio.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 3fef619de6..fb8e7ce3ea 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -1233,17 +1233,17 @@ static VALUE strio_putc(VALUE self, VALUE ch) { struct StringIO *ptr = writable(self); - int c = NUM2CHR(ch); - long olen; + VALUE str; check_modifiable(ptr); - olen = RSTRING_LEN(ptr->string); - if (ptr->flags & FMODE_APPEND) { - ptr->pos = olen; + if (RB_TYPE_P(ch, T_STRING)) { + str = rb_str_substr(ch, 0, 1); } - strio_extend(ptr, ptr->pos, 1); - RSTRING_PTR(ptr->string)[ptr->pos++] = c; - OBJ_INFECT(ptr->string, self); + else { + char c = NUM2CHR(ch); + str = rb_str_new(&c, 1); + } + strio_write(self, str); return ch; } |