ruby-changes:37528
From: nobu <ko1@a...>
Date: Mon, 16 Feb 2015 12:43:25 +0900 (JST)
Subject: [ruby-changes:37528] nobu:r49609 (trunk): console.c: avoid inadvertent pindown
nobu 2015-02-16 12:43:18 +0900 (Mon, 16 Feb 2015) New Revision: 49609 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49609 Log: console.c: avoid inadvertent pindown * ext/io/console/console.c (console_dev): call Kernel#__send__ method to avoid inadvertent pindown. Modified files: trunk/ext/io/console/console.c Index: ext/io/console/console.c =================================================================== --- ext/io/console/console.c (revision 49608) +++ ext/io/console/console.c (revision 49609) @@ -79,6 +79,25 @@ getattr(int fd, conmode *t) https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L79 static ID id_getc, id_console, id_close; +#ifndef HAVE_RB_F_SEND +static ID id___send__; + +static VALUE +rb_f_send(int argc, VALUE *argv, VALUE recv) +{ + VALUE sym = argv[0]; + ID vid = rb_check_id(&sym); + if (vid) { + --argc; + ++argv; + } + else { + vid = id___send__; + } + return rb_funcallv(recv, vid, argc, argv); +} +#endif + typedef struct { int vmin; int vtime; @@ -649,8 +668,6 @@ console_dev(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L668 rb_check_arity(argc, 0, UNLIMITED_ARGUMENTS); 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)) { @@ -662,7 +679,7 @@ console_dev(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L679 } } if (sym) { - if (sym == ID2SYM(id_close) && !argc) { + if (sym == ID2SYM(id_close) && argc == 1) { if (con) { rb_io_close(con); rb_const_remove(klass, id_console); @@ -720,8 +737,7 @@ console_dev(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L737 rb_const_set(klass, id_console, con); } if (sym) { - /* TODO: avoid inadvertent pindown */ - return rb_funcallv(con, SYM2ID(sym), argc, argv); + return rb_f_send(argc, argv, con); } return con; } @@ -744,9 +760,13 @@ io_getch(int argc, VALUE *argv, VALUE io https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L760 void Init_console(void) { +#undef rb_intern id_getc = rb_intern("getc"); id_console = rb_intern("console"); id_close = rb_intern("close"); +#ifndef HAVE_RB_F_SEND + id___send__ = rb_intern("__send__"); +#endif InitVM(console); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/