diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-10-04 12:51:57 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2020-01-02 18:40:45 -0800 |
commit | beae6cbf0fd8b6619e5212552de98022d4c4d4d4 (patch) | |
tree | a926f619ed39569df4e93ec31157acdb78796379 /cont.c | |
parent | 8ba261c7546e3cd12ff6870bb41dd0a0bee32ba8 (diff) | |
download | ruby-beae6cbf0fd8b6619e5212552de98022d4c4d4d4.tar.gz |
Fully separate positional arguments and keyword arguments
This removes the warnings added in 2.7, and changes the behavior
so that a final positional hash is not treated as keywords or
vice-versa.
To handle the arg_setup_block splat case correctly with keyword
arguments, we need to check if we are taking a keyword hash.
That case didn't have a test, but it affects real-world code,
so add a test for it.
This removes rb_empty_keyword_given_p() and related code, as
that is not needed in Ruby 3. The empty keyword case is the
same as the no keyword case in Ruby 3.
This changes rb_scan_args to implement keyword argument
separation for C functions when the : character is used.
For backwards compatibility, it returns a duped hash.
This is a bad idea for performance, but not duping the hash
breaks at least Enumerator::ArithmeticSequence#inspect.
Instead of having RB_PASS_CALLED_KEYWORDS be a number,
simplify the code by just making it be rb_keyword_given_p().
Diffstat (limited to 'cont.c')
-rw-r--r-- | cont.c | 12 |
1 files changed, 4 insertions, 8 deletions
@@ -1790,8 +1790,6 @@ rb_fiber_new(rb_block_call_func_t func, VALUE obj) static void rb_fiber_terminate(rb_fiber_t *fiber, int need_interrupt); -#define PASS_KW_SPLAT (rb_empty_keyword_given_p() ? RB_PASS_EMPTY_KEYWORDS : rb_keyword_given_p()) - void rb_fiber_start(void) { @@ -1809,7 +1807,6 @@ rb_fiber_start(void) rb_context_t *cont = &VAR_FROM_MEMORY(fiber)->cont; int argc; const VALUE *argv, args = cont->value; - int kw_splat = cont->kw_splat; GetProcPtr(fiber->first_proc, proc); argv = (argc = cont->argc) > 1 ? RARRAY_CONST_PTR(args) : &args; cont->value = Qnil; @@ -1818,8 +1815,7 @@ rb_fiber_start(void) th->ec->root_svar = Qfalse; EXEC_EVENT_HOOK(th->ec, RUBY_EVENT_FIBER_SWITCH, th->self, 0, 0, 0, Qnil); - rb_adjust_argv_kw_splat(&argc, &argv, &kw_splat); - cont->value = rb_vm_invoke_proc(th->ec, proc, argc, argv, kw_splat, VM_BLOCK_HANDLER_NONE); + cont->value = rb_vm_invoke_proc(th->ec, proc, argc, argv, cont->kw_splat, VM_BLOCK_HANDLER_NONE); } EC_POP_TAG(); @@ -2163,7 +2159,7 @@ rb_fiber_alive_p(VALUE fiber_value) static VALUE rb_fiber_m_resume(int argc, VALUE *argv, VALUE fiber) { - return rb_fiber_resume_kw(fiber, argc, argv, PASS_KW_SPLAT); + return rb_fiber_resume_kw(fiber, argc, argv, rb_keyword_given_p()); } /* @@ -2249,7 +2245,7 @@ rb_fiber_m_transfer(int argc, VALUE *argv, VALUE fiber_value) { rb_fiber_t *fiber = fiber_ptr(fiber_value); fiber->transferred = 1; - return fiber_switch(fiber, argc, argv, 0, PASS_KW_SPLAT); + return fiber_switch(fiber, argc, argv, 0, rb_keyword_given_p()); } /* @@ -2265,7 +2261,7 @@ rb_fiber_m_transfer(int argc, VALUE *argv, VALUE fiber_value) static VALUE rb_fiber_s_yield(int argc, VALUE *argv, VALUE klass) { - return rb_fiber_yield_kw(argc, argv, PASS_KW_SPLAT); + return rb_fiber_yield_kw(argc, argv, rb_keyword_given_p()); } /* |