diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-17 18:02:53 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-17 18:02:53 +0000 |
commit | d4454d0123214c95b4fb6f3c7846e2858ad3fd99 (patch) | |
tree | fcab5233ebdc658fda03cbf45d9d2817c3ccd6bc /io.c | |
parent | ab742d9d2ee6f56d987b17ebd1795d5922c47172 (diff) | |
download | ruby-d4454d0123214c95b4fb6f3c7846e2858ad3fd99.tar.gz |
io.c (argf_read_nonblock): support `exception: false'
This is a preparation for [ruby-core:69892]
("io.c: avoid kwarg parsing in C API")
since I noticed ARGF.read_nonblock did not properly catch up to
the `exception: false' change.
* io.c (argf_read_nonblock): support `exception: false'
(io_nonblock_eof): new function
(io_read_nonblock): use io_nonblock_eof
(argf_getpartial): accept kwargs hash for `exception: false'
* test/ruby/test_argf.rb (test_read_nonblock): new test
[ruby-core:70000] [Feature #11358]
* NEWS: add item for ARGF.read_nonblock
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 39 |
1 files changed, 27 insertions, 12 deletions
@@ -2619,6 +2619,15 @@ io_readpartial(int argc, VALUE *argv, VALUE io) return ret; } +static VALUE +io_nonblock_eof(VALUE opts) +{ + if (!no_exception_p(opts)) { + rb_eof_error(); + } + return Qnil; +} + /* * call-seq: * ios.read_nonblock(maxlen) -> string @@ -2680,10 +2689,7 @@ io_read_nonblock(int argc, VALUE *argv, VALUE io) ret = io_getpartial(argc, argv, io, opts, 1); if (NIL_P(ret)) { - if (no_exception_p(opts)) - return Qnil; - else - rb_eof_error(); + return io_nonblock_eof(opts); } return ret; } @@ -11139,7 +11145,8 @@ argf_forward_call(VALUE arg) return Qnil; } -static VALUE argf_getpartial(int argc, VALUE *argv, VALUE argf, int nonblock); +static VALUE argf_getpartial(int argc, VALUE *argv, VALUE argf, VALUE opts, + int nonblock); /* * call-seq: @@ -11164,7 +11171,7 @@ static VALUE argf_getpartial(int argc, VALUE *argv, VALUE argf, int nonblock); static VALUE argf_readpartial(int argc, VALUE *argv, VALUE argf) { - return argf_getpartial(argc, argv, argf, 0); + return argf_getpartial(argc, argv, argf, Qnil, 0); } /* @@ -11178,11 +11185,18 @@ argf_readpartial(int argc, VALUE *argv, VALUE argf) static VALUE argf_read_nonblock(int argc, VALUE *argv, VALUE argf) { - return argf_getpartial(argc, argv, argf, 1); + VALUE opts; + + rb_scan_args(argc, argv, "11:", NULL, NULL, &opts); + + if (!NIL_P(opts)) + argc--; + + return argf_getpartial(argc, argv, argf, opts, 1); } static VALUE -argf_getpartial(int argc, VALUE *argv, VALUE argf, int nonblock) +argf_getpartial(int argc, VALUE *argv, VALUE argf, VALUE opts, int nonblock) { VALUE tmp, str, length; @@ -11205,16 +11219,17 @@ argf_getpartial(int argc, VALUE *argv, VALUE argf, int nonblock) RUBY_METHOD_FUNC(0), Qnil, rb_eEOFError, (VALUE)0); } else { - tmp = io_getpartial(argc, argv, ARGF.current_file, Qnil, nonblock); + tmp = io_getpartial(argc, argv, ARGF.current_file, opts, nonblock); } if (NIL_P(tmp)) { if (ARGF.next_p == -1) { - rb_eof_error(); + return io_nonblock_eof(opts); } argf_close(argf); ARGF.next_p = 1; - if (RARRAY_LEN(ARGF.argv) == 0) - rb_eof_error(); + if (RARRAY_LEN(ARGF.argv) == 0) { + return io_nonblock_eof(opts); + } if (NIL_P(str)) str = rb_str_new(NULL, 0); return str; |