aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-04-10 10:52:33 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-04-10 10:52:33 +0900
commit63a5412db7138297a2e7513067ef80dad7a3b4b4 (patch)
treeb1c66e2e5962a51d38b269f470a4995b496f9843 /io.c
parent230efaf2ae3ca33ed1e3072458982f85d0e31347 (diff)
downloadruby-63a5412db7138297a2e7513067ef80dad7a3b4b4.tar.gz
Make `#inspect` interruptible in `Kernel#p`
Only writing the inspected result and a newline is uninterruptible.
Diffstat (limited to 'io.c')
-rw-r--r--io.c36
1 files changed, 16 insertions, 20 deletions
diff --git a/io.c b/io.c
index 2ba983cfbe..716528e2cf 100644
--- a/io.c
+++ b/io.c
@@ -7839,11 +7839,11 @@ rb_f_puts(int argc, VALUE *argv, VALUE recv)
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 */
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)
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);
}
/*