aboutsummaryrefslogtreecommitdiffstats
path: root/vm_args.c
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2019-07-13 12:04:01 -0400
committerAlan Wu <XrXr@users.noreply.github.com>2019-12-21 09:08:52 -0500
commit85a337f986fe6da99c7f8358f790f17b122b3903 (patch)
treef5c41137c2db802327cd4c405de7a922cbae7453 /vm_args.c
parentddb6023d64a8c96348b4e67603753e2916a04f28 (diff)
downloadruby-85a337f986fe6da99c7f8358f790f17b122b3903.tar.gz
Kernel#lambda: return forwarded block as non-lambda proc
Before this commit, Kernel#lambda can't tell the difference between a directly passed literal block and one passed with an ampersand. A block passed with an ampersand is semantically speaking already a non-lambda proc. When Kernel#lambda receives a non-lambda proc, it should simply return it. Implementation wise, when the VM calls a method with a literal block, it places the code for the block on the calling control frame and passes a pointer (block handler) to the callee. Before this commit, the VM forwards block arguments by simply forwarding the block handler, which leaves the slot for block code unused when a control frame forwards its block argument. I use the vacant space to indicate that a frame has forwarded its block argument and inspect that in Kernel#lambda to detect forwarded blocks. This is a very ad-hoc solution and relies *heavily* on the way block passing works in the VM. However, it's the most self-contained solution I have. [Bug #15620]
Diffstat (limited to 'vm_args.c')
-rw-r--r--vm_args.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/vm_args.c b/vm_args.c
index 47ab8ee66a..444abf9086 100644
--- a/vm_args.c
+++ b/vm_args.c
@@ -1204,7 +1204,10 @@ vm_caller_setup_arg_block(const rb_execution_context_t *ec, rb_control_frame_t *
return VM_BLOCK_HANDLER_NONE;
}
else if (block_code == rb_block_param_proxy) {
- return VM_CF_BLOCK_HANDLER(reg_cfp);
+ VM_ASSERT(!VM_CFP_IN_HEAP_P(GET_EC(), reg_cfp));
+ VALUE handler = VM_CF_BLOCK_HANDLER(reg_cfp);
+ reg_cfp->block_code = (const void *) handler;
+ return handler;
}
else if (SYMBOL_P(block_code) && rb_method_basic_definition_p(rb_cSymbol, idTo_proc)) {
const rb_cref_t *cref = vm_env_cref(reg_cfp->ep);