From 38e931fa2ceac6d922f3eabedb8f35f211de0bdb Mon Sep 17 00:00:00 2001 From: Koichi Sasada 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). --- cont.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'cont.c') diff --git a/cont.c b/cont.c index 61f42b386f..0db18bb813 100644 --- a/cont.c +++ b/cont.c @@ -228,8 +228,8 @@ struct rb_fiber_struct { 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) { 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 v1.2.3