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
This commit is contained in:
parent
b515528271
commit
4e61f6d31d
28
proc.c
28
proc.c
@ -1212,13 +1212,9 @@ proc_to_s(VALUE self)
|
|||||||
static VALUE
|
static VALUE
|
||||||
proc_to_s_(VALUE self, const rb_proc_t *proc)
|
proc_to_s_(VALUE self, const rb_proc_t *proc)
|
||||||
{
|
{
|
||||||
VALUE str = 0;
|
VALUE cname = rb_obj_class(self);
|
||||||
const char *cname = rb_obj_classname(self);
|
const struct rb_block *block = &proc->block;
|
||||||
const struct rb_block *block;
|
VALUE str = rb_sprintf("#<%"PRIsVALUE":", cname);
|
||||||
const char *is_lambda;
|
|
||||||
|
|
||||||
block = &proc->block;
|
|
||||||
is_lambda = proc->is_lambda ? " (lambda)" : "";
|
|
||||||
|
|
||||||
again:
|
again:
|
||||||
switch (vm_block_type(block)) {
|
switch (vm_block_type(block)) {
|
||||||
@ -1228,24 +1224,22 @@ proc_to_s_(VALUE self, const rb_proc_t *proc)
|
|||||||
case block_type_iseq:
|
case block_type_iseq:
|
||||||
{
|
{
|
||||||
const rb_iseq_t *iseq = rb_iseq_check(block->as.captured.code.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,
|
rb_str_catf(str, "%p@%"PRIsVALUE":%d", (void *)self,
|
||||||
iseq->body->location.path,
|
iseq->body->location.path,
|
||||||
FIX2INT(iseq->body->location.first_lineno), is_lambda);
|
FIX2INT(iseq->body->location.first_lineno));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case block_type_symbol:
|
case block_type_symbol:
|
||||||
str = rb_sprintf("#<%s:%p(&%+"PRIsVALUE")%s>", cname, (void *)self,
|
rb_str_catf(str, "%p(&%+"PRIsVALUE")", (void *)self, block->as.symbol);
|
||||||
block->as.symbol, is_lambda);
|
|
||||||
break;
|
break;
|
||||||
case block_type_ifunc:
|
case block_type_ifunc:
|
||||||
str = rb_sprintf("#<%s:%p%s>", cname, proc->block.as.captured.code.ifunc,
|
rb_str_catf(str, "%p", proc->block.as.captured.code.ifunc);
|
||||||
is_lambda);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OBJ_TAINTED(self)) {
|
if (proc->is_lambda) rb_str_cat_cstr(str, " (lambda)");
|
||||||
OBJ_TAINT(str);
|
rb_str_cat_cstr(str, ">");
|
||||||
}
|
OBJ_INFECT_RAW(str, self);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1174,6 +1174,8 @@ class TestProc < Test::Unit::TestCase
|
|||||||
x = proc {}
|
x = proc {}
|
||||||
x.taint
|
x.taint
|
||||||
assert_predicate(x.to_s, :tainted?)
|
assert_predicate(x.to_s, :tainted?)
|
||||||
|
name = "Proc\u{1f37b}"
|
||||||
|
assert_include(EnvUtil.labeled_class(name, Proc).new {}.to_s, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@line_of_source_location_test = __LINE__ + 1
|
@@line_of_source_location_test = __LINE__ + 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user