From 945e4692ca9898c0595ef30437ec3a45b75483a4 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 25 Dec 2014 07:14:12 +0000 Subject: console.c: IO.console arguments passing * ext/io/console/console.c (console_dev): send the given arguments to the opened console. as a special case, do nothing if :close is given. * test/lib/leakchecker.rb (LeakChecker#check_fd_leak): close if console. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48993 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 ++++++++ ext/io/console/console.c | 43 +++++++++++++++++++++++++++++++------- test/io/console/test_io_console.rb | 8 +++++++ test/lib/leakchecker.rb | 3 +++ 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5a7dbf826d..e17071e2a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Thu Dec 25 16:14:10 2014 Nobuyoshi Nakada + + * ext/io/console/console.c (console_dev): send the given arguments + to the opened console. as a special case, do nothing if :close + is given. + + * test/lib/leakchecker.rb (LeakChecker#check_fd_leak): close if + console. + Thu Dec 25 16:01:19 2014 Nobuyoshi Nakada * file.c (rb_file_expand_path_internal): drop characters ignored diff --git a/ext/io/console/console.c b/ext/io/console/console.c index 0290a65a72..e846450007 100644 --- a/ext/io/console/console.c +++ b/ext/io/console/console.c @@ -77,7 +77,7 @@ getattr(int fd, conmode *t) #define SET_LAST_ERROR (0) #endif -static ID id_getc, id_console; +static ID id_getc, id_console, id_close; typedef struct { int vmin; @@ -629,27 +629,49 @@ console_ioflush(VALUE io) /* * call-seq: * IO.console -> # + * IO.console(sym, *args) * * Returns an File instance opened console. * + * If +sym+ is given, it will be sent to the opened console with + * +args+ and the result will be returned instead of the console IO + * itself. + * * You must require 'io/console' to use this method. */ static VALUE -console_dev(VALUE klass) +console_dev(int argc, VALUE *argv, VALUE klass) { VALUE con = 0; rb_io_t *fptr; + VALUE sym = 0; + rb_check_arity(argc, 0, 1); + if (argc) { + Check_Type(sym = argv[0], T_SYMBOL); + --argc; + ++argv; + } if (klass == rb_cIO) klass = rb_cFile; if (rb_const_defined(klass, id_console)) { con = rb_const_get(klass, id_console); - if (RB_TYPE_P(con, T_FILE)) { - if ((fptr = RFILE(con)->fptr) && GetReadFD(fptr) != -1) - return con; + if (!RB_TYPE_P(con, T_FILE) || + (!(fptr = RFILE(con)->fptr) || GetReadFD(fptr) == -1)) { + rb_const_remove(klass, id_console); + con = 0; } - rb_const_remove(klass, id_console); } - { + if (sym) { + if (sym == ID2SYM(id_close) && !argc) { + if (con) { + rb_io_close(con); + rb_const_remove(klass, id_console); + con = 0; + } + return Qnil; + } + } + if (!con) { VALUE args[2]; #if defined HAVE_TERMIOS_H || defined HAVE_TERMIO_H || defined HAVE_SGTTY_H # define CONSOLE_DEVICE "/dev/tty" @@ -697,6 +719,10 @@ console_dev(VALUE klass) fptr->mode |= FMODE_SYNC; rb_const_set(klass, id_console, con); } + if (sym) { + /* TODO: avoid inadvertent pindown */ + return rb_funcall(con, SYM2ID(sym), argc, argv); + } return con; } @@ -720,6 +746,7 @@ Init_console(void) { id_getc = rb_intern("getc"); id_console = rb_intern("console"); + id_close = rb_intern("close"); InitVM(console); } @@ -739,7 +766,7 @@ InitVM_console(void) rb_define_method(rb_cIO, "iflush", console_iflush, 0); 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); + rb_define_singleton_method(rb_cIO, "console", console_dev, -1); { VALUE mReadable = rb_define_module_under(rb_cIO, "generic_readable"); rb_define_method(mReadable, "getch", io_getch, -1); diff --git a/test/io/console/test_io_console.rb b/test/io/console/test_io_console.rb index 237a41a35f..3481a2b213 100644 --- a/test/io/console/test_io_console.rb +++ b/test/io/console/test_io_console.rb @@ -222,14 +222,22 @@ class TestIO_Console < Test::Unit::TestCase IO.console.close assert_kind_of(IO, IO.console) assert_nothing_raised(IOError) {IO.console.fileno} + + IO.console(:close) + assert(IO.console(:tty?)) + ensure + IO.console(:close) end def test_sync assert(IO.console.sync, "console should be unbuffered") + ensure + IO.console(:close) end else def test_close assert_equal(["true"], run_pty("IO.console.close; p IO.console.fileno >= 0")) + assert_equal(["true"], run_pty("IO.console(:close); p IO.console(:tty?)")) end def test_sync diff --git a/test/lib/leakchecker.rb b/test/lib/leakchecker.rb index 5d05c1e456..37c87c9f72 100644 --- a/test/lib/leakchecker.rb +++ b/test/lib/leakchecker.rb @@ -31,6 +31,9 @@ class LeakChecker def check_fd_leak(test_name) leaked = false live1 = @fd_info + if IO.respond_to?(:console) + IO.console(:close) + end live2 = find_fds fd_closed = live1 - live2 if !fd_closed.empty? -- cgit v1.2.3 From e13315da2f352643c356b4d754b728b21e770c13 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 25 Dec 2014 08:27:09 +0000 Subject: configure.in: include winsock2.h * configure.in (NET_LUID): include winsock2.h instead of windows.h. patch by Jon Forums in [ruby-core:67125]. [Bug #10640] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ configure.in | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index e17071e2a8..30a25a6ca3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Dec 25 17:27:06 2014 Nobuyoshi Nakada + + * configure.in (NET_LUID): include winsock2.h instead of windows.h. + patch by Jon Forums in [ruby-core:67125]. [Bug #10640] + Thu Dec 25 16:14:10 2014 Nobuyoshi Nakada * ext/io/console/console.c (console_dev): send the given arguments diff --git a/configure.in b/configure.in index ae08fa0956..375ef5533c 100644 --- a/configure.in +++ b/configure.in @@ -1102,8 +1102,7 @@ main() ac_cv_func_malloc_usable_size=no { test "$target_cpu" = x64 && ac_cv_func___builtin_setjmp=no; } AC_CHECK_TYPE([NET_LUID], [], [], - [@%:@include - @%:@include + [@%:@include @%:@include ]) if test x"$ac_cv_type_NET_LUID" = xyes; then AC_DEFINE(HAVE_TYPE_NET_LUID, 1) -- cgit v1.2.3 From 7632a82d5750b7908bd173eda3268ecb0855b934 Mon Sep 17 00:00:00 2001 From: ngoto Date: Thu, 25 Dec 2014 08:33:41 +0000 Subject: * gc.c (wmap_final_func): fix memory size shortage when realloc wmap. Fix SEGV during finilize of WeakRef on Solaris (though the SEGV could occur on all OS/platforms). [ruby-dev:48779] [Bug #10646] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48999 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ gc.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 30a25a6ca3..6e1cc77216 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Thu Dec 25 17:30:40 2014 Naohisa Goto + + * gc.c (wmap_final_func): fix memory size shortage when realloc wmap. + Fix SEGV during finilize of WeakRef on Solaris (though the SEGV + could occur on all OS/platforms). [ruby-dev:48779] [Bug #10646] + Thu Dec 25 17:27:06 2014 Nobuyoshi Nakada * configure.in (NET_LUID): include winsock2.h instead of windows.h. diff --git a/gc.c b/gc.c index c75f8637c0..5f67bdec29 100644 --- a/gc.c +++ b/gc.c @@ -7672,7 +7672,7 @@ wmap_final_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing) return ST_DELETE; } if (j < i) { - ptr = ruby_sized_xrealloc2(ptr, j, sizeof(VALUE), i); + ptr = ruby_sized_xrealloc2(ptr, j + 1, sizeof(VALUE), i); ptr[0] = j; *value = (st_data_t)ptr; } -- cgit v1.2.3