ruby-changes:71894
From: Nobuyoshi <ko1@a...>
Date: Fri, 20 May 2022 18:02:10 +0900 (JST)
Subject: [ruby-changes:71894] 0dfd5d19f3 (master): [ruby/io-nonblock] Rename `io_nonblock_mode` and extract `set_fcntl_flags`
https://git.ruby-lang.org/ruby.git/commit/?id=0dfd5d19f3 From 0dfd5d19f3f98b596ad524e4369086fc031065cd Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Thu, 21 Apr 2022 17:03:11 +0900 Subject: [ruby/io-nonblock] Rename `io_nonblock_mode` and extract `set_fcntl_flags` https://github.com/ruby/io-nonblock/commit/22f08574df --- ext/io/nonblock/nonblock.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/ext/io/nonblock/nonblock.c b/ext/io/nonblock/nonblock.c index e5915fa128..b8a40ff38e 100644 --- a/ext/io/nonblock/nonblock.c +++ b/ext/io/nonblock/nonblock.c @@ -19,14 +19,14 @@ https://github.com/ruby/ruby/blob/trunk/ext/io/nonblock/nonblock.c#L19 #ifdef F_GETFL static int -io_nonblock_mode(int fd) +get_fcntl_flags(int fd) { int f = fcntl(fd, F_GETFL); if (f == -1) rb_sys_fail(0); return f; } #else -#define io_nonblock_mode(fd) ((void)(fd), 0) +#define get_fcntl_flags(fd) ((void)(fd), 0) #endif #ifdef F_GETFL @@ -41,7 +41,7 @@ rb_io_nonblock_p(VALUE io) https://github.com/ruby/ruby/blob/trunk/ext/io/nonblock/nonblock.c#L41 { rb_io_t *fptr; GetOpenFile(io, fptr); - if (io_nonblock_mode(fptr->fd) & O_NONBLOCK) + if (get_fcntl_flags(fptr->fd) & O_NONBLOCK) return Qtrue; return Qfalse; } @@ -50,6 +50,13 @@ rb_io_nonblock_p(VALUE io) https://github.com/ruby/ruby/blob/trunk/ext/io/nonblock/nonblock.c#L50 #endif #ifdef F_SETFL +static void +set_fcntl_flags(int fd, int f) +{ + if (fcntl(fd, F_SETFL, f) == -1) + rb_sys_fail(0); +} + static int io_nonblock_set(int fd, int f, int nb) { @@ -63,8 +70,7 @@ io_nonblock_set(int fd, int f, int nb) https://github.com/ruby/ruby/blob/trunk/ext/io/nonblock/nonblock.c#L70 return 0; f &= ~O_NONBLOCK; } - if (fcntl(fd, F_SETFL, f) == -1) - rb_sys_fail(0); + set_fcntl_flags(fd, f); return 1; } @@ -123,7 +129,7 @@ rb_io_nonblock_set(VALUE io, VALUE nb) https://github.com/ruby/ruby/blob/trunk/ext/io/nonblock/nonblock.c#L129 if (RTEST(nb)) rb_io_set_nonblock(fptr); else - io_nonblock_set(fptr->fd, io_nonblock_mode(fptr->fd), RTEST(nb)); + io_nonblock_set(fptr->fd, get_fcntl_flags(fptr->fd), RTEST(nb)); return io; } @@ -131,8 +137,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/io/nonblock/nonblock.c#L137 io_nonblock_restore(VALUE arg) { int *restore = (int *)arg; - if (fcntl(restore[0], F_SETFL, restore[1]) == -1) - rb_sys_fail(0); + set_fcntl_flags(restore[0], restore[1]); return Qnil; } @@ -159,7 +164,7 @@ rb_io_nonblock_block(int argc, VALUE *argv, VALUE io) https://github.com/ruby/ruby/blob/trunk/ext/io/nonblock/nonblock.c#L164 rb_scan_args(argc, argv, "01", &v); nb = RTEST(v); } - f = io_nonblock_mode(fptr->fd); + f = get_fcntl_flags(fptr->fd); restore[0] = fptr->fd; restore[1] = f; if (!io_nonblock_set(fptr->fd, f, nb)) -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/