ruby-changes:63317
From: Nobuyoshi <ko1@a...>
Date: Sun, 11 Oct 2020 02:01:08 +0900 (JST)
Subject: [ruby-changes:63317] a79966743c (master): [ruby/io-console] Fix timeout type error (#18)
https://git.ruby-lang.org/ruby.git/commit/?id=a79966743c From a79966743c346bfc588022db29229b79bee51d45 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sun, 11 Oct 2020 01:51:18 +0900 Subject: [ruby/io-console] Fix timeout type error (#18) Fixed TypeError when IO#getch timed out `rb_io_wait` returns a bit-flags Integer representing available events, or Qfalse if timed out. Also the result of `NUM2INT` is not a `VALUE`. ``` $ ./bin/ruby -v -rio/console -e "p IO.console.getch(intr: true, time: 0.1)" ruby 3.0.0dev (2020-10-09T20:27:30Z master 5ea2ea74cc) [x64-mingw32] -e:1:in `getch': no implicit conversion of false into Integer (TypeError) from -e:1:in `<main>' ``` https://github.com/ruby/io-console/commit/3bdfaf62df diff --git a/ext/io/console/console.c b/ext/io/console/console.c index 50baf4f..11ce699 100644 --- a/ext/io/console/console.c +++ b/ext/io/console/console.c @@ -546,7 +546,7 @@ console_getch(int argc, VALUE *argv, VALUE io) https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L546 if (w < 0) rb_eof_error(); if (!(w & RB_WAITFD_IN)) return Qnil; # else - VALUE result = RB_NUM2INT(rb_io_wait(io, RUBY_IO_READABLE, timeout)); + VALUE result = rb_io_wait(io, RUBY_IO_READABLE, timeout); if (result == Qfalse) return Qnil; # endif } diff --git a/test/io/console/test_io_console.rb b/test/io/console/test_io_console.rb index 3613a2c..3962de3 100644 --- a/test/io/console/test_io_console.rb +++ b/test/io/console/test_io_console.rb @@ -471,6 +471,10 @@ defined?(IO.console) and TestIO_Console.class_eval do https://github.com/ruby/ruby/blob/trunk/test/io/console/test_io_console.rb#L471 ensure IO.console(:close) end + + def test_getch_timeout + assert_nil(IO.console.getch(intr: true, time: 0.1, min: 0)) + end end end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/