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
@ -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)
|
#define is_broken_string(str) (rb_enc_str_coderange(str) == ENC_CODERANGE_BROKEN)
|
||||||
size_t rb_str_memsize(VALUE);
|
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_proc_call(VALUE args, VALUE sym, int argc, const VALUE *argv, VALUE passed_proc);
|
||||||
|
VALUE rb_sym_to_proc(VALUE sym);
|
||||||
|
|
||||||
/* struct.c */
|
/* struct.c */
|
||||||
VALUE rb_struct_init_copy(VALUE copy, VALUE s);
|
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);
|
return rb_funcall_with_block(obj, (ID)sym, argc - 1, argv + 1, passed_proc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define sym_to_proc rb_sym_to_proc
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* sym.to_proc
|
* 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"]
|
* (1..3).collect(&:to_s) #=> ["1", "2", "3"]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static VALUE
|
VALUE
|
||||||
sym_to_proc(VALUE sym)
|
sym_to_proc(VALUE sym)
|
||||||
{
|
{
|
||||||
static VALUE sym_proc_cache = Qfalse;
|
static VALUE sym_proc_cache = Qfalse;
|
||||||
|
@ -140,6 +140,13 @@ class TestSymbol < Test::Unit::TestCase
|
|||||||
end;
|
end;
|
||||||
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
|
def test_call
|
||||||
o = Object.new
|
o = Object.new
|
||||||
def o.foo(x, y); x + y; end
|
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);
|
GetProcPtr(blockval, proc);
|
||||||
calling->blockptr = &proc->block;
|
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 {
|
else {
|
||||||
blockval = blockptr->proc;
|
blockval = blockptr->proc;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user