From 3073404e741df19ae16248126640777ed36110e8 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Sun, 29 Sep 2019 21:33:59 -0700 Subject: Add rb_enumeratorize_with_size_kw and related macros Currently, there is not a way to create a sized enumerator in C with a different set of arguments than provided by Ruby, and correctly handle keyword arguments. This function allows that. The need for this is fairly uncommon, but it occurs at least in Enumerator.produce, which takes arugments from Ruby but calls rb_enumeratorize_with_size with a different set of arguments. --- ext/-test-/enumerator_kw/depend | 14 ++++++++++++++ ext/-test-/enumerator_kw/enumerator_kw.c | 21 +++++++++++++++++++++ ext/-test-/enumerator_kw/extconf.rb | 1 + 3 files changed, 36 insertions(+) create mode 100644 ext/-test-/enumerator_kw/depend create mode 100644 ext/-test-/enumerator_kw/enumerator_kw.c create mode 100755 ext/-test-/enumerator_kw/extconf.rb (limited to 'ext/-test-/enumerator_kw') diff --git a/ext/-test-/enumerator_kw/depend b/ext/-test-/enumerator_kw/depend new file mode 100644 index 0000000000..b7489eaf73 --- /dev/null +++ b/ext/-test-/enumerator_kw/depend @@ -0,0 +1,14 @@ +# AUTOGENERATED DEPENDENCIES START +enumerator_kw.o: $(RUBY_EXTCONF_H) +enumerator_kw.o: $(arch_hdrdir)/ruby/config.h +enumerator_kw.o: $(hdrdir)/ruby.h +enumerator_kw.o: $(hdrdir)/ruby/assert.h +enumerator_kw.o: $(hdrdir)/ruby/backward.h +enumerator_kw.o: $(hdrdir)/ruby/defines.h +enumerator_kw.o: $(hdrdir)/ruby/intern.h +enumerator_kw.o: $(hdrdir)/ruby/missing.h +enumerator_kw.o: $(hdrdir)/ruby/ruby.h +enumerator_kw.o: $(hdrdir)/ruby/st.h +enumerator_kw.o: $(hdrdir)/ruby/subst.h +enumerator_kw.o: enumerator_kw.c +# AUTOGENERATED DEPENDENCIES END diff --git a/ext/-test-/enumerator_kw/enumerator_kw.c b/ext/-test-/enumerator_kw/enumerator_kw.c new file mode 100644 index 0000000000..cd6099ffb3 --- /dev/null +++ b/ext/-test-/enumerator_kw/enumerator_kw.c @@ -0,0 +1,21 @@ +#include + +static VALUE +enumerator_kw(int argc, VALUE *argv, VALUE self) +{ + VALUE obj, opt, enum_args[4]; + enum_args[0] = Qnil; + enum_args[1] = Qnil; + rb_scan_args(argc, argv, "01*:", enum_args, enum_args+1, &opt); + enum_args[3] = self; + enum_args[2] = opt; + RETURN_SIZED_ENUMERATOR_KW(self, 4, enum_args, 0, RB_NO_KEYWORDS); + return rb_yield_values_kw(4, enum_args, RB_NO_KEYWORDS); +} + +void +Init_enumerator_kw(void) { + VALUE module = rb_define_module("Bug"); + module = rb_define_module_under(module, "EnumeratorKw"); + rb_define_method(module, "m", enumerator_kw, -1); +} diff --git a/ext/-test-/enumerator_kw/extconf.rb b/ext/-test-/enumerator_kw/extconf.rb new file mode 100755 index 0000000000..ab2be73fa8 --- /dev/null +++ b/ext/-test-/enumerator_kw/extconf.rb @@ -0,0 +1 @@ +create_makefile("-test-/enumerator_kw") -- cgit v1.2.3