ruby-changes:60717
From: Nobuyoshi <ko1@a...>
Date: Fri, 10 Apr 2020 13:33:42 +0900 (JST)
Subject: [ruby-changes:60717] 63a5412db7 (master): Make `#inspect` interruptible in `Kernel#p`
https://git.ruby-lang.org/ruby.git/commit/?id=63a5412db7 From 63a5412db7138297a2e7513067ef80dad7a3b4b4 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Fri, 10 Apr 2020 10:52:33 +0900 Subject: Make `#inspect` interruptible in `Kernel#p` Only writing the inspected result and a newline is uninterruptible. diff --git a/io.c b/io.c index 2ba983c..716528e 100644 --- a/io.c +++ b/io.c @@ -7839,11 +7839,11 @@ rb_f_puts(int argc, VALUE *argv, VALUE recv) https://github.com/ruby/ruby/blob/trunk/io.c#L7839 return rb_funcallv(rb_stdout, rb_intern("puts"), argc, argv); } -void -rb_p(VALUE obj) /* for debug print within C code */ +static VALUE +rb_p_write(VALUE str) { VALUE args[2]; - args[0] = rb_obj_as_string(rb_inspect(obj)); + args[0] = str; args[1] = rb_default_rs; if (RB_TYPE_P(rb_stdout, T_FILE) && rb_method_basic_definition_p(CLASS_OF(rb_stdout), id_write)) { @@ -7852,25 +7852,20 @@ rb_p(VALUE obj) /* for debug print within C code */ https://github.com/ruby/ruby/blob/trunk/io.c#L7852 else { rb_io_writev(rb_stdout, 2, args); } + return Qnil; } -struct rb_f_p_arg { - int argc; - VALUE *argv; -}; +void +rb_p(VALUE obj) /* for debug print within C code */ +{ + rb_p_write(rb_obj_as_string(rb_inspect(obj))); +} static VALUE -rb_f_p_internal(VALUE arg) +rb_p_result(int argc, const VALUE *argv) { - struct rb_f_p_arg *arg1 = (struct rb_f_p_arg*)arg; - int argc = arg1->argc; - VALUE *argv = arg1->argv; - int i; VALUE ret = Qnil; - for (i=0; i<argc; i++) { - rb_p(argv[i]); - } if (argc == 1) { ret = argv[0]; } @@ -7904,11 +7899,12 @@ rb_f_p_internal(VALUE arg) https://github.com/ruby/ruby/blob/trunk/io.c#L7899 static VALUE rb_f_p(int argc, VALUE *argv, VALUE self) { - struct rb_f_p_arg arg; - arg.argc = argc; - arg.argv = argv; - - return rb_uninterruptible(rb_f_p_internal, (VALUE)&arg); + int i; + for (i=0; i<argc; i++) { + VALUE inspected = rb_obj_as_string(rb_inspect(argv[i])); + rb_uninterruptible(rb_p_write, inspected); + } + return rb_p_result(argc, argv); } /* -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/