[前][次][番号順一覧][スレッド一覧]

ruby-changes:58385

From: Koichi <ko1@a...>
Date: Thu, 24 Oct 2019 16:53:13 +0900 (JST)
Subject: [ruby-changes:58385] 38e931fa2c (master): show "transferred" attribute on Fiber#to_s

https://git.ruby-lang.org/ruby.git/commit/?id=38e931fa2c

From 38e931fa2ceac6d922f3eabedb8f35f211de0bdb Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Thu, 24 Oct 2019 16:28:15 +0900
Subject: show "transferred" attribute on Fiber#to_s

If a fiber is invoked with transfer method (such as "f.transfer"),
then the invoked fiber ("f") is labeled as "transferred" and this
fiber can not be invoked with Fiber#resume. This patch adds
transferred attribute for "Fiber#to_s" (and inspect).

diff --git a/cont.c b/cont.c
index 61f42b3..0db18bb 100644
--- a/cont.c
+++ b/cont.c
@@ -228,8 +228,8 @@ struct rb_fiber_struct { https://github.com/ruby/ruby/blob/trunk/cont.c#L228
     VALUE first_proc;
     struct rb_fiber_struct *prev;
     BITFIELD(enum fiber_status, status, 2);
-    /* If a fiber invokes "transfer",
-     * then this fiber can't "resume" any more after that.
+    /* If a fiber invokes by "transfer",
+     * then this fiber can't be invoked by "resume" any more after that.
      * You shouldn't mix "transfer" and "resume".
      */
     unsigned int transferred : 1;
@@ -2273,9 +2273,15 @@ fiber_to_s(VALUE fiber_value) https://github.com/ruby/ruby/blob/trunk/cont.c#L2273
 {
     const rb_fiber_t *fiber = fiber_ptr(fiber_value);
     const rb_proc_t *proc;
-    char status_info[0x10];
+    char status_info[0x20];
+
+    if (fiber->transferred) {
+        snprintf(status_info, 0x20, " (%s, transferred)", fiber_status_name(fiber->status));
+    }
+    else {
+        snprintf(status_info, 0x20, " (%s)", fiber_status_name(fiber->status));
+    }
 
-    snprintf(status_info, 0x10, " (%s)", fiber_status_name(fiber->status));
     if (!rb_obj_is_proc(fiber->first_proc)) {
         VALUE str = rb_any_to_s(fiber_value);
         strlcat(status_info, ">", sizeof(status_info));
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]