Skip to content

Commit b872fbe

Browse files
committed
Deprecate rb_eval_cmd_kw
1 parent 7f41c3e commit b872fbe

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

include/ruby/internal/intern/vm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ VALUE rb_check_funcall(VALUE recv, ID mid, int argc, const VALUE *argv);
9595
*/
9696
VALUE rb_check_funcall_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat);
9797

98+
#ifdef RBIMPL_ATTR_DEPRECATED_INTERNAL
9899
/**
99100
* This API is practically a variant of rb_proc_call_kw() now. Historically
100101
* when there still was a concept called `$SAFE`, this was an API for that.
@@ -109,7 +110,9 @@ VALUE rb_check_funcall_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int k
109110
* - RB_PASS_CALLED_KEYWORDS it depends if there is a passed block.
110111
* @return What the command evaluates to.
111112
*/
113+
RBIMPL_ATTR_DEPRECATED_INTERNAL(4.0)
112114
VALUE rb_eval_cmd_kw(VALUE cmd, VALUE arg, int kw_splat);
115+
#endif
113116

114117
/**
115118
* Identical to rb_funcallv(), except it takes Ruby's array instead of C's.

spec/ruby/optional/capi/ext/kernel_spec.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,11 @@ VALUE kernel_spec_rb_eval_string(VALUE self, VALUE str) {
117117
return rb_eval_string(RSTRING_PTR(str));
118118
}
119119

120+
#ifndef RUBY_VERSION_IS_4_0
120121
VALUE kernel_spec_rb_eval_cmd_kw(VALUE self, VALUE cmd, VALUE args, VALUE kw_splat) {
121122
return rb_eval_cmd_kw(cmd, args, NUM2INT(kw_splat));
122123
}
124+
#endif
123125

124126
VALUE kernel_spec_rb_raise(VALUE self, VALUE hash) {
125127
rb_hash_aset(hash, ID2SYM(rb_intern("stage")), ID2SYM(rb_intern("before")));
@@ -403,7 +405,9 @@ void Init_kernel_spec(void) {
403405
rb_define_method(cls, "rb_category_warn_deprecated_with_integer_extra_value", kernel_spec_rb_category_warn_deprecated_with_integer_extra_value, 1);
404406
rb_define_method(cls, "rb_ensure", kernel_spec_rb_ensure, 4);
405407
rb_define_method(cls, "rb_eval_string", kernel_spec_rb_eval_string, 1);
408+
#ifndef RUBY_VERSION_IS_4_0
406409
rb_define_method(cls, "rb_eval_cmd_kw", kernel_spec_rb_eval_cmd_kw, 3);
410+
#endif
407411
rb_define_method(cls, "rb_raise", kernel_spec_rb_raise, 1);
408412
rb_define_method(cls, "rb_throw", kernel_spec_rb_throw, 1);
409413
rb_define_method(cls, "rb_throw_obj", kernel_spec_rb_throw_obj, 2);

spec/ruby/optional/capi/kernel_spec.rb

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -635,22 +635,24 @@ def proc_caller
635635
end
636636
end
637637

638-
describe "rb_eval_cmd_kw" do
639-
it "evaluates a string of ruby code" do
640-
@s.rb_eval_cmd_kw("1+1", [], 0).should == 2
641-
end
638+
ruby_version_is ""..."4.0" do
639+
describe "rb_eval_cmd_kw" do
640+
it "evaluates a string of ruby code" do
641+
@s.rb_eval_cmd_kw("1+1", [], 0).should == 2
642+
end
642643

643-
it "calls a proc with the supplied arguments" do
644-
@s.rb_eval_cmd_kw(-> *x { x.map { |i| i + 1 } }, [1, 3, 7], 0).should == [2, 4, 8]
645-
end
644+
it "calls a proc with the supplied arguments" do
645+
@s.rb_eval_cmd_kw(-> *x { x.map { |i| i + 1 } }, [1, 3, 7], 0).should == [2, 4, 8]
646+
end
646647

647-
it "calls a proc with keyword arguments if kw_splat is non zero" do
648-
a_proc = -> *x, **y {
649-
res = x.map { |i| i + 1 }
650-
y.each { |k, v| res << k; res << v }
651-
res
652-
}
653-
@s.rb_eval_cmd_kw(a_proc, [1, 3, 7, {a: 1, b: 2, c: 3}], 1).should == [2, 4, 8, :a, 1, :b, 2, :c, 3]
648+
it "calls a proc with keyword arguments if kw_splat is non zero" do
649+
a_proc = -> *x, **y {
650+
res = x.map { |i| i + 1 }
651+
y.each { |k, v| res << k; res << v }
652+
res
653+
}
654+
@s.rb_eval_cmd_kw(a_proc, [1, 3, 7, {a: 1, b: 2, c: 3}], 1).should == [2, 4, 8, :a, 1, :b, 2, :c, 3]
655+
end
654656
end
655657
end
656658

0 commit comments

Comments
 (0)