diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-10 02:58:36 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-10 02:58:36 +0000 |
commit | 43384ae9788be243746849ee54d9f5c8f7e0412b (patch) | |
tree | e696a34c00d2d333a01e85e91e964e2f8a40e707 /proc.c | |
parent | 57199f2125ce8e2043420af6ccc3354e1d411c0f (diff) |
Fiber#to_s (#inspect) return richer information.
* cont.c (fiber_to_s): return with block and status information.
* proc.c (proc_to_s_): removed and introduce rb_block_to_s() function
to return block information string.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59558 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'proc.c')
-rw-r--r-- | proc.c | 43 |
1 files changed, 20 insertions, 23 deletions
@@ -48,8 +48,6 @@ static int method_min_max_arity(VALUE, int *max); #define IS_METHOD_PROC_IFUNC(ifunc) ((ifunc)->func == bmcall) -static VALUE proc_to_s_(VALUE self, const rb_proc_t *proc); - static void block_mark(const struct rb_block *block) { @@ -1245,27 +1243,10 @@ proc_hash(VALUE self) return ST2FIX(hash); } -/* - * call-seq: - * prc.to_s -> string - * - * Returns the unique identifier for this proc, along with - * an indication of where the proc was defined. - */ - -static VALUE -proc_to_s(VALUE self) -{ - const rb_proc_t *proc; - GetProcPtr(self, proc); - return proc_to_s_(self, proc); -} - -static VALUE -proc_to_s_(VALUE self, const rb_proc_t *proc) +VALUE +rb_block_to_s(VALUE self, const struct rb_block *block, const char *additional_info) { VALUE cname = rb_obj_class(self); - const struct rb_block *block = &proc->block; VALUE str = rb_sprintf("#<%"PRIsVALUE":", cname); again: @@ -1285,17 +1266,33 @@ proc_to_s_(VALUE self, const rb_proc_t *proc) rb_str_catf(str, "%p(&%+"PRIsVALUE")", (void *)self, block->as.symbol); break; case block_type_ifunc: - rb_str_catf(str, "%p", proc->block.as.captured.code.ifunc); + rb_str_catf(str, "%p", block->as.captured.code.ifunc); break; } - if (proc->is_lambda) rb_str_cat_cstr(str, " (lambda)"); + if (additional_info) rb_str_cat_cstr(str, additional_info); rb_str_cat_cstr(str, ">"); OBJ_INFECT_RAW(str, self); return str; } /* + * call-seq: + * prc.to_s -> string + * + * Returns the unique identifier for this proc, along with + * an indication of where the proc was defined. + */ + +static VALUE +proc_to_s(VALUE self) +{ + const rb_proc_t *proc; + GetProcPtr(self, proc); + return rb_block_to_s(self, &proc->block, proc->is_lambda ? " (lambda)" : NULL); +} + +/* * call-seq: * prc.to_proc -> proc * |