ruby-changes:66827
From: Nobuyoshi <ko1@a...>
Date: Sun, 18 Jul 2021 12:41:03 +0900 (JST)
Subject: [ruby-changes:66827] e0e12202c7 (master): Use rb_block_call() instead of the deprecated rb_iterate()
https://git.ruby-lang.org/ruby.git/commit/?id=e0e12202c7 From e0e12202c7688881b8fcdad96669ca0cd7be8622 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sun, 18 Jul 2021 11:40:21 +0900 Subject: Use rb_block_call() instead of the deprecated rb_iterate() --- spec/ruby/optional/capi/array_spec.rb | 8 ++++---- spec/ruby/optional/capi/ext/array_spec.c | 22 +++++++++------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/spec/ruby/optional/capi/array_spec.rb b/spec/ruby/optional/capi/array_spec.rb index 8d003fb..8e90980 100644 --- a/spec/ruby/optional/capi/array_spec.rb +++ b/spec/ruby/optional/capi/array_spec.rb @@ -343,10 +343,10 @@ describe "C-API Array function" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/array_spec.rb#L343 end end - describe "rb_iterate" do + describe "rb_block_call" do it "calls an callback function as a block passed to an method" do s = [1,2,3,4] - s2 = @s.rb_iterate(s) + s2 = @s.rb_block_call(s) s2.should == s @@ -357,7 +357,7 @@ describe "C-API Array function" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/array_spec.rb#L357 it "calls a function with the other function available as a block" do h = {a: 1, b: 2} - @s.rb_iterate_each_pair(h).sort.should == [1,2] + @s.rb_block_call_each_pair(h).sort.should == [1,2] end it "calls a function which can yield into the original block" do @@ -371,7 +371,7 @@ describe "C-API Array function" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/array_spec.rb#L371 yield 4 end - @s.rb_iterate_then_yield(o) { |x| s2 << x } + @s.rb_block_call_then_yield(o) { |x| s2 << x } s2.should == [1,2,3,4] end diff --git a/spec/ruby/optional/capi/ext/array_spec.c b/spec/ruby/optional/capi/ext/array_spec.c index 39ed1ed..9386239 100644 --- a/spec/ruby/optional/capi/ext/array_spec.c +++ b/spec/ruby/optional/capi/ext/array_spec.c @@ -196,10 +196,10 @@ static VALUE copy_ary(RB_BLOCK_CALL_FUNC_ARGLIST(el, new_ary)) { https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/ext/array_spec.c#L196 return rb_ary_push(new_ary, el); } -static VALUE array_spec_rb_iterate(VALUE self, VALUE ary) { +static VALUE array_spec_rb_block_call(VALUE self, VALUE ary) { VALUE new_ary = rb_ary_new(); - rb_iterate(rb_each, ary, copy_ary, new_ary); + rb_block_call(ary, rb_intern("each"), 0, 0, copy_ary, new_ary); return new_ary; } @@ -208,14 +208,10 @@ static VALUE sub_pair(RB_BLOCK_CALL_FUNC_ARGLIST(el, holder)) { https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/ext/array_spec.c#L208 return rb_ary_push(holder, rb_ary_entry(el, 1)); } -static VALUE each_pair(VALUE obj) { - return rb_funcall(obj, rb_intern("each_pair"), 0); -} - -static VALUE array_spec_rb_iterate_each_pair(VALUE self, VALUE obj) { +static VALUE array_spec_rb_block_call_each_pair(VALUE self, VALUE obj) { VALUE new_ary = rb_ary_new(); - rb_iterate(each_pair, obj, sub_pair, new_ary); + rb_block_call(obj, rb_intern("each_pair"), 0, 0, sub_pair, new_ary); return new_ary; } @@ -225,8 +221,8 @@ static VALUE iter_yield(RB_BLOCK_CALL_FUNC_ARGLIST(el, ary)) { https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/ext/array_spec.c#L221 return Qnil; } -static VALUE array_spec_rb_iterate_then_yield(VALUE self, VALUE obj) { - rb_iterate(rb_each, obj, iter_yield, obj); +static VALUE array_spec_rb_block_call_then_yield(VALUE self, VALUE obj) { + rb_block_call(obj, rb_intern("each"), 0, 0, iter_yield, obj); return Qnil; } @@ -287,9 +283,9 @@ void Init_array_spec(void) { https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/ext/array_spec.c#L283 rb_define_method(cls, "rb_ary_plus", array_spec_rb_ary_plus, 2); rb_define_method(cls, "rb_ary_unshift", array_spec_rb_ary_unshift, 2); rb_define_method(cls, "rb_assoc_new", array_spec_rb_assoc_new, 2); - rb_define_method(cls, "rb_iterate", array_spec_rb_iterate, 1); - rb_define_method(cls, "rb_iterate_each_pair", array_spec_rb_iterate_each_pair, 1); - rb_define_method(cls, "rb_iterate_then_yield", array_spec_rb_iterate_then_yield, 1); + rb_define_method(cls, "rb_block_call", array_spec_rb_block_call, 1); + rb_define_method(cls, "rb_block_call_each_pair", array_spec_rb_block_call_each_pair, 1); + rb_define_method(cls, "rb_block_call_then_yield", array_spec_rb_block_call_then_yield, 1); rb_define_method(cls, "rb_mem_clear", array_spec_rb_mem_clear, 1); rb_define_method(cls, "rb_ary_freeze", array_spec_rb_ary_freeze, 1); rb_define_method(cls, "rb_ary_to_ary", array_spec_rb_ary_to_ary, 1); -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/