aboutsummaryrefslogtreecommitdiffstats
path: root/proc.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-10 02:58:36 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-10 02:58:36 +0000
commitd5b6cdd64784e6ed9b112317e4e0d8d2d8376e01 (patch)
treee696a34c00d2d333a01e85e91e964e2f8a40e707 /proc.c
parenta3e5e22f9e2155abb30261bffe7c0a7e6105a3e3 (diff)
downloadruby-d5b6cdd64784e6ed9b112317e4e0d8d2d8376e01.tar.gz
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.c43
1 files changed, 20 insertions, 23 deletions
diff --git a/proc.c b/proc.c
index eaec02c20e..b43e11f04a 100644
--- a/proc.c
+++ b/proc.c
@@ -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
*