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).
This commit is contained in:
Koichi Sasada 2019-10-24 16:28:15 +09:00
Родитель 4c3e3b8028
Коммит 38e931fa2c
1 изменённых файлов: 10 добавлений и 4 удалений

14
cont.c
Просмотреть файл

@ -228,8 +228,8 @@ struct rb_fiber_struct {
VALUE first_proc; VALUE first_proc;
struct rb_fiber_struct *prev; struct rb_fiber_struct *prev;
BITFIELD(enum fiber_status, status, 2); BITFIELD(enum fiber_status, status, 2);
/* If a fiber invokes "transfer", /* If a fiber invokes by "transfer",
* then this fiber can't "resume" any more after that. * then this fiber can't be invoked by "resume" any more after that.
* You shouldn't mix "transfer" and "resume". * You shouldn't mix "transfer" and "resume".
*/ */
unsigned int transferred : 1; 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_fiber_t *fiber = fiber_ptr(fiber_value);
const rb_proc_t *proc; 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)) { if (!rb_obj_is_proc(fiber->first_proc)) {
VALUE str = rb_any_to_s(fiber_value); VALUE str = rb_any_to_s(fiber_value);
strlcat(status_info, ">", sizeof(status_info)); strlcat(status_info, ">", sizeof(status_info));