From 90e393b3687d783f7820a9f6055c6bb5a94f85a1 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 21 Apr 2014 05:11:50 +0000 Subject: stringio.c: non-ascii encoding * 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/trunk@45646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/stringio/stringio.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'ext') diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index db3732e072..e964e79e12 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; } -- cgit v1.2.3