summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-08 19:19:22 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-08 19:19:22 +0000
commitebacc098943aab2e1d5e743f829f880621ea9833 (patch)
tree3dd9d874d09002458b93a741f9616c653616abcc
parent117fec74396341a72956bb0e3c5ed8c87614f7e5 (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_2@54042 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--ext/stringio/stringio.c12
-rw-r--r--test/stringio/test_stringio.rb9
-rw-r--r--version.h2
4 files changed, 27 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index ab2bfafe4e..44483b6e3f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Mar 9 04:15:20 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]
+
Wed Mar 9 04:05:36 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 cca408fcb5..ecd7b07203 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -497,7 +497,17 @@ 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();
+
+ 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 07d89d16e1..6d0bd5c803 100644
--- a/test/stringio/test_stringio.rb
+++ b/test/stringio/test_stringio.rb
@@ -586,4 +586,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 a796de7d44..a72b0a3e00 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.2.5"
#define RUBY_RELEASE_DATE "2016-03-09"
-#define RUBY_PATCHLEVEL 246
+#define RUBY_PATCHLEVEL 247
#define RUBY_RELEASE_YEAR 2016
#define RUBY_RELEASE_MONTH 3