From dc59c76898a6b6c3f87ec176660cb30fb2935370 Mon Sep 17 00:00:00 2001 From: normal Date: Mon, 4 Jan 2016 20:45:14 +0000 Subject: stringio: binmode sets encoding to ASCII-8BIT This should match the behavior of IO#binmode as far as treating content as ASCII-8BIT (binary). * ext/stringio/stringio.c (strio_binmode): implement to set encoding * test/stringio/test_stringio.rb (test_binmode): new test [ruby-core:72699] [Bug #11945] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53435 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/stringio/stringio.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'ext/stringio') diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 23c4356f97..bd83ea207b 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -493,7 +493,18 @@ strio_set_lineno(VALUE self, VALUE lineno) return lineno; } -#define strio_binmode strio_self +static VALUE +strio_binmode(VALUE self) +{ + struct StringIO *ptr = StringIO(self); + rb_encoding *enc = rb_ascii8bit_encoding(); + + ptr->enc = enc; + if (WRITABLE(self)) { + rb_enc_associate(ptr->string, enc); + } + return self; +} #define strio_fcntl strio_unimpl -- cgit v1.2.3