зеркало из https://github.com/github/ruby.git
vm.c: fix return in lambda
* vm.c (invoke_block_from_c_splattable): pass lambda-ness. * vm_eval.c (yield_under): invoke lambda proc properly. [ruby-core:78917] [Bug #13090] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57240 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
31729338a0
Коммит
91587f6b63
|
@ -79,6 +79,26 @@ class TestLambdaParameters < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_instance_eval_return
|
||||||
|
bug13090 = '[ruby-core:78917] [Bug #13090] cannot return in lambdas'
|
||||||
|
x = :ng
|
||||||
|
assert_nothing_raised(LocalJumpError) do
|
||||||
|
x = instance_eval(&->(_){return :ok})
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
assert_equal(:ok, x, bug13090)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_instance_exec_return
|
||||||
|
bug13090 = '[ruby-core:78917] [Bug #13090] cannot return in lambdas'
|
||||||
|
x = :ng
|
||||||
|
assert_nothing_raised(LocalJumpError) do
|
||||||
|
x = instance_exec(&->(){return :ok})
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
assert_equal(:ok, x, bug13090)
|
||||||
|
end
|
||||||
|
|
||||||
def yield_1(arg)
|
def yield_1(arg)
|
||||||
yield arg
|
yield arg
|
||||||
end
|
end
|
||||||
|
|
12
vm.c
12
vm.c
|
@ -1021,9 +1021,9 @@ invoke_iseq_block_from_c(rb_thread_t *th, const struct rb_captured_block *captur
|
||||||
static inline VALUE
|
static inline VALUE
|
||||||
invoke_block_from_c_splattable(rb_thread_t *th, VALUE block_handler,
|
invoke_block_from_c_splattable(rb_thread_t *th, VALUE block_handler,
|
||||||
int argc, const VALUE *argv,
|
int argc, const VALUE *argv,
|
||||||
VALUE passed_block_handler, const rb_cref_t *cref)
|
VALUE passed_block_handler, const rb_cref_t *cref,
|
||||||
|
int is_lambda)
|
||||||
{
|
{
|
||||||
int is_lambda = FALSE;
|
|
||||||
again:
|
again:
|
||||||
switch (vm_block_handler_type(block_handler)) {
|
switch (vm_block_handler_type(block_handler)) {
|
||||||
case block_handler_type_iseq:
|
case block_handler_type_iseq:
|
||||||
|
@ -1058,21 +1058,21 @@ check_block_handler(rb_thread_t *th)
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
vm_yield_with_cref(rb_thread_t *th, int argc, const VALUE *argv, const rb_cref_t *cref)
|
vm_yield_with_cref(rb_thread_t *th, int argc, const VALUE *argv, const rb_cref_t *cref, int is_lambda)
|
||||||
{
|
{
|
||||||
return invoke_block_from_c_splattable(th, check_block_handler(th), argc, argv, VM_BLOCK_HANDLER_NONE, cref);
|
return invoke_block_from_c_splattable(th, check_block_handler(th), argc, argv, VM_BLOCK_HANDLER_NONE, cref, is_lambda);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
vm_yield(rb_thread_t *th, int argc, const VALUE *argv)
|
vm_yield(rb_thread_t *th, int argc, const VALUE *argv)
|
||||||
{
|
{
|
||||||
return invoke_block_from_c_splattable(th, check_block_handler(th), argc, argv, VM_BLOCK_HANDLER_NONE, NULL);
|
return invoke_block_from_c_splattable(th, check_block_handler(th), argc, argv, VM_BLOCK_HANDLER_NONE, NULL, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
vm_yield_with_block(rb_thread_t *th, int argc, const VALUE *argv, VALUE block_handler)
|
vm_yield_with_block(rb_thread_t *th, int argc, const VALUE *argv, VALUE block_handler)
|
||||||
{
|
{
|
||||||
return invoke_block_from_c_splattable(th, check_block_handler(th), argc, argv, block_handler, NULL);
|
return invoke_block_from_c_splattable(th, check_block_handler(th), argc, argv, block_handler, NULL, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline VALUE
|
static inline VALUE
|
||||||
|
|
|
@ -16,7 +16,7 @@ struct local_var_list {
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline VALUE method_missing(VALUE obj, ID id, int argc, const VALUE *argv, enum method_missing_reason call_status);
|
static inline VALUE method_missing(VALUE obj, ID id, int argc, const VALUE *argv, enum method_missing_reason call_status);
|
||||||
static inline VALUE vm_yield_with_cref(rb_thread_t *th, int argc, const VALUE *argv, const rb_cref_t *cref);
|
static inline VALUE vm_yield_with_cref(rb_thread_t *th, int argc, const VALUE *argv, const rb_cref_t *cref, int is_lambda);
|
||||||
static inline VALUE vm_yield(rb_thread_t *th, int argc, const VALUE *argv);
|
static inline VALUE vm_yield(rb_thread_t *th, int argc, const VALUE *argv);
|
||||||
static inline VALUE vm_yield_with_block(rb_thread_t *th, int argc, const VALUE *argv, VALUE block_handler);
|
static inline VALUE vm_yield_with_block(rb_thread_t *th, int argc, const VALUE *argv, VALUE block_handler);
|
||||||
static VALUE vm_exec(rb_thread_t *th);
|
static VALUE vm_exec(rb_thread_t *th);
|
||||||
|
@ -1573,6 +1573,7 @@ yield_under(VALUE under, VALUE self, int argc, const VALUE *argv)
|
||||||
struct rb_captured_block new_captured;
|
struct rb_captured_block new_captured;
|
||||||
const VALUE *ep = NULL;
|
const VALUE *ep = NULL;
|
||||||
rb_cref_t *cref;
|
rb_cref_t *cref;
|
||||||
|
int is_lambda = FALSE;
|
||||||
|
|
||||||
if (block_handler != VM_BLOCK_HANDLER_NONE) {
|
if (block_handler != VM_BLOCK_HANDLER_NONE) {
|
||||||
again:
|
again:
|
||||||
|
@ -1588,6 +1589,7 @@ yield_under(VALUE under, VALUE self, int argc, const VALUE *argv)
|
||||||
new_block_handler = VM_BH_FROM_IFUNC_BLOCK(&new_captured);
|
new_block_handler = VM_BH_FROM_IFUNC_BLOCK(&new_captured);
|
||||||
break;
|
break;
|
||||||
case block_handler_type_proc:
|
case block_handler_type_proc:
|
||||||
|
is_lambda = rb_proc_lambda_p(block_handler) != Qfalse;
|
||||||
block_handler = vm_proc_to_block_handler(VM_BH_TO_PROC(block_handler));
|
block_handler = vm_proc_to_block_handler(VM_BH_TO_PROC(block_handler));
|
||||||
goto again;
|
goto again;
|
||||||
case block_handler_type_symbol:
|
case block_handler_type_symbol:
|
||||||
|
@ -1602,7 +1604,7 @@ yield_under(VALUE under, VALUE self, int argc, const VALUE *argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
cref = vm_cref_push(th, under, ep, TRUE);
|
cref = vm_cref_push(th, under, ep, TRUE);
|
||||||
return vm_yield_with_cref(th, argc, argv, cref);
|
return vm_yield_with_cref(th, argc, argv, cref, is_lambda);
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
|
@ -1623,7 +1625,7 @@ rb_yield_refine_block(VALUE refinement, VALUE refinements)
|
||||||
CREF_REFINEMENTS_SET(cref, refinements);
|
CREF_REFINEMENTS_SET(cref, refinements);
|
||||||
VM_FORCE_WRITE_SPECIAL_CONST(&VM_CF_LEP(th->cfp)[VM_ENV_DATA_INDEX_SPECVAL], new_block_handler);
|
VM_FORCE_WRITE_SPECIAL_CONST(&VM_CF_LEP(th->cfp)[VM_ENV_DATA_INDEX_SPECVAL], new_block_handler);
|
||||||
new_captured.self = refinement;
|
new_captured.self = refinement;
|
||||||
return vm_yield_with_cref(th, 0, NULL, cref);
|
return vm_yield_with_cref(th, 0, NULL, cref, FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче