ruby-changes:68296
From: Nobuyoshi <ko1@a...>
Date: Thu, 7 Oct 2021 19:59:06 +0900 (JST)
Subject: [ruby-changes:68296] 606e785fa8 (master): Reuse ractor stderr
https://git.ruby-lang.org/ruby.git/commit/?id=606e785fa8 From 606e785fa8ec26c2819caca8b1f238e3ef5d8ff0 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Thu, 7 Oct 2021 17:59:16 +0900 Subject: Reuse ractor stderr --- io.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/io.c b/io.c index 2a736ceb27..50c9fea62c 100644 --- a/io.c +++ b/io.c @@ -8168,15 +8168,16 @@ rb_obj_display(int argc, VALUE *argv, VALUE self) https://github.com/ruby/ruby/blob/trunk/io.c#L8168 } static int -rb_stderr_to_original_p(void) +rb_stderr_to_original_p(VALUE err) { - return (rb_ractor_stderr() == orig_stderr || RFILE(orig_stderr)->fptr->fd < 0); + return (err == orig_stderr || RFILE(orig_stderr)->fptr->fd < 0); } void rb_write_error2(const char *mesg, long len) { - if (rb_stderr_to_original_p()) { + VALUE out = rb_ractor_stderr(); + if (rb_stderr_to_original_p(out)) { #ifdef _WIN32 if (isatty(fileno(stderr))) { if (rb_w32_write_console(rb_str_new(mesg, len), fileno(stderr)) > 0) return; @@ -8188,7 +8189,7 @@ rb_write_error2(const char *mesg, long len) https://github.com/ruby/ruby/blob/trunk/io.c#L8189 } } else { - rb_io_write(rb_ractor_stderr(), rb_str_new(mesg, len)); + rb_io_write(out, rb_str_new(mesg, len)); } } @@ -8201,8 +8202,9 @@ rb_write_error(const char *mesg) https://github.com/ruby/ruby/blob/trunk/io.c#L8202 void rb_write_error_str(VALUE mesg) { + VALUE out = rb_ractor_stderr(); /* a stopgap measure for the time being */ - if (rb_stderr_to_original_p()) { + if (rb_stderr_to_original_p(out)) { size_t len = (size_t)RSTRING_LEN(mesg); #ifdef _WIN32 if (isatty(fileno(stderr))) { @@ -8216,14 +8218,14 @@ rb_write_error_str(VALUE mesg) https://github.com/ruby/ruby/blob/trunk/io.c#L8218 } else { /* may unlock GVL, and */ - rb_io_write(rb_ractor_stderr(), mesg); + rb_io_write(out, mesg); } } int rb_stderr_tty_p(void) { - if (rb_stderr_to_original_p()) + if (rb_stderr_to_original_p(rb_ractor_stderr())) return isatty(fileno(stderr)); return 0; } -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/