summaryrefslogtreecommitdiff
path: root/proc.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-08 07:34:13 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-08 07:34:13 +0000
commit4e61f6d31d6adc76ce1694d921fa6201ae4e0046 (patch)
treed4bab49ede914632f5f1796b119994b8ef18cf88 /proc.c
parentb515528271a25e52cdbc28289436c94108141b4a (diff)
downloadruby-4e61f6d31d6adc76ce1694d921fa6201ae4e0046.tar.gz
proc.c: preserve class name encoding in Proc#to_s
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57808 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'proc.c')
-rw-r--r--proc.c28
1 files changed, 11 insertions, 17 deletions
diff --git a/proc.c b/proc.c
index 27724118be..dd571f7ba8 100644
--- a/proc.c
+++ b/proc.c
@@ -1212,13 +1212,9 @@ proc_to_s(VALUE self)
static VALUE
proc_to_s_(VALUE self, const rb_proc_t *proc)
{
- VALUE str = 0;
- const char *cname = rb_obj_classname(self);
- const struct rb_block *block;
- const char *is_lambda;
-
- block = &proc->block;
- is_lambda = proc->is_lambda ? " (lambda)" : "";
+ VALUE cname = rb_obj_class(self);
+ const struct rb_block *block = &proc->block;
+ VALUE str = rb_sprintf("#<%"PRIsVALUE":", cname);
again:
switch (vm_block_type(block)) {
@@ -1228,24 +1224,22 @@ proc_to_s_(VALUE self, const rb_proc_t *proc)
case block_type_iseq:
{
const rb_iseq_t *iseq = rb_iseq_check(block->as.captured.code.iseq);
- str = rb_sprintf("#<%s:%p@%"PRIsVALUE":%d%s>", cname, (void *)self,
- iseq->body->location.path,
- FIX2INT(iseq->body->location.first_lineno), is_lambda);
+ rb_str_catf(str, "%p@%"PRIsVALUE":%d", (void *)self,
+ iseq->body->location.path,
+ FIX2INT(iseq->body->location.first_lineno));
}
break;
case block_type_symbol:
- str = rb_sprintf("#<%s:%p(&%+"PRIsVALUE")%s>", cname, (void *)self,
- block->as.symbol, is_lambda);
+ rb_str_catf(str, "%p(&%+"PRIsVALUE")", (void *)self, block->as.symbol);
break;
case block_type_ifunc:
- str = rb_sprintf("#<%s:%p%s>", cname, proc->block.as.captured.code.ifunc,
- is_lambda);
+ rb_str_catf(str, "%p", proc->block.as.captured.code.ifunc);
break;
}
- if (OBJ_TAINTED(self)) {
- OBJ_TAINT(str);
- }
+ if (proc->is_lambda) rb_str_cat_cstr(str, " (lambda)");
+ rb_str_cat_cstr(str, ">");
+ OBJ_INFECT_RAW(str, self);
return str;
}