mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
vm_args.c: wrap symbol ifunc
* vm_args.c (args_setup_block_parameter): wrap a symbol in ifunc by a proc as a block parameter. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52056 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
334710c155
commit
ceddb49868
4 changed files with 14 additions and 1 deletions
|
@ -1110,6 +1110,7 @@ VALUE rb_external_str_with_enc(VALUE str, rb_encoding *eenc);
|
|||
#define is_broken_string(str) (rb_enc_str_coderange(str) == ENC_CODERANGE_BROKEN)
|
||||
size_t rb_str_memsize(VALUE);
|
||||
VALUE rb_sym_proc_call(VALUE args, VALUE sym, int argc, const VALUE *argv, VALUE passed_proc);
|
||||
VALUE rb_sym_to_proc(VALUE sym);
|
||||
|
||||
/* struct.c */
|
||||
VALUE rb_struct_init_copy(VALUE copy, VALUE s);
|
||||
|
|
3
string.c
3
string.c
|
@ -8946,6 +8946,7 @@ rb_sym_proc_call(VALUE args, VALUE sym, int argc, const VALUE *argv, VALUE passe
|
|||
return rb_funcall_with_block(obj, (ID)sym, argc - 1, argv + 1, passed_proc);
|
||||
}
|
||||
|
||||
#define sym_to_proc rb_sym_to_proc
|
||||
/*
|
||||
* call-seq:
|
||||
* sym.to_proc
|
||||
|
@ -8955,7 +8956,7 @@ rb_sym_proc_call(VALUE args, VALUE sym, int argc, const VALUE *argv, VALUE passe
|
|||
* (1..3).collect(&:to_s) #=> ["1", "2", "3"]
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
VALUE
|
||||
sym_to_proc(VALUE sym)
|
||||
{
|
||||
static VALUE sym_proc_cache = Qfalse;
|
||||
|
|
|
@ -140,6 +140,13 @@ class TestSymbol < Test::Unit::TestCase
|
|||
end;
|
||||
end
|
||||
|
||||
def test_to_proc_arg
|
||||
assert_separately([], <<-"end;", timeout: 5.0)
|
||||
def (obj = Object.new).proc(&b) b; end
|
||||
assert_same(:itself.to_proc, obj.proc(&:itself))
|
||||
end;
|
||||
end
|
||||
|
||||
def test_call
|
||||
o = Object.new
|
||||
def o.foo(x, y); x + y; end
|
||||
|
|
|
@ -478,6 +478,10 @@ args_setup_block_parameter(rb_thread_t *th, struct rb_calling_info *calling, VAL
|
|||
GetProcPtr(blockval, proc);
|
||||
calling->blockptr = &proc->block;
|
||||
}
|
||||
else if (RUBY_VM_IFUNC_P(blockptr->proc)) {
|
||||
const ID mid = (ID)((struct vm_ifunc *)blockptr->proc)->data;
|
||||
blockval = rb_sym_to_proc(ID2SYM(mid));
|
||||
}
|
||||
else {
|
||||
blockval = blockptr->proc;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue