ruby-changes:22874
From: nobu <ko1@a...>
Date: Tue, 6 Mar 2012 12:32:59 +0900 (JST)
Subject: [ruby-changes:22874] nobu:r34923 (ruby_1_9_3): merge revision(s) 34376:
nobu 2012-03-06 12:32:28 +0900 (Tue, 06 Mar 2012) New Revision: 34923 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34923 Log: 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. Modified files: branches/ruby_1_9_3/ChangeLog branches/ruby_1_9_3/ext/io/console/console.c branches/ruby_1_9_3/ext/stringio/stringio.c branches/ruby_1_9_3/test/io/console/test_io_console.rb branches/ruby_1_9_3/version.h Index: ruby_1_9_3/ChangeLog =================================================================== --- ruby_1_9_3/ChangeLog (revision 34922) +++ ruby_1_9_3/ChangeLog (revision 34923) @@ -1,3 +1,10 @@ +Tue Mar 6 12:31:47 2012 Nobuyoshi Nakada <nobu@r...> + + * 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@s...> * io.c (Init_IO): Mention io/console methods. [Ruby 1.9 - Bug #5602] Index: ruby_1_9_3/ext/stringio/stringio.c =================================================================== --- ruby_1_9_3/ext/stringio/stringio.c (revision 34922) +++ ruby_1_9_3/ext/stringio/stringio.c (revision 34923) @@ -806,7 +806,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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); + } } Index: ruby_1_9_3/ext/io/console/console.c =================================================================== --- ruby_1_9_3/ext/io/console/console.c (revision 34922) +++ ruby_1_9_3/ext/io/console/console.c (revision 34923) @@ -623,6 +623,12 @@ 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 @@ 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); + } } Index: ruby_1_9_3/version.h =================================================================== --- ruby_1_9_3/version.h (revision 34922) +++ ruby_1_9_3/version.h (revision 34923) @@ -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 Index: ruby_1_9_3/test/io/console/test_io_console.rb =================================================================== --- ruby_1_9_3/test/io/console/test_io_console.rb (revision 34922) +++ ruby_1_9_3/test/io/console/test_io_console.rb (revision 34923) @@ -4,6 +4,7 @@ require 'pty' rescue LoadError end +require_relative '../../ruby/envutil' class TestIO_Console < Test::Unit::TestCase def test_raw @@ -175,8 +176,6 @@ 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 @@ 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 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/