summaryrefslogtreecommitdiff
path: root/vm_eval.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-09-05 19:25:34 -0700
committerJeremy Evans <code@jeremyevans.net>2019-09-06 19:41:23 -0700
commit37a2c660aa4f4aacfd6a56651b10124e3ac01321 (patch)
treee31ede184f37489e1cda4ae2400e6424a03ffb39 /vm_eval.c
parent3fafc549ba909e986917f2b6b96eb14624c26329 (diff)
Convert keyword argument to required positional hash argument for Class#new, Method#call, UnboundMethod#bind_call
Also add keyword argument separation warnings for Class#new and Method#call. To allow for keyword argument to required positional hash converstion in cfuncs, add a vm frame flag indicating the cfunc was called with an empty keyword hash (which was removed before calling the cfunc). The cfunc can check this frame flag and add back an empty hash if it is passing its arguments to another Ruby method. Add rb_empty_keyword_given_p function for checking if called with an empty keyword hash, and rb_add_empty_keyword for adding back an empty hash to argv. All of this empty keyword argument support is only for 2.7. It will be removed in 3.0 as Ruby 3 will not convert empty keyword arguments to required positional hash arguments. Comment all of the relevent code to make it obvious this is expected to be removed. Add rb_funcallv_kw as an public C-API function, just like rb_funcallv but with a keyword flag. This is used by rb_obj_call_init (internals of Class#new). This also required expected call_type enum with CALL_FCALL_KW, similar to the recent addition of CALL_PUBLIC_KW. Add rb_vm_call_kw as a internal function, used by call_method_data (internals of Method#call and UnboundMethod#bind_call). Add tests for UnboundMethod#bind_call keyword handling.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2432
Diffstat (limited to 'vm_eval.c')
-rw-r--r--vm_eval.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/vm_eval.c b/vm_eval.c
index b0249391bf..4a3b9e325f 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -33,6 +33,7 @@ typedef enum call_type {
CALL_FCALL,
CALL_VCALL,
CALL_PUBLIC_KW,
+ CALL_FCALL_KW,
CALL_TYPE_MAX
} call_type;
@@ -210,6 +211,12 @@ rb_vm_call(rb_execution_context_t *ec, VALUE recv, VALUE id, int argc, const VAL
return rb_vm_call0(ec, recv, id, argc, argv, me, VM_NO_KEYWORDS);
}
+VALUE
+rb_vm_call_kw(rb_execution_context_t *ec, VALUE recv, VALUE id, int argc, const VALUE *argv, const rb_callable_method_entry_t *me, int kw_splat)
+{
+ return rb_vm_call0(ec, recv, id, argc, argv, me, kw_splat);
+}
+
static inline VALUE
vm_call_super(rb_execution_context_t *ec, int argc, const VALUE *argv)
{
@@ -298,9 +305,17 @@ rb_call0(rb_execution_context_t *ec,
call_type scope = call_scope;
int kw_splat = VM_NO_KEYWORDS;
- if (scope == CALL_PUBLIC_KW) {
+ switch(scope) {
+ case(CALL_PUBLIC_KW):
scope = CALL_PUBLIC;
kw_splat = 1;
+ break;
+ case(CALL_FCALL_KW):
+ scope = CALL_FCALL;
+ kw_splat = 1;
+ break;
+ default:
+ break;
}
if (scope == CALL_PUBLIC) {
@@ -861,6 +876,12 @@ rb_funcallv(VALUE recv, ID mid, int argc, const VALUE *argv)
return rb_call(recv, mid, argc, argv, CALL_FCALL);
}
+VALUE
+rb_funcallv_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
+{
+ return rb_call(recv, mid, argc, argv, kw_splat ? CALL_FCALL_KW : CALL_FCALL);
+}
+
/*!
* Calls a method.
*