ruby-changes:45735
From: nobu <ko1@a...>
Date: Wed, 8 Mar 2017 16:34:18 +0900 (JST)
Subject: [ruby-changes:45735] nobu:r57808 (trunk): proc.c: preserve class name encoding in Proc#to_s
nobu 2017-03-08 16:34:13 +0900 (Wed, 08 Mar 2017) New Revision: 57808 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57808 Log: proc.c: preserve class name encoding in Proc#to_s Modified files: trunk/proc.c trunk/test/ruby/test_proc.rb Index: proc.c =================================================================== --- proc.c (revision 57807) +++ proc.c (revision 57808) @@ -1212,13 +1212,9 @@ proc_to_s(VALUE self) https://github.com/ruby/ruby/blob/trunk/proc.c#L1212 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 * https://github.com/ruby/ruby/blob/trunk/proc.c#L1224 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; } Index: test/ruby/test_proc.rb =================================================================== --- test/ruby/test_proc.rb (revision 57807) +++ test/ruby/test_proc.rb (revision 57808) @@ -1174,6 +1174,8 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_proc.rb#L1174 x = proc {} x.taint assert_predicate(x.to_s, :tainted?) + name = "Proc\u{1f37b}" + assert_include(EnvUtil.labeled_class(name, Proc).new {}.to_s, name) end @@line_of_source_location_test = __LINE__ + 1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/