From 3338bc99e5163813cfe129844bcf397a77d4b916 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 13 Mar 2015 06:03:03 +0000 Subject: [PATCH] io.c: rb_io_get_fptr * io.c (rb_io_get_fptr): return non-null fptr. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49960 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- io.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/io.c b/io.c index 4287d96e74..06c3f8f7d6 100644 --- a/io.c +++ b/io.c @@ -651,6 +651,13 @@ rb_io_check_closed(rb_io_t *fptr) } } +static rb_io_t * +rb_io_get_fptr(VALUE io) +{ + rb_io_t *fptr = RFILE(io)->fptr; + rb_io_check_initialized(fptr); + return fptr; +} VALUE rb_io_get_io(VALUE io) @@ -668,8 +675,7 @@ VALUE rb_io_get_write_io(VALUE io) { VALUE write_io; - rb_io_check_initialized(RFILE(io)->fptr); - write_io = RFILE(io)->fptr->tied_io_for_writing; + write_io = rb_io_get_fptr(io)->tied_io_for_writing; if (write_io) { return write_io; } @@ -680,15 +686,15 @@ VALUE rb_io_set_write_io(VALUE io, VALUE w) { VALUE write_io; - rb_io_check_initialized(RFILE(io)->fptr); + rb_io_t *fptr = rb_io_get_fptr(io); if (!RTEST(w)) { w = 0; } else { GetWriteIO(w); } - write_io = RFILE(io)->fptr->tied_io_for_writing; - RFILE(io)->fptr->tied_io_for_writing = w; + write_io = fptr->tied_io_for_writing; + fptr->tied_io_for_writing = w; return write_io ? write_io : Qnil; } @@ -4422,8 +4428,7 @@ rb_io_close(VALUE io) static VALUE rb_io_close_m(VALUE io) { - rb_io_t *fptr = RFILE(io)->fptr; - rb_io_check_initialized(fptr); + rb_io_t *fptr = rb_io_get_fptr(io); if (fptr->fd < 0) { return Qnil; } @@ -4495,8 +4500,7 @@ rb_io_closed(VALUE io) } } - fptr = RFILE(io)->fptr; - rb_io_check_initialized(fptr); + fptr = rb_io_get_fptr(io); return 0 <= fptr->fd ? Qfalse : Qtrue; }