From 649a64ae29318501472f74798a12eb60871ab990 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Sun, 29 Sep 2019 17:47:17 -0700 Subject: Add three more C-API functions for handling keywords This adds rb_funcall_passing_block_kw, rb_funcallv_public_kw, and rb_yield_splat_kw. This functions are necessary to easily handle cases where rb_funcall_passing_block, rb_funcallv_public, and rb_yield_splat are currently used and a keyword argument separation warning is raised. --- ext/-test-/funcall/funcall.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'ext/-test-/funcall') diff --git a/ext/-test-/funcall/funcall.c b/ext/-test-/funcall/funcall.c index 4e13c952e5..43521bf2e9 100644 --- a/ext/-test-/funcall/funcall.c +++ b/ext/-test-/funcall/funcall.c @@ -1,7 +1,5 @@ #include "ruby.h" -VALUE rb_funcall_passing_block(VALUE, ID, int, const VALUE*); - static VALUE with_funcall2(int argc, VALUE *argv, VALUE self) { @@ -14,6 +12,24 @@ with_funcall_passing_block(int argc, VALUE *argv, VALUE self) return rb_funcall_passing_block(self, rb_intern("target"), argc, argv); } +static VALUE +with_funcall_passing_block_kw(int argc, VALUE *argv, VALUE self) +{ + return rb_funcall_passing_block_kw(self, rb_intern("target"), argc-1, argv+1, FIX2INT(argv[0])); +} + +static VALUE +with_funcallv_public_kw(int argc, VALUE *argv, VALUE self) +{ + return rb_funcallv_public_kw(argv[0], SYM2ID(argv[1]), argc-3, argv+3, FIX2INT(argv[2])); +} + +static VALUE +with_yield_splat_kw(int argc, VALUE *argv, VALUE self) +{ + return rb_yield_splat_kw(argv[1], FIX2INT(argv[0])); +} + static VALUE extra_args_name(VALUE self) { @@ -34,10 +50,22 @@ Init_funcall(void) "with_funcall2", with_funcall2, -1); + rb_define_singleton_method(cRelay, + "with_funcall_passing_block_kw", + with_funcall_passing_block_kw, + -1); rb_define_singleton_method(cRelay, "with_funcall_passing_block", with_funcall_passing_block, -1); + rb_define_singleton_method(cRelay, + "with_funcallv_public_kw", + with_funcallv_public_kw, + -1); + rb_define_singleton_method(cRelay, + "with_yield_splat_kw", + with_yield_splat_kw, + -1); rb_define_singleton_method(cTestFuncall, "extra_args_name", extra_args_name, 0); -- cgit v1.2.3