diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-06 03:32:28 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-06 03:32:28 +0000 |
commit | c7495f996d672c0a132940951fa5d44e2c066a6f (patch) | |
tree | 8b6707ce1ec4701769cc0fd6729776aec4a85649 | |
parent | 9ca160c168abf64695e7ff89beb72c0ce5eed6a6 (diff) |
merge revision(s) 34376:
* ext/io/console/console.c (io_getch): default delegating method
for StringIO. https://github.com/nobu/io-console/issues/4
* ext/stringio/stringio.c: moved some methods to hidden modules.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34923 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | ext/io/console/console.c | 10 | ||||
-rw-r--r-- | ext/stringio/stringio.c | 43 | ||||
-rw-r--r-- | test/io/console/test_io_console.rb | 12 | ||||
-rw-r--r-- | version.h | 2 |
5 files changed, 54 insertions, 20 deletions
@@ -1,3 +1,10 @@ +Tue Mar 6 12:31:47 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * ext/io/console/console.c (io_getch): default delegating method + for StringIO. https://github.com/nobu/io-console/issues/4 + + * ext/stringio/stringio.c: moved some methods to hidden modules. + Tue Mar 6 12:29:34 2012 Eric Hodel <drbrain@segment7.net> * io.c (Init_IO): Mention io/console methods. [Ruby 1.9 - Bug #5602] diff --git a/ext/io/console/console.c b/ext/io/console/console.c index cd5ffd94fb..8a5c814dda 100644 --- a/ext/io/console/console.c +++ b/ext/io/console/console.c @@ -623,6 +623,12 @@ console_dev(VALUE klass) return con; } +static VALUE +io_getch(int argc, VALUE *argv, VALUE io) +{ + return rb_funcall2(io, rb_intern("getc"), argc, argv); +} + /* * IO console methods */ @@ -649,4 +655,8 @@ InitVM_console(void) rb_define_method(rb_cIO, "oflush", console_oflush, 0); rb_define_method(rb_cIO, "ioflush", console_ioflush, 0); rb_define_singleton_method(rb_cIO, "console", console_dev, 0); + { + VALUE mReadable = rb_define_module_under(rb_cIO, "readable"); + rb_define_method(mReadable, "getch", io_getch, -1); + } } diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 5aa2d27ef3..6c41c3c368 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -806,7 +806,7 @@ strio_ungetbyte(VALUE self, VALUE c) static VALUE strio_readchar(VALUE self) { - VALUE c = strio_getc(self); + VALUE c = rb_funcall2(self, rb_intern("getc"), 0, 0); if (NIL_P(c)) rb_eof_error(); return c; } @@ -820,7 +820,7 @@ strio_readchar(VALUE self) static VALUE strio_readbyte(VALUE self) { - VALUE c = strio_getbyte(self); + VALUE c = rb_funcall2(self, rb_intern("getbyte"), 0, 0); if (NIL_P(c)) rb_eof_error(); return c; } @@ -1037,7 +1037,7 @@ strio_gets(int argc, VALUE *argv, VALUE self) static VALUE strio_readline(int argc, VALUE *argv, VALUE self) { - VALUE line = strio_gets(argc, argv, self); + VALUE line = rb_funcall2(self, rb_intern("gets"), argc, argv); if (NIL_P(line)) rb_eof_error(); return line; } @@ -1288,14 +1288,14 @@ strio_read(int argc, VALUE *argv, VALUE self) static VALUE strio_sysread(int argc, VALUE *argv, VALUE self) { - VALUE val = strio_read(argc, argv, self); + VALUE val = rb_funcall2(self, rb_intern("read"), argc, argv); if (NIL_P(val)) { rb_eof_error(); } return val; } -#define strio_syswrite strio_write +#define strio_syswrite rb_io_write /* * call-seq: @@ -1459,25 +1459,13 @@ Init_stringio() rb_define_method(StringIO, "getc", strio_getc, 0); rb_define_method(StringIO, "ungetc", strio_ungetc, 1); rb_define_method(StringIO, "ungetbyte", strio_ungetbyte, 1); - rb_define_method(StringIO, "readchar", strio_readchar, 0); rb_define_method(StringIO, "getbyte", strio_getbyte, 0); - rb_define_method(StringIO, "readbyte", strio_readbyte, 0); rb_define_method(StringIO, "gets", strio_gets, -1); - rb_define_method(StringIO, "readline", strio_readline, -1); rb_define_method(StringIO, "readlines", strio_readlines, -1); rb_define_method(StringIO, "read", strio_read, -1); - rb_define_method(StringIO, "sysread", strio_sysread, -1); - rb_define_method(StringIO, "readpartial", strio_sysread, -1); - rb_define_method(StringIO, "read_nonblock", strio_sysread, -1); rb_define_method(StringIO, "write", strio_write, 1); - rb_define_method(StringIO, "<<", strio_addstr, 1); - rb_define_method(StringIO, "print", strio_print, -1); - rb_define_method(StringIO, "printf", strio_printf, -1); rb_define_method(StringIO, "putc", strio_putc, 1); - rb_define_method(StringIO, "puts", strio_puts, -1); - rb_define_method(StringIO, "syswrite", strio_syswrite, 1); - rb_define_method(StringIO, "write_nonblock", strio_syswrite, 1); rb_define_method(StringIO, "isatty", strio_isatty, 0); rb_define_method(StringIO, "tty?", strio_isatty, 0); @@ -1490,4 +1478,25 @@ Init_stringio() rb_define_method(StringIO, "external_encoding", strio_external_encoding, 0); rb_define_method(StringIO, "internal_encoding", strio_internal_encoding, 0); rb_define_method(StringIO, "set_encoding", strio_set_encoding, -1); + + { + VALUE mReadable = rb_define_module_under(rb_cIO, "readable"); + rb_define_method(mReadable, "readchar", strio_readchar, 0); + rb_define_method(mReadable, "readbyte", strio_readbyte, 0); + rb_define_method(mReadable, "readline", strio_readline, -1); + rb_define_method(mReadable, "sysread", strio_sysread, -1); + rb_define_method(mReadable, "readpartial", strio_sysread, -1); + rb_define_method(mReadable, "read_nonblock", strio_sysread, -1); + rb_include_module(StringIO, mReadable); + } + { + VALUE mWritable = rb_define_module_under(rb_cIO, "writable"); + rb_define_method(mWritable, "<<", strio_addstr, 1); + rb_define_method(mWritable, "print", strio_print, -1); + rb_define_method(mWritable, "printf", strio_printf, -1); + rb_define_method(mWritable, "puts", strio_puts, -1); + rb_define_method(mWritable, "syswrite", strio_syswrite, 1); + rb_define_method(mWritable, "write_nonblock", strio_syswrite, 1); + rb_include_module(StringIO, mWritable); + } } diff --git a/test/io/console/test_io_console.rb b/test/io/console/test_io_console.rb index b0fcbb7588..9c2fe1ac54 100644 --- a/test/io/console/test_io_console.rb +++ b/test/io/console/test_io_console.rb @@ -4,6 +4,7 @@ begin require 'pty' rescue LoadError end +require_relative '../../ruby/envutil' class TestIO_Console < Test::Unit::TestCase def test_raw @@ -175,8 +176,6 @@ class TestIO_Console < Test::Unit::TestCase end if defined?(PTY) and defined?(IO::console) class TestIO_Console < Test::Unit::TestCase - require_relative '../../ruby/envutil' - case when Process.respond_to?(:daemon) noctty = [EnvUtil.rubybin, "-e", "Process.daemon(true)"] @@ -194,6 +193,7 @@ class TestIO_Console < Test::Unit::TestCase t2 = Tempfile.new("console") t2.close cmd = NOCTTY + [ + '--disable=gems', '-rio/console', '-e', 'open(ARGV[0], "w") {|f| f.puts IO.console.inspect}', '-e', 'File.unlink(ARGV[1])', @@ -208,3 +208,11 @@ class TestIO_Console < Test::Unit::TestCase end end end if defined?(IO.console) + +class TestIO_Console < Test::Unit::TestCase + def test_stringio_getch + assert_ruby_status(%w"--disable=gems -rstringio -rio/console", "exit(StringIO.method_defined?(:getch))") + assert_ruby_status(%w"--disable=gems -rio/console -rstringio", "exit(StringIO.method_defined?(:getch))") + assert_ruby_status(%w"--disable=gems -rstringio", "exit(!StringIO.method_defined?(:getch))") + end +end @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.3" -#define RUBY_PATCHLEVEL 158 +#define RUBY_PATCHLEVEL 159 #define RUBY_RELEASE_DATE "2012-03-06" #define RUBY_RELEASE_YEAR 2012 |