Skip to content

Commit

Permalink
Fix more keyword separation issues
Browse files Browse the repository at this point in the history
This fixes instance_exec and similar methods. It also fixes
Enumerator::Yielder#yield, rb_yield_block, and a couple of cases
with Proc#{<<,>>}.

This support requires the addition of rb_yield_values_kw, similar to
rb_yield_values2, for passing the keyword flag.

Unlike earlier attempts at this, this does not modify the rb_block_call_func
type or add a separate function type.  The functions of type
rb_block_call_func are called by Ruby with a separate VM frame, and we can
get the keyword flag information from the VM frame flags, so it doesn't need
to be passed as a function argument.

These changes require the following VM functions accept a keyword flag:

* vm_yield_with_cref
* vm_yield
* vm_yield_with_block
  • Loading branch information
jeremyevans committed Sep 27, 2019
1 parent 0c6f366 commit 660c7e0
Show file tree
Hide file tree
Showing 9 changed files with 707 additions and 32 deletions.
4 changes: 2 additions & 2 deletions enumerator.c
Expand Up @@ -1320,7 +1320,7 @@ yielder_yield(VALUE obj, VALUE args)
{
struct yielder *ptr = yielder_ptr(obj);

return rb_proc_call(ptr->proc, args);
return rb_proc_call_kw(ptr->proc, args, RB_PASS_CALLED_KEYWORDS);
}

/* :nodoc: */
Expand Down Expand Up @@ -1357,7 +1357,7 @@ yielder_to_proc(VALUE obj)
static VALUE
yielder_yield_i(RB_BLOCK_CALL_FUNC_ARGLIST(obj, memo))
{
return rb_yield_values2(argc, argv);
return rb_yield_values_kw(argc, argv, RB_PASS_CALLED_KEYWORDS);
}

static VALUE
Expand Down
2 changes: 1 addition & 1 deletion ext/-test-/iter/yield.c
Expand Up @@ -4,7 +4,7 @@ static VALUE
yield_block(int argc, VALUE *argv, VALUE self)
{
rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
return rb_block_call(self, rb_to_id(argv[0]), argc-1, argv+1, rb_yield_block, 0);
return rb_block_call_kw(self, rb_to_id(argv[0]), argc-1, argv+1, rb_yield_block, 0, RB_PASS_CALLED_KEYWORDS);
}

void
Expand Down
2 changes: 1 addition & 1 deletion hash.c
Expand Up @@ -4471,7 +4471,7 @@ rb_hash_gt(VALUE hash, VALUE other)
}

static VALUE
hash_proc_call(VALUE key, VALUE hash, int argc, const VALUE *argv, VALUE passed_proc)
hash_proc_call(RB_BLOCK_CALL_FUNC_ARGLIST(key, hash))
{
rb_check_arity(argc, 1, 1);
return rb_hash_aref(hash, *argv);
Expand Down
3 changes: 2 additions & 1 deletion include/ruby/ruby.h
Expand Up @@ -1970,8 +1970,9 @@ VALUE rb_each(VALUE);
VALUE rb_yield(VALUE);
VALUE rb_yield_values(int n, ...);
VALUE rb_yield_values2(int n, const VALUE *argv);
VALUE rb_yield_values_kw(int n, const VALUE *argv, int kw_splat);
VALUE rb_yield_splat(VALUE);
VALUE rb_yield_block(VALUE, VALUE, int, const VALUE *, VALUE); /* rb_block_call_func */
VALUE rb_yield_block(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)); /* rb_block_call_func */
#define RB_NO_KEYWORDS 0
#define RB_PASS_KEYWORDS 1
#define RB_PASS_EMPTY_KEYWORDS 2
Expand Down
2 changes: 1 addition & 1 deletion proc.c
Expand Up @@ -2895,7 +2895,7 @@ mlambda(VALUE method)
static VALUE
bmcall(RB_BLOCK_CALL_FUNC_ARGLIST(args, method))
{
return rb_method_call_with_block(argc, argv, method, blockarg);
return rb_method_call_with_block_kw(argc, argv, method, blockarg, RB_PASS_CALLED_KEYWORDS);
}

VALUE
Expand Down

0 comments on commit 660c7e0

Please sign in to comment.