summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-29 05:00:42 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-29 05:00:42 +0000
commit7485f7467964570986efcc22f57da433ab48e959 (patch)
tree52d899e4099f24264e5e28e5ba428b2b40718091
parente6489da9e3ddf6b109aa3db22be414c84ec4afab (diff)
merge revision(s) 53435: [Backport #11945]
* 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/branches/ruby_2_3@54353 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--ext/stringio/stringio.c13
-rw-r--r--test/stringio/test_stringio.rb9
-rw-r--r--version.h2
4 files changed, 28 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 1dfc038a51..7d3684ec0b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Tue Mar 29 13:56:36 2016 Eric Wong <e@80x24.org>
+
+ * ext/stringio/stringio.c (strio_binmode): implement to set encoding
+ * test/stringio/test_stringio.rb (test_binmode): new test
+ [ruby-core:72699] [Bug #11945]
+
Tue Mar 29 13:50:30 2016 Eric Wong <e@80x24.org>
* io.c (io_getpartial): remove unused kwarg from template
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
diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb
index 9a041c2148..75bf73aa0f 100644
--- a/test/stringio/test_stringio.rb
+++ b/test/stringio/test_stringio.rb
@@ -644,4 +644,13 @@ class TestStringIO < Test::Unit::TestCase
assert_raise(ArgumentError, "[ruby-dev:43392]") { StringIO.new.each_line(0){} }
assert_raise(ArgumentError, "[ruby-dev:43392]") { StringIO.new.each_line("a",0){} }
end
+
+ def test_binmode
+ s = StringIO.new
+ s.set_encoding('utf-8')
+ assert_same s, s.binmode
+
+ bug_11945 = '[ruby-core:72699] [Bug #11945]'
+ assert_equal Encoding::ASCII_8BIT, s.external_encoding, bug_11945
+ end
end
diff --git a/version.h b/version.h
index 50f4efd3d7..3bcd92d21f 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.3.0"
#define RUBY_RELEASE_DATE "2016-03-29"
-#define RUBY_PATCHLEVEL 11
+#define RUBY_PATCHLEVEL 12
#define RUBY_RELEASE_YEAR 2016
#define RUBY_RELEASE_MONTH 3